Reputation: 1111
I am on my testbranch:
$git branch
master
* testbranch
Here is my code in .git/hooks/pre-push
file:
#!/bin/bash
protected_branch='testbranch'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
echo "Test"
pwdlsfail
rc=$?
if [[ $rc != 0 ]] ; then
echo "test failed - push denied. Run tests locally and confirm they pass before pushing"
exit $rc
fi
else
# Everything went OK so we can exit with a zero
exit 0
fi
Tried running above code as a shell script and works fine:
$./1.sh
Test
./1.sh: line 8: pwdlsfail: command not found
test failed on rev - push denied. Run tests locally and confirm they pass before pushing
But pre-push
hook is still not getting called with git push origin testbranch
, am I missing something?
Upvotes: 0
Views: 3385
Reputation: 224864
It sounds from your description that you're trying to put the pre-receive
hook into your local repository. That's not how it works - the pre-receive
hook should be on your remote. If you want to run something locally before you push, use the pre-push
hook.
There are several other hooks listed in the documentation that you may also find useful.
Upvotes: 2