Portable Git Hooks

My professional experience has given me opportunities to play with git hooks.  Possibly the most vetted is the hooks I created for puppet.  I’ve been most recently living in a less puppet-centric and more python-centric world.  The projects I’ve been contributing to and maintaining are mostly python, but have a fair bit of non-python in them as well (bash, ruby, yaml, etc.). This shift in focus has given me an idea!

One git hook to rule them all!

I’m tired of copying my hooks (literally ‘cp’ in most cases) between projects and then commenting/removing the parts that don’t make sense in the new project’s context.  The hooks I initially wrote for puppet development seem to have a decently pluggable base.  I reused a fair bit of the code to accomplish client-side checks in a git repo that has python and yaml files in it.  However, I’m considering the possibility of creating a new Github project that is a collection of git hooks that can be modified by a config file in <project>/.git/hooks/.  This config file would allow you enable/disable hooks as needed and modify their behavior (such as possibly shutting off certain pep8 checks, or maybe disabling a puppet-lint check).


I’m not sure how far I will go with this idea yet.  It seems to have some merit on the surface.  Being able to simply include (git submodules: ugh!) the git hook project in your project and possibly changing a config file to configure the checks.  Then, no matter what file types are in your repo, you can be confident they are syntactically correct and follow proper styling (as well as any other checks that makes sense).  Talk is cheap. Time to write some code, I guess.


Looks like there is a way to do global git hooks, which would solve this perfectly! http://www.philforhumanity.com/Global_Git_Hooks.html