I have a pre-push script in my .git/hooks folder. This script runs fine when pushing from a local branch that has a pre-existing remote upstream branch. But it fails to run when I create a new branch off of master, say test-pre-push
, commit a build-breaking change for example, and then enter the command git push --set-upstream origin test-pre-push
. The commit and the branch are pushed to the remote repo. How can I ensure the script is run with each and every push to remote?
Check below for my pre-push script:
#!/bin/bash
#The command to run
CMD='./gradlew testDebugUnitTest'
# Check if we actually have commits to push
commits=$(git log @\{u\}..)
if [ -z "$commits" ]; then
exit 0
fi
$CMD
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "failed $CMD"
exit 1
fi
exit 0