Elf M. Sternberg d7b4592ce1 | ||
---|---|---|
.gitignore | ||
LICENSE | ||
README.md | ||
pre-commit |
README.md
pre-commit
This program is a git pre-commit hook that runs an arbitrary set of syntax, style, and complexity checks against files about to be checked in.
pre-commit is a git-hook; you install it into your project's .git directory in .git/hooks and make it executable. It will run every time you attempt to commit a collection of files, running the configured list of linters against those files, and will terminate the check-in if any of the files fails.
pre-commit uses the git-stash to temporarily store any changes you may have made between your "git-add" and your "git-commit"; it therefore checks against your staged files, not your workspace files. Most hooks do the wrong thing and assume your stage and workspace are the same. This is not necessarily so.
pre-commit is written in Hy, a Lisp-like dialect of Python. I find Hy's support for "cond", complex anonymous functions, and complex return values highly appealing. The UTF-8 handling in this script means it is compatible only with Hy running atop Python3.
pre-commit is based on the pre-commit recommendations in Steve Pulec's "Why you need a git-hook and why most are wrong" available at: http://css.dzone.com/articles/why-your-need-git-pre-commit The changes I've made reflect a different set of needs, different possible ways of receiving error conditions, and a slightly nicer output.
If, while installing this, you encounter a problem, you must return your git repository to its original pre-stash state. Learn to use the following commands correctly:
git stash list git stash pop