Local commit hooks are definitely not what you want here.
Your requirement that 'we do not have access to modify the git server so this must be done using a local commit hook on each dev machine' is completely bogus. You can always set up another repository that is your 'test remote' which you have full control over (which will then sync up with the git server you have no control over).
Once you set up this test remote, you can add hooks to run your tests on any push. The effort to type git push test-remote my-branch
to get test results is pretty minimal.
Continuous integration with Git
Also check out Jenkins, gitlab, etc...
Update after 8/7/13:
So you really want to do some 'tests' on a remote server to prevent commits. If you want to prevent based on the content of the commit itself, use the pre-commit
hook. See this question for how to get a list of changed files. Once you have those changed files, you can get them to a remote server using scp
or rsync
and run a test command with ssh
.
If you need to check the commit message use the commit-msg
hook.
Here is a good tutorial on hooks: http://git-scm.com/book/en/Customizing-Git-Git-Hooks
It also mentions a few reasons why it might be a bad idea.
They’re often used to enforce certain policies, although it’s important to note that these scripts aren’t transferred during a clone. You can enforce policy on the server side to reject pushes of commits that don’t conform to some policy, but it’s entirely up to the developer to use these scripts on the client side. So, these are scripts to help developers, and they must be set up and maintained by them, although they can be overridden or modified by them at any time.