-
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimized pre-commit-hook action. (#574)
* Optimized pre-commit-hook action. - Added template inorder to run grunt lint only if there are staged changes. - Added grunt lint-nofix task to run linter in no-fix mode. - Fixed some linting changes too. * changed var to let and const keywords * updated inline comment in grunt githooks configuration
- Loading branch information
1 parent
4da9b7b
commit a7d8cb0
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// hooks/pre-commit.js | ||
|
||
const exec = require('child_process').exec; | ||
// Executes shell commands synchronously | ||
const sh = require('child_process').execSync; | ||
|
||
exec('git diff --cached --quiet', function (err, stdout, stderr) { | ||
|
||
// only run if there are staged changes | ||
// i.e. what you would be committing if you ran "git commit" without "-a" option. | ||
if (err) { | ||
|
||
// stash unstaged changes - only test what's being committed | ||
sh('git stash --keep-index --quiet'); | ||
|
||
exec('grunt {{task}}', function (err, stdout, stderr) { | ||
|
||
console.log(stdout); | ||
|
||
// restore stashed changes | ||
sh('git stash pop --quiet'); | ||
|
||
let exitCode = 0; | ||
if (err) { | ||
console.log(stderr); | ||
exitCode = -1; | ||
} | ||
process.exit(exitCode); | ||
}); | ||
} | ||
|
||
}); |