Hate when you open a PR and you forgot to run the checks, and of course
the only time you forget, the build goes red?
Well, forget no more
! Using Git hooks
, you can have Git check for you before pushing (or committing, if you're paranoid).How?
Simple! You only need Git 1.8.2 or later.
1. Create an executable file in the .git/hooks
directory called pre-push
if you prefer that). From a shell set at your repo's root:
$ mkdir .git/hooks
$ touch .git/hooks/pre-push
$ chmod a+x .git/hooks/pre-push
2. Write a shell script inside of that file, by editing it with your favourite editor:
# Runs test suite before each push
3. Work as usual, then push (or commit).
If your script has returned 0
as exit code, everything will continue normally. Any non-zero exit code will abort the command, so you can go back and fix whatever you broke, before anybody else has to know it ;) #gde #android #blogpost