5 ms·
Git Hooks - pre-commit
- luckydude 17y agoWhy is this interesting? pre-commit triggers were in BitKeeper, what, 10 years ago? Did I miss something exciting here?
- leftnode 17y agoMost version control systems have hooks, I recently ported one of my subversion hooks to git and decided to blog about it. I figured it'd probably help someone out there, which is why I submitted it to HN.
- etherealG 17y agoit's interesting cause it's useful and many people probably don't know about it.
- icefox 17y agoIt is interesting because every time I ask someone what hooks they use on their git repos they look at me with a blank face. There are so many useful things you can do with commit hooks. I have written dozens of hooks for my repositories. Spell checking my commit message and running the unit test on the file I just committed (and only that file) are the two bare minimum basic hooks that I always install, but there are dozens more depending on the repository. I wrote up a bunch of different ones I used last year on a blog entry: http://benjamin-meyer.blogspot.com/2008/10/git-hooks.html http://benjamin-meyer.blogspot.com/2008/10/git-hooks.html Think of it as the next level of unit testing. Have some bash scripts that you occasionally put an error in? add a bash -n hook on bash files to prevent mistakes. In the Arora repository there have been probably a dozen commits total that broke the build on one of the platforms. How many build breakage commits do you have in your repo? Speaking of this, the ruby on rails guys seems to be really for tests, but to run a test (even the hello world return true one) takes several seconds... how do I improve this to take ms?
- mnemonik 17y agoJust posted this to the blog, thought I would repost here too: I recently wrote a pre-commit hook that runs pylint on my Python files. http://fitzgeraldnick.com/weblog/9/ http://fitzgeraldnick.com/weblog/9/ “git diff –staged –name-only HEAD” will get you the files that are about to be committed and then you can check if they end with “.php” (or “.py” in my case) and go from there. I also check to see if “#!” and “python” are in the first line of a file because my pre-commit hook is written in python but doesn’t have an extension, just a crunch bang.
- philjackson 17y agoI use pre-commit to check if I've left any software breakpoints in my code. Very handy.