Snowing Code

Personal notes on software development


Git pre-push hook for your .NET project

(Publish date: 24/06/2013)

Only recently, on version 1.8.2, git has added the long awaited pre-push hook. Windows received this feature as part of the 1.8.3.1 release since we don't get every new git release (as far as I understood). As I was already looking for a solution for compiling my .net code and running my unit tests every time just before I push my code, and making sure that if anything fails, the push is stopped, I already had some ruby code to do just that. When I heard the pre-push hook was available, I thought I could share that bit of code with other people looking for a similar solution. So I wrote a small ruby gem to do just that.

So if you want to add a pre-push hook to your git repository simply:
  1. make sure you have ruby installed on your machine.
  2. run gem install pre_push
  3. cd to your repository.
  4. run prepush [/r=test_runner:optional] [/td=path/to/tested.dll,path/to/another.dll:optional]
An example would be: prepush /r=xunit191 /td=./MyProj.Tests/bin/MyProj.Tests.dll
The test frameworks currently supported are mspec, xunit and nunit (which is the default). If you don't specify the /td= option, the test runner will run the tests of your solution. The gem will use the first sln file it finds under your repository. You can open the pre-push file inside .git/hooks and modify it as you wish.
This is pretty much it. If you need anything else your pre-push hook to do, feel free to let me know. I also take pull requests :) Here is the source code for my pre_push gem.

Tags: git
blog comments powered by Disqus