Skip to content

Commit

Permalink
fix(is-ignored): ignore merge tag commit messages (#2920)
Browse files Browse the repository at this point in the history
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'`
  • Loading branch information
gaetanmaisse committed Dec 15, 2021
1 parent f21eb16 commit 914782a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions @commitlint/is-ignored/src/defaults.ts
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions @commitlint/is-ignored/src/is-ignored.test.ts
Expand Up @@ -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(
Expand Down Expand Up @@ -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', {
Expand Down

0 comments on commit 914782a

Please sign in to comment.