I do little shell scripting so hopefully I am doing something obviously wrong!
This hook is intended to run whenever you push. If you are on the designated branch, in this case 'githook', it should run npm run testbuild
and if that fails, stop the push.
If you are on another branch it should not interfere, and if you are on that branch and that test completes without error, it should let the push go ahead.
Here is the content of the script pre-push
:
#!/bin/zsh
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
CMD="npm run testbuild"
if [[ $current_branch = "githook"]]; then
eCHO "You are on $branch, running build test"
eval $CMD
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "failed $CMD"
exit 1
fi
fi
exit 0
Currently, when I push from that branch, I get this:
.git/hooks/pre-push:7: parse error near `;'~
But I don't see anything obviously wrong there?