diff --git a/index.js b/index.js index 1c40d1a..48ceb2b 100755 --- a/index.js +++ b/index.js @@ -24,7 +24,7 @@ var TYPES = config.types || ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', // fixup! and squash! are part of Git, commits tagged with them are not intended to be merged, cf. https://git-scm.com/docs/git-commit var PATTERN = /^((fixup! |squash! )?(\w+)(?:\(([^\)\s]+)\))?: (.+))(?:\n|$)/; - +var MERGE_COMMIT_PATTERN = /^Merge branch \'.*\' into .*$/; var error = function() { // gitx does not display it // http://gitx.lighthouseapp.com/projects/17830/tickets/294-feature-display-hook-error-message-when-hook-fails @@ -45,6 +45,11 @@ var validateMessage = function(raw) { var isValid = true; + if(MERGE_COMMIT_PATTERN.test(message)){ + console.log('Merge commit detected.'); + return true + } + if (IGNORED.test(message)) { console.log('Commit message validation ignored.'); return true; diff --git a/index.test.js b/index.test.js index 1118038..b2cddb0 100644 --- a/index.test.js +++ b/index.test.js @@ -162,6 +162,12 @@ describe('validate-commit-msg.js', function() { expect(m.validateMessage('fixup! fix($compile): something')).to.equal(VALID); expect(m.validateMessage('squash! fix($compile): something super mega extra giga tera long, maybe even longer and longer and longer...')).to.equal(VALID); }); + + it('should handle merge commits', function() { + expect(m.validateMessage('Merge branch \'master\' into validate-commit-msg-integration')).to.equal(VALID); + expect(m.validateMessage('Merge branch master into validate-commit-msg-integration')).to.equal(INVALID); + expect(m.validateMessage('Merge branch \'master\' into validate-commit_msg-integration')).to.equal(VALID); + }); }); afterEach(function() {