Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass parameters to git pre-push hook

Tags:

git

githooks

I've create a git pre-push hook that builds my .NET solution and runs the unit tests. So executing a git push command now fires off the build/tests prior to pushing code to origin.

That all works just fine. However, there are cases when I'd like to bypass this hook. Maybe I know a test is failing and that's fine for now, I'd just like to be able to skip the logic in my hook.

Ideally I'd be able to do something like this:

git push --skip-tests

However, that doesn't seem to fly because git flags --skip-tests as an invalid parameter. Is there a way I can pass a parameter into the hook from the command line when doing a push so that I can branch the hook logic based on whether that parameter exists or not?

like image 387
Scott Avatar asked May 04 '16 19:05

Scott


1 Answers

You should skip it with:

git push --no-verify

From git push man page

With --no-verify, the hook is bypassed completely.


However, this bypass not just the tests but the all hook: build too.

You could keep the hook, but add an environment variable that the hook script would detect in order to build but not test.

skip-test=true git push
like image 62
VonC Avatar answered Nov 15 '22 03:11

VonC