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.

  • How to keep track of processed git commits?
  • Git responds with “Your branch is ahead of 'origin/Dev' by 2 commits” after merging a pull request through Bitbucket
  • git push -u origin --all does not work anymore
  • Setting up personal branch permissions using gitolite
  • Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
  • How to I update the path to a moved git-svn remote branch
  • git: how can i list new files to add them after?
  • Is it safe to delete a fork of a GitHub repo, when the original refers to mine?
  • How to serve static non-image asset from a readthedocs site?
  • How to clone a django reporsitory into a virtualenv
  • What is the use of two or more User.Name in Git.
  • Add generated files in Rubymine to git
  • 3 Solutions collect form web for “Use gruntjs as precommit hook”

    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: http://codeinthehole.com/writing/tips-for-using-a-git-pre-commit-hook/

    And the git docs: http://git-scm.com/book/en/Customizing-Git-Git-Hooks

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

    I recently had the same issue and detailed a more comprehensive Grunt solution on http://viget.com/extend/grunt-getting-started-with-git-hooks

    I think you should check out grunt-githooks, a nice Grunt plugin that does all the magic for you and lets you easily register Grunt tasks for certain hooks from within your Gruntfile.js, such as:

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

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

    Find the module on npm here.

    Git Baby is a git and github fan, let's start git clone.