Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use gruntjs as precommit hook

Is there a way to run a gruntjs task as precommit hook. For example I want do prevent commits with failing tests or jshint issues. I've also think about to run a code beautifier for every commit.

like image 700
Andreas Köberle Avatar asked Jan 08 '13 10:01

Andreas Köberle


1 Answers

Git hooks are just scripts executed when you do an action like commit. They can contain whatever programming language you'd like.

Example of triggering grunt:

#!/bin/sh
grunt

Save this in the file: .git/hooks/pre-commit

If grunt exits with an error code higher than 0, which it does if any task fail, it will prevent the commit:

Exiting non-zero from this hook aborts the commit


Reading material: Tips for using a git pre-commit hook

And the git docs: 8.3 Customizing Git - Git Hooks

Like many other Version Control Systems, Git has a way to fire off custom scripts when certain important actions occur.

like image 110
Sindre Sorhus Avatar answered Sep 28 '22 01:09

Sindre Sorhus