Avoid rewriting history with rebase or roll back and re-commit and use the below in your git/hooks/pre-commit
1234567891011121314151617
#!/bin/bashcurBranch=$(git rev-parse --abbrev-ref HEAD)# Ignore rebase, stash unstaged.[[$curBranch !='(no branch)']]&&git stash -q --keep-index &&grunt test# Check the exit status of grunt.[[$? -ne 0 ]]&&echo"Test failed, can't commit"&&exit 1
# All is well, stage and restore stash.git add .
git stash pop -q
In the Gruntfile.js (As of now I'm using mocha, so..)
1234567891011121314151617181920
module.exports=function(grunt){// Add the grunt-mocha-test tasks.grunt.loadNpmTasks('grunt-mocha-test');grunt.initConfig({// Configure a mochaTest taskmochaTest:{test:{options:{reporter:'spec'},src:['test/**/*.js']}}});grunt.registerTask('test','mochaTest');};
Well ofcourse, this can be imporved for release tasks as well :-)