0

Our group does co-development, and we have recently configured TeamCity to run regression tests upon a push to the remote repo. Ideally, our developers will now use the Gerrit push, so that the push can be gated by TeamCity. I'm anticipating that not all developers will push via Gerrit, and will decide to still do a "git push" and bypass the verification gate.

I've looked a bit into the git pre-push hook... I see that I can block the push, but can I send a new command that will run the Gerrit push?

Thanks

tennis
  • 151
  • 1
  • 1
  • 6

1 Answers1

0

The answer here states that you should probably use a pre-commit hook so that failed tests aren't even committed.

You can add this to the pre-commit file:

#!/bin/bash
printf "Temporarily committing results... \n"
git commit "$@"
printf "Testing using Gerrit... \n"
### ({Command to test using Gerrit goes here} && printf "Success! Commit saved! \n") || 
   (printf "Tests failed, undoing commit \n" && git reset HEAD^)

Alternatively, you should be able to just append the command to run Gerrit to the end of .git/pre-commit.

Note that hooks do not prevent all disaster; someone running git commit with the option --no-verify could have that commit escape testing!

Community
  • 1
  • 1
  • I'm not sure that I want to control at the commit stage. It's possible that someone might make a commit but won't be ready to push yet, right? I already have TeamCity set up to trigger at the push stage and gate the Gerrit push. That's why I want to intercept an attempt of going a regular "git push" and redirect the command to be a gerrit push. – tennis Jan 09 '16 at 23:38
  • @tennis Sure, you might make a commit that won't be pushed yet, but all you're doing here is testing to see if the commit is a good one. After all, why would you want to commit something that doesn't work? This way, it doesn't matter if you plan on pushing now or later - all commits have passed testing. –  Jan 10 '16 at 04:47
  • Right -- that's why I have my regression testing set up to run when someone does a Gerrit push. It pauses the pushing process to run the regression, and return a pass/fail. If the testing failed, then the push is blocked and the developer is notified. I'm considering for now, doing a pre-push hook that just doesn't allow the push, and reminds the developer that they need to run the Gerrit push command instead. – tennis Jan 12 '16 at 18:07