Skip to content

Commit 914782a

Browse files
authored
fix(is-ignored): ignore merge tag commit messages (#2920)
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'`
1 parent f21eb16 commit 914782a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

@commitlint/is-ignored/src/defaults.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const wildcards: Matcher[] = [
1818
test(
1919
/^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m
2020
),
21+
test(/^(Merge tag (.*?))(?:\r?\n)*$/m),
2122
test(/^(R|r)evert (.*)/),
2223
test(/^(fixup|squash)!/),
2324
isSemver,

@commitlint/is-ignored/src/is-ignored.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ test('should return true for branch merges with newline characters and more char
7070
);
7171
});
7272

73+
test('should return true for tag merges', () => {
74+
expect(isIgnored("Merge tag '1.1.1'")).toBe(true);
75+
expect(isIgnored("Merge tag 'a tag'")).toBe(true);
76+
});
77+
78+
test('should return true for tag merges with newline characters', () => {
79+
expect(isIgnored("Merge tag '1.1.1'\n")).toBe(true);
80+
expect(isIgnored("Merge tag '1.1.1'\r\n")).toBe(true);
81+
});
82+
83+
test('should return true for tag merges with multiple newline characters', () => {
84+
expect(isIgnored("Merge tag '1.1.1'\n\n\n")).toBe(true);
85+
expect(isIgnored("Merge tag '1.1.1'\r\n\r\n\r\n")).toBe(true);
86+
});
87+
88+
test('should return true for tag merges with newline characters and more characters after it', () => {
89+
expect(isIgnored("Merge tag '1.1.1'\n ")).toBe(true);
90+
expect(isIgnored("Merge tag '1.1.1'\r\n # some comment")).toBe(true);
91+
});
92+
7393
test('should return true for revert commits', () => {
7494
expect(
7595
isIgnored(
@@ -133,6 +153,10 @@ test('should return false for commits containing, but not starting, with merge b
133153
expect(isIgnored('foo bar Merge branch xxx')).toBe(false);
134154
});
135155

156+
test('should return false for commits containing, but not starting, with merge tag', () => {
157+
expect(isIgnored("foo bar Merge tag '1.1.1'")).toBe(false);
158+
});
159+
136160
test('should return false for ignored message if defaults is false', () => {
137161
expect(
138162
isIgnored('Auto-merged develop into master', {

0 commit comments

Comments
 (0)