diff --git a/.all-contributorsrc b/.all-contributorsrc
index 1ebd8f7..9c9c22c 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -267,6 +267,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "maxcnunes",
+ "name": "Max Claus Nunes",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/680356?v=3",
+ "profile": "http://blog.maxcnunes.net/",
+ "contributions": [
+ "code"
+ ]
}
]
}
diff --git a/README.md b/README.md
index f972908..d26ba4f 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
[![downloads][downloads-badge]][npm-stat]
[![MIT License][license-badge]][LICENSE]
-[![All Contributors](https://img.shields.io/badge/all_contributors-26-orange.svg?style=flat-square)](#contributors)
+[![All Contributors](https://img.shields.io/badge/all_contributors-27-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Donate][donate-badge]][donate]
[![Code of Conduct][coc-badge]][coc]
@@ -192,7 +192,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [
Shawn Erquhart](http://www.professant.com)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=erquhart) [π](https://github.com/kentcdodds/validate-commit-msg/commits?author=erquhart) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=erquhart) | [
Tushar Mathur](http://tusharm.com)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=tusharmath) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=tusharmath) | [
Jason Dreyzehner](https://twitter.com/bitjson)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=bitjson) [π](https://github.com/kentcdodds/validate-commit-msg/commits?author=bitjson) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=bitjson) | [
Abimbola Idowu](http://twitter.com/hisabimbola)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=hisabimbola) | [
Gleb Bahmutov](https://glebbahmutov.com/)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=bahmutov) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=bahmutov) | [
Dennis](http://dennis.io)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=ds82) | [
Matt Lewis](https://mattlewis.me/)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=mattlewis92) |
| [
Tom Vincent](https://tlvince.com)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=tlvince) | [
Anders D. Johnson](https://andrz.me/)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=adjohnson916) [π](https://github.com/kentcdodds/validate-commit-msg/commits?author=adjohnson916) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=adjohnson916) | [
James Zetlen](http://jameszetlen.com)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=zetlen) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=zetlen) | [
Paul Bienkowski](http://opatut.de)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=opatut) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=opatut) | [
Barney Scott](https://github.com/bmds)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=bmds) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=bmds) | [
Emmanuel Murillo SΓ‘nchez](https://github.com/Emmurillo)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=Emmurillo) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=Emmurillo) | [
Hans Kristian Flaatten](https://starefossen.github.io)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=Starefossen) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=Starefossen) |
-| [
Bo Lingen](https://github.com/citycide)
[π](https://github.com/kentcdodds/validate-commit-msg/commits?author=citycide) | [
Spyros Ioakeimidis](http://www.spyros.io)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=spirosikmd) [π](https://github.com/kentcdodds/validate-commit-msg/commits?author=spirosikmd) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=spirosikmd) | [
Matt Travi](https://matt.travi.org)
[π](https://github.com/kentcdodds/validate-commit-msg/issues?q=author%3Atravi) | [
Jonathan Garbee](http://jonathan.garbee.me)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=Garbee) [π](https://github.com/kentcdodds/validate-commit-msg/commits?author=Garbee) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=Garbee) | [
Tobias Lins](https://lins.in)
[π](https://github.com/kentcdodds/validate-commit-msg/commits?author=tobiaslins) |
+| [
Bo Lingen](https://github.com/citycide)
[π](https://github.com/kentcdodds/validate-commit-msg/commits?author=citycide) | [
Spyros Ioakeimidis](http://www.spyros.io)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=spirosikmd) [π](https://github.com/kentcdodds/validate-commit-msg/commits?author=spirosikmd) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=spirosikmd) | [
Matt Travi](https://matt.travi.org)
[π](https://github.com/kentcdodds/validate-commit-msg/issues?q=author%3Atravi) | [
Jonathan Garbee](http://jonathan.garbee.me)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=Garbee) [π](https://github.com/kentcdodds/validate-commit-msg/commits?author=Garbee) [β οΈ](https://github.com/kentcdodds/validate-commit-msg/commits?author=Garbee) | [
Tobias Lins](https://lins.in)
[π](https://github.com/kentcdodds/validate-commit-msg/commits?author=tobiaslins) | [
Max Claus Nunes](http://blog.maxcnunes.net/)
[π»](https://github.com/kentcdodds/validate-commit-msg/commits?author=maxcnunes) |
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
diff --git a/lib/cli.js b/lib/cli.js
index 434afa8..63f5c05 100755
--- a/lib/cli.js
+++ b/lib/cli.js
@@ -18,27 +18,44 @@ var getGitFolder = require('./getGitFolder');
// hacky start if not run by mocha :-D
// istanbul ignore next
if (process.argv.join('').indexOf('mocha') === -1) {
+ var commitMsgFileOrText = process.argv[2] || getGitFolder() + '/COMMIT_EDITMSG';
- var commitMsgFile = process.argv[2] || getGitFolder() + '/COMMIT_EDITMSG';
- var incorrectLogFile = commitMsgFile.replace('COMMIT_EDITMSG', 'logs/incorrect-commit-msgs');
+ var bufferToString = function (buffer) {
+ return hasToString(buffer) && buffer.toString();
+ };
- var hasToString = function hasToString(x) {
+ var hasToString = function (x) {
return x && typeof x.toString === 'function';
};
- fs.readFile(commitMsgFile, function(err, buffer) {
- var msg = getCommitMessage(buffer);
-
+ var validate = function (msg, isFile) {
if (!validateMessage(msg)) {
- fs.appendFile(incorrectLogFile, msg + '\n', function() {
+ var incorrectLogFile = (
+ isFile
+ ? commitMsgFileOrText.replace('COMMIT_EDITMSG', 'logs/incorrect-commit-msgs')
+ : (getGitFolder() + '/logs/incorrect-commit-msgs')
+ );
+
+ fs.appendFile(incorrectLogFile, msg + '\n', function appendFile() {
process.exit(1);
});
} else {
process.exit(0);
}
+ };
- function getCommitMessage(buffer) {
- return hasToString(buffer) && buffer.toString();
+ fs.readFile(commitMsgFileOrText, function readFile(err, buffer) {
+ if(err && err.code !== 'ENOENT') {
+ throw err;
}
+
+ var isFile = !err;
+ var msg = (
+ isFile
+ ? bufferToString(buffer)
+ : commitMsgFileOrText
+ );
+
+ validate(msg, isFile);
});
}