kvz / ochtra

One Commit Hook To Rule All
MIT License
86 stars 13 forks source link
command-line commits git hooks programming-languages quality-assurance shell

ochtra

Build Status

ochtra stands for One Commit Hook To Rule All and is an attempt at creating the definitive Git commit hook that:

ochtra deals with some common pitfalls you'll find in other hooks:

Try it now

Without installing anything, you can see ochtra in action on a local test repository:

cd /tmp
mkdir test-repo && cd $_

git init
curl -s https://raw.githubusercontent.com/kvz/ochtra/master/pre-commit -ko .git/hooks/pre-commit \
 && chmod u+x $_

echo ";-)" > syntax-error.go
git add syntax-error.go
git commit

You'll notice that ochtra won't let you commit that syntax-error.go:

screen shot 2014-01-07 at 15 18 47

Phew : ) Now for .go files it won't typically be a huge problem as your Go project won't run with syntax errors in the first place. But what about making that quick documentation change and leaving a typo? What about that Bash file in your repository? ochtra has got you covered.

Install

As of Git 1.7 you can install ochtra as a git template.

mkdir -p ~/.gittemplate/hooks
curl https://raw.githubusercontent.com/kvz/ochtra/master/pre-commit -o ~/.gittemplate/hooks/pre-commit \
 && chmod u+x $_
git config --global init.templatedir '~/.gittemplate'

This will make it present in all newly create repositories.

Now, to install/update in existing repositories you can type

cd my-project
rm .git/hooks/pre-commit
git init # just copies any non-existing files from ~/.gittemplate to current repo

Uninstall

To remove ochtra from one project, type

rm .git/hooks/pre-commit

To remove the automatic installer for new Git repos, type

git config --global --unset init.templatedir
# git config --global --remove-section init

Tests

To run the tests:

make test

Contributors

Feel free to report issues, comment on my blog or send a pull requests.

Contributors so far:

Tips

$ git commit -n

This can be useful if you import big chunks of code that don't pass jshint yet.

Thanks

These pages have been a source of inspiration when building ochtra:

License

MIT Licensed