Giter Club home page Giter Club logo

ochtra's Introduction

ochtra

Build Status

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

  • Works on all your languages (for now Ruby, JavaScript, TypeScript, CoffeeScript, Python, Sh, Bash, Dash, Go, Perl, PHP, XML, JSON, YAML, HTML)
  • Is globally installable for all your repositories
  • Aims to keep syntax errors from entering your codebase
  • Is not religous about coding style (you still can have your own custom pre-ochtra hook for that)

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

  • Works on initial commits
  • Will skip files that are staged to be deleted
  • Will not run when we're not currently on a branch
  • Can co-exist with your current commit hook, just rename it to pre-ochtra
  • Works on filenames with spaces
  • Checks files as staged in Git, not how they're currently saved in your working dir
  • Deals with discrepancies between linters sometimes printing errors on STDOUT vs STDERR

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:

  • abtris (YAML, JSON & XML support)
  • Stefan Näwe (reporting issue)
  • mihaeu (reporting issue)
  • Mischa ter Smitten (curl fix for githubusercontent when installing)
  • Jan Dorsman (fix PHP error logging)
  • qdx (fix pipestatus & Git invalid object bug)
  • Jostein Kjønigsen (TypeScript support)
  • Dan Boulet (HTML support, improve YAML/Git/Go support and tests)

Tips

  • If you already had a pre-commit hook that you want to preserve and have executed before ochtra, just rename it to pre-ochtra.

  • If you ever want to commit code and disable the pre-commit one time, type

$ git commit -n

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

  • If you want to install linters, have a look at the .travis.yml file, it has instructions for all of them

Thanks

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

License

MIT Licensed

ochtra's People

Contributors

abtris avatar dboulet avatar josteink avatar kvz avatar oldskool avatar tersmitten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ochtra's Issues

Does not work on Windows + cygwin (php/js)

js file with error:

$ git commit -m "a"
on branch master
--> jshint syntax checking for test.js
stdin: line 1, col 1, Expected an assignment or function call and instead saw an expression.
stdin: line 1, col 9, Missing semicolon.
stdin: line 2, col 1, Expected an assignment or function call and instead saw an expression.
stdin: line 2, col 4, Missing semicolon.
stdin: line 3, col 1, Expected an assignment or function call and instead saw an expression.
stdin: line 3, col 2, Missing semicolon.
stdin: line 4, col 1, Expected an assignment or function call and instead saw an expression.
stdin: line 4, col 2, Missing semicolon.

8 errors
No jshint syntax errors detected in 'test.js'
[master 588c64f] a
 1 file changed, 2 insertions(+), 1 deletion(-)

php file with error:

$ git commit -m "a"
on branch master
--> php syntax checking for test.php
No php syntax errors detected in 'test.php'
[master 4357ee1] a
 1 file changed, 2 insertions(+), 1 deletion(-)

When I run the lint directly:

$ php -l test.php

Parse error: syntax error, unexpected 'adsasdsa' (T_STRING), expecting ',' or ';' in test.php on line 3
Errors parsing test.php

Any hints?

Blatantly ignores relevant dotfiles

This pre-commit hook is a great idea, but sadly I can't reasonably use it in JS projects because it completely bypasses the relevant .jshintrc files by reading from STDIN instead of from disk.

Is there any way to fix this problem or is it a limitation of git hooks in general?

Doesn’t work with very large files

I’m on MacOS, and noticed that this scripts fails with large files. For example, if I attempt to commit a valid 66 kB YAML file (just as a test), I get back an error message asking me to fix syntax errors. If the file size under 65 kB, it works fine.

I think that this has to do with reaching buffer limits when piping large amounts of data, but am not 100% sure.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.