git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Feature Request: provide cmdline args to git hooks

From
COChris O'Kelly <chris@mapcreative.com.au>
Date
Apr 14, 2015, 03:42 UTC
Message-ID
<CAM-hpQcgOgrAJBAZrH4icDtJMiHUYOz1tynYkoj7qzyVMZ0eVQ@mail.gmail.com>

Hello, Just a brief note about a feature I would find incredibly useful, were it available.

A brief background of my use case: I am wanting to write a pre-push hook to prevent tags being pushed to our production servers. The production servers in our case are --bare endpoints, and when we push a tag at them, they always checkout the commit that tag is attached to via some post-receive magic (WPEngine, FWIW). This behavior is even present when the tag was already pushed to the repo previously, if for instance a normal push is made with the --tags argument. In the past we have had problems when a developer is using a GUI like SourceTree and accidentally leaves the 'push all tags' option checked, pushing 100s of tags to the server, which then dutifully begins checking out each in turn.

Currently I check for tag refs being pushed with: #...SNIP... while read local_ref local_sha remote_ref remote_sha do local_type=$(echo "$local_ref" | awk -F/ '{print $2}') remote_type=$(echo "$remote_ref" | awk -F/ '{print $2}') if [[ "$no_tags" -eq 1 && ($local_type = "tags" || $remote_type = "tags")]] then echo "Detected attempt to push tags to a no_tags repo! Exiting without push..." exit 1 fi #...SNIP...

which works fine the first time tags are pushed, but when they are already up to date as of the last fetch, they are not passed to the stdin for pre-push, so I cannot detect them.

in a linux environment we can inspect /proc/$PPID/cmdline or ps -ocommand= -p $PPID to find the --tags argument (or any manually specified tag refs, etc), however commonly developers are using Windows with SourceTree, and the pseudo-nix environment it provides lacks a /proc directory and uses the cut down cygwin version of ps. I have considered going down the parsing route with general ps output, reading line by line to find the appropriate ppid, then echoing the output, but varying output and column order of ps between SourceTree and various linux versions looks to make that infeasible as a portable solution.

If we could access the original git push commandline inside the hook, either through a parameter passed directly to the script or possibly a GIT_* environment variable, it would make this possible. My specific use case may not be incredibly common, but this could also be used to check if, for example, a push is being forced in a portable fashion - something I can see being useful for a pre-push hook in a variety of circumstances.

Alternatively - am I missing the super easy (and probably super obvious) way to do this with the existing tools?

Next: Junio C Hamano
Message 1 of 6 in “Feature Request: provide cmdline args to git hooks”
  1. Chris O'KellyApr 14, 2015
  2. Junio C HamanoApr 14, 2015
  3. Chris O'KellyApr 14, 2015
  4. Junio C HamanoApr 14, 2015
  5. Chris O'KellyApr 15, 2015
  6. Junio C HamanoApr 15, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.