3

I have an origin repo that I have full access to and I don't want code to be pushed successfully to this repo unless the code being pushed successfully passes my unit tests. I saw many examples of .git/hooks/update scripts and they seem to break down into a few categories that do not fit my use case.

For example, in (http://git-scm.com/book/en/Customizing-Git-An-Example-Git-Enforced-Policy), the script accesses files locally in the .git/hooks/ directory (ACL example) or individual files in the new or old SHAs.

I need to do an entire build process on all the new files as if I were in the directory of the new commit and were running

.git/hooks/update

#!/usr/bin/bash
mvn test
exit $?
Victor 'Chris' Cabral
  • 2,135
  • 1
  • 16
  • 33

1 Answers1

2

I would recommend a guarded commit approach, where you are pushing to an intermediate repo, which:

  • triggers the mvn test
  • push, upon successful completion, to your actual intended repo.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • That sounds like a great approach. Have you used this approach? Any extra considerations or tips while taking this approach? – Victor 'Chris' Cabral Jan 16 '14 at 14:28
  • 1
    @Victor'Chris'Cabral mainly by having a second bare repo, with a post-receive hook in it (similar to your update hook), and a test at the end of the hook to push to the original repo if `mvn test` doesn't return an error. – VonC Jan 16 '14 at 14:48
  • Also, is there any way to do this with rejecting the update just in case I want to? – Victor 'Chris' Cabral Jan 17 '14 at 16:42
  • @Victor'Chris'Cabral reject a commit you have already pushed would mean git revert that commit locally and push it, in order to cancel the previous commit. (last part of http://stackoverflow.com/a/4114122/6309) – VonC Jan 17 '14 at 17:29