diff --git a/README.md b/README.md index 0e704be..9f5d786 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,11 @@ see the messages when committing This should provide plenty of information to debug the hooks +## Local development + +To execute commit message validation, run `npm run demo-commit-message` and vary the +test message to see how the hook validates it. + ### Small print Author: Gleb Bahmutov © 2014 diff --git a/bin/commit-msg.js b/bin/commit-msg.js index 2f2d5ee..6984d42 100755 --- a/bin/commit-msg.js +++ b/bin/commit-msg.js @@ -22,13 +22,19 @@ la(check.fn(preGit.printError), 'missing preGit.printError,', Object.keys(preGit)); function checkMessage(msg) { + log('checking commit message:', msg); const isValid = wizard.validate(msg); if (!isValid) { + log('invalid commit message', msg); process.exit(-1); } + log('valid git commit message'); } ggit.commitMessage() + .then((msg) => { + return process.env.TEST_GIT_MESSAGE || msg; + }) .then(checkMessage) .catch((err) => { // assuming each validator printed the errors? diff --git a/package.json b/package.json index d2e46e4..a979da1 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ }, "config": { "pre-git": { + "commit-msg": "simple", "demo": [ "echo this is command 1", "echo this is command 2", @@ -48,7 +49,7 @@ "lazy-ass": "1.3.0", "require-relative": "0.8.7", "shelljs": "0.5.3", - "simple-commit-message": "1.1.0", + "simple-commit-message": "2.1.0", "validate-commit-msg": "1.0.0", "word-wrap": "1.1.0" }, @@ -98,6 +99,8 @@ "issues": "git-issues", "size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";", "semantic-release": "semantic-release pre && npm publish && semantic-release post", - "demo": "DEBUG=pre-git node --harmony src/pre-git.js" + "demo": "DEBUG=pre-git node --harmony src/pre-git.js", + "demo-commit-message": "TEST_GIT_MESSAGE='chore(test): test message' DEBUG=pre-git NODE_PATH=.. node bin/commit-msg.js", + "demo-commit-wizard": "DEBUG=pre-git NODE_PATH=.. node bin/commit-wizard.js" } }