Skip to content

Commit 691a52d

Browse files
authored
fix(rules): ignore cherry-picks in signed-off-by (#4625)
Before this change, the rule `signed-off-by` was rejecting cherry picked commits. The cherry pick message wasn't appearing as the last line. With this in place, the rule will treat cherry picked commits as regular commits. Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
1 parent 53ce21e commit 691a52d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

@commitlint/rules/src/signed-off-by.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ Signed-off-by:
1616
1717
# Please enter the commit message for your changes. Lines starting
1818
# with '#' will be ignored, and an empty message aborts the commit.
19+
`,
20+
21+
withSignoffAndCherryPick: `test: subject
22+
23+
message body
24+
25+
Signed-off-by:
26+
27+
(cherry picked from commit 1234567aB)
1928
`,
2029
};
2130

@@ -26,6 +35,7 @@ const parsed = {
2635
inSubject: parse(messages.inSubject),
2736
inBody: parse(messages.inBody),
2837
withSignoffAndComments: parse(messages.withSignoffAndComments),
38+
withSignoffAndCherryPick: parse(messages.withSignoffAndCherryPick),
2939
};
3040

3141
test('empty against "always signed-off-by" should fail', async () => {
@@ -109,3 +119,23 @@ test('inBody against "never signed-off-by" should succeed', async () => {
109119
const expected = true;
110120
expect(actual).toEqual(expected);
111121
});
122+
123+
test("cherry pick marker should be ignored", async () => {
124+
const [actual] = signedOffBy(
125+
await parsed.withSignoffAndCherryPick,
126+
"always",
127+
"Signed-off-by:",
128+
);
129+
const expected = true;
130+
expect(actual).toEqual(expected);
131+
});
132+
133+
test('cherry pick marker with "never signed-off-by" should fail', async () => {
134+
const [actual] = signedOffBy(
135+
await parsed.withSignoffAndCherryPick,
136+
"never",
137+
"Signed-off-by:",
138+
);
139+
const expected = false;
140+
expect(actual).toEqual(expected);
141+
});

@commitlint/rules/src/signed-off-by.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import message from "@commitlint/message";
22
import toLines from "@commitlint/to-lines";
33
import { SyncRule } from "@commitlint/types";
44

5+
const CHERRY_PICK_REGEX = /^\(cherry picked from commit [0-9a-f]{7,64}\)$/i;
6+
57
export const signedOffBy: SyncRule<string> = (
68
parsed,
79
when = "always",
@@ -11,6 +13,8 @@ export const signedOffBy: SyncRule<string> = (
1113
(ln) =>
1214
// skip comments
1315
!ln.startsWith("#") &&
16+
// skip cherry pick commits
17+
!CHERRY_PICK_REGEX.test(ln.trim()) &&
1418
// ignore empty lines
1519
Boolean(ln),
1620
);

0 commit comments

Comments
 (0)