I have a prepush hook that tests my code, however, it also runs when I do a git push --tags
. Is there any way to avoid this?
Maybe there's some way to check if its a regular push or if its a --tags
push?
Update - These are the only arguments I was able to find:
Sharing tags is similar to pushing branches. By default, git push will not push tags. Tags have to be explicitly passed to git push .
Quick tip if you want to skip the pre-commit validations and quickly want to get a commit out there. To get your commit through without running that pre-commit hook, use the --no-verify option. Voila, without pre-commit hooks running!
If you want enforcement, use an update hook in the central repo. If the hook is doing per-commit verification, you can still provide a pre-commit hook; developers will likely adopt it voluntarily, so that they can find out right away when they've done something wrong, rather than waiting until they try to push.
Committing-Workflow Hooks The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code.
I have a solution to this, but it's really kludgey. A while back, I set up a pre-commit hook to stop me from accidentally using -a
when I have files staged. My solution is to read the command that invoked the original git command (probably only works on linux too).
while read -d $'\0' arg ; do
if [[ "$arg" == '--tags' ]] ; then
exit 0
fi
done < /proc/$PPID/cmdline
# and perform your check here
Original
That being said, try calling env
in the hook; git sets a few extra vars (starting with GIT_
prefixes, like GIT_INDEX_FILE
).
You can use env variable to control it:
#.git/hooks/pre-push
if [[ $SKIP_HOOKS ]]; then
exit 0
fi
# do things you want...
and run command like this:
SKIP_HOOKS=true git push --tags
You are looking for the --no-verify
flag. So:
git push --tags --no-verify
This is what git help push
tells you about that flag:
--[no-]verify
Toggle the pre-push hook (see githooks(5)). The default is --verify, giving the hook a chance to prevent the push.
With --no-verify, the hook is bypassed completely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With