Thank you very much for this! However, there’s a small problem with this.
In bash $?
means the exit status of the last command only! So, when you run this:
./scripts/run-brakeman.bash
./scripts/run-tests.bashif [ $? -ne 0 ]; then
echo "Brakeman and Tests must pass before pushing!"
exit 1
fi
If your run-brakeman.bash
script fails, but your run-tests.bash
script is successful, your $?
variable will equal 0
, and the commit will be pushed upstream. A quick and dirty fix for this is to execute both scripts together. Like so:
./scripts/run-brakeman.bash && ./scripts/run-tests.bashif [ $? -ne 0 ]; then
echo "Brakeman and Tests must pass before pushing!"
exit 1
fi
This way, if either one fails, the $?
variable will be non-zero.