Use gruntjs as precommit hook

Is there any way to run the gruntjs task as a precommit hook. For example, I want to prevent committing with errors or problems with jshint. I also think about running code for each commit.

+9
git pre-commit-hook gruntjs
source share
3 answers

Git hooks are just scripts executed when you execute an action, such as commit. They can contain any programming language.

An example of running grunt:

#!/bin/sh grunt 

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

If grunt fails with an error code above 0, which occurs when any task fails, this prevents the adoption:

Exiting non-zero from this hook cancels commit


Reading Material: Tips for Using git pre-commit hook

And git docs: 8.3 Configuring Git - Git Hooks

Like many other version control systems, Git has a way to run user scripts when performing certain important actions.

+9
source share

I recently had the same problem, and we looked in detail at a more comprehensive Grunt solution at http://viget.com/extend/grunt-getting-started-with-git-hooks

+5
source share

I think you should check out grunt-githooks , a beautiful Grunt plugin that does all the magic for you and allows you to easily log Grunt tasks for specific hooks from your Gruntfile.js , for example:

 grunt.initConfig({ githooks: { all: { // Will run the jshint and test:unit tasks at every commit 'pre-commit': 'jshint test:unit', } } }); 

(Taken from the documents at https://github.com/wecodemore/grunt-githooks#defining-a-few-hooks )

Find the module on npm here .

+2
source share

All Articles