From b6863f1ff27047d4bf1248b18f1af472a20f9743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Tue, 14 Dec 2021 17:29:47 +0100 Subject: [PATCH] fix(is-ignored): ignore merge tag commit messages Merging a tag in another branch can lead to conflicts. In this case, the default Git commit message after resolving the conflicts will be like: `Merge tag 'x.y.z'` Currently, this commit message format is being considered as an error. So I updated the wildcards to get a consistent behavior between branch and tag merge: - `Merge branch 'a branch'` - `Merge branch 'a tag'` --- @commitlint/is-ignored/src/defaults.ts | 1 + @commitlint/is-ignored/src/is-ignored.test.ts | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/@commitlint/is-ignored/src/defaults.ts b/@commitlint/is-ignored/src/defaults.ts index e8acc4448e..31d419e52b 100644 --- a/@commitlint/is-ignored/src/defaults.ts +++ b/@commitlint/is-ignored/src/defaults.ts @@ -18,6 +18,7 @@ export const wildcards: Matcher[] = [ test( /^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m ), + test(/^(Merge tag (.*?))(?:\r?\n)*$/m), test(/^(R|r)evert (.*)/), test(/^(fixup|squash)!/), isSemver, diff --git a/@commitlint/is-ignored/src/is-ignored.test.ts b/@commitlint/is-ignored/src/is-ignored.test.ts index 08911a615b..833ab04c49 100644 --- a/@commitlint/is-ignored/src/is-ignored.test.ts +++ b/@commitlint/is-ignored/src/is-ignored.test.ts @@ -70,6 +70,26 @@ test('should return true for branch merges with newline characters and more char ); }); +test('should return true for tag merges', () => { + expect(isIgnored("Merge tag '1.1.1'")).toBe(true); + expect(isIgnored("Merge tag 'a tag'")).toBe(true); +}); + +test('should return true for tag merges with newline characters', () => { + expect(isIgnored("Merge tag '1.1.1'\n")).toBe(true); + expect(isIgnored("Merge tag '1.1.1'\r\n")).toBe(true); +}); + +test('should return true for tag merges with multiple newline characters', () => { + expect(isIgnored("Merge tag '1.1.1'\n\n\n")).toBe(true); + expect(isIgnored("Merge tag '1.1.1'\r\n\r\n\r\n")).toBe(true); +}); + +test('should return true for tag merges with newline characters and more characters after it', () => { + expect(isIgnored("Merge tag '1.1.1'\n ")).toBe(true); + expect(isIgnored("Merge tag '1.1.1'\r\n # some comment")).toBe(true); +}); + test('should return true for revert commits', () => { expect( isIgnored( @@ -133,6 +153,10 @@ test('should return false for commits containing, but not starting, with merge b expect(isIgnored('foo bar Merge branch xxx')).toBe(false); }); +test('should return false for commits containing, but not starting, with merge tag', () => { + expect(isIgnored("foo bar Merge tag '1.1.1'")).toBe(false); +}); + test('should return false for ignored message if defaults is false', () => { expect( isIgnored('Auto-merged develop into master', {