Skip to content

fix(rules): ignore cherry-picks in signed-off-by#4625

Merged
escapedcat merged 1 commit intoconventional-changelog:masterfrom
mzedel:fix/signed-off-by-cherries
Feb 19, 2026
Merged

fix(rules): ignore cherry-picks in signed-off-by#4625
escapedcat merged 1 commit intoconventional-changelog:masterfrom
mzedel:fix/signed-off-by-cherries

Conversation

@mzedel
Copy link
Contributor

@mzedel mzedel commented Feb 18, 2026

Description

Before this change, the rule signed-off-by was rejecting cherry picked commits, as the cherry pick message wasn't appearing as the last line. With this in place, the rule will treat cherry picked commits just the same as regular commits.

Motivation and Context

Addresses #2704 to remove the need for the trailer-exists workaround.

Usage examples

  1. cherry-pick any commit with cherry-pick -x commit-id
  2. run commitlint

or with the current change:

yarn build

printf 'fix: 🍒\n\nSigned-off-by: Manuel Zedel <manuel.zedel@northern.tech>\n\ncherry picked from commit 123' | commitlint --config @commitlint/cli/fixtures/signoff/commitlint.config.js

How Has This Been Tested?

I added a unit-test, watched it fail and then fixed the implementation to make the test pass.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@qodo-code-review
Copy link

Review Summary by Qodo

Fix signed-off-by rule to ignore cherry-pick trailers

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fixes signed-off-by rule rejecting cherry-picked commits
• Filters out cherry-pick trailer lines during validation
• Adds test case for cherry-pick scenario
Diagram
flowchart LR
  A["Cherry-picked commit"] -->|"contains cherry-pick trailer"| B["signed-off-by rule"]
  B -->|"filters cherry-pick lines"| C["validates Signed-off-by presence"]
  C -->|"passes validation"| D["commit accepted"]
Loading

Grey Divider

File Changes

1. @commitlint/rules/src/signed-off-by.ts 🐞 Bug fix +2/-0

Filter cherry-pick trailer lines in validation

• Added filter to skip lines starting with cherry picked from commit
• Preserves existing comment filtering logic
• Allows commits with both Signed-off-by and cherry-pick trailers to pass validation

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


2. @commitlint/rules/src/signed-off-by.test.ts 🧪 Tests +20/-0

Add cherry-pick scenario test coverage

• Added new test message withSignoffAndCherryPick with both trailers
• Added parsed variant for the new test message
• Added test case verifying cherry-pick commits pass with always mode

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


Grey Divider

Qodo Logo

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 18, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@qodo-code-review
Copy link

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (1)

Grey Divider


Action required

1. Cherry-pick pattern missing parenthesis 📎 Requirement gap ⛯ Reliability
Description
Git's cherry-pick -x appends (cherry picked from commit <hash>) with a leading (, but the
filter uses ln.startsWith("cherry picked from commit") (no parenthesis), so real cherry-picked
commits produced by git will not be filtered and commitlint will still fail on them. The test
fixture also omits the parenthesis, so it does not exercise the real git output.
Code

@commitlint/rules/src/signed-off-by.ts[R14-15]

+			// skip cherry pick commits
+			!ln.startsWith("cherry picked from commit") &&
Evidence
Compliance rule 7 requires that commitlint correctly handles the `(cherry picked from commit
<hash>) line appended by git cherry-pick -x. Git's actual output includes a leading (`, but the
added filter !ln.startsWith("cherry picked from commit") omits it, meaning the pattern never
matches real git cherry-pick output. The test fixture at line 27 also uses `cherry picked from
commit 123` (no parenthesis), so the test passes but does not validate the real scenario.

Commitlint Passes on Cherry-Picked Commits
@commitlint/rules/src/signed-off-by.ts[14-15]
@commitlint/rules/src/signed-off-by.test.ts[27-27]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The filter added to skip cherry-pick lines uses `ln.startsWith(&quot;cherry picked from commit&quot;)`, but `git cherry-pick -x` actually appends `(cherry picked from commit &lt;hash&gt;)` — with a leading parenthesis `(`. The current pattern will never match real git output, leaving the original bug unfixed.

## Issue Context
Git&#x27;s `-x` flag appends a line of the form `(cherry picked from commit &lt;hash&gt;)` to the commit message body. The test fixture at line 27 also lacks the parenthesis (`cherry picked from commit 123`), so the test passes but does not exercise the real git format, giving a false sense of correctness.

## Fix Focus Areas
- @commitlint/rules/src/signed-off-by.ts[15-15] — change `&quot;cherry picked from commit&quot;` to `&quot;(cherry picked from commit&quot;`
- @commitlint/rules/src/signed-off-by.test.ts[27-27] — update test message from `cherry picked from commit 123` to `(cherry picked from commit 123)`

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Test fixture uses wrong cherry-pick format 🐞 Bug ✓ Correctness
Description
The new test fixture withSignoffAndCherryPick uses cherry picked from commit 123 (no
parentheses), which is a format that git cherry-pick -x never produces. Because both the fixture
and the implementation share the same incorrect format, the test passes while the real-world
scenario remains completely untested and broken.
Code

@commitlint/rules/src/signed-off-by.test.ts[R21-28]

+	withSignoffAndCherryPick: `test: subject
+
+message body
+
+Signed-off-by:
+
+cherry picked from commit 123
`,
Evidence
The fixture at lines 21-28 omits the parentheses that git always adds. The PR description's own
usage example also uses the wrong format (cherry picked from commit 123). Because the
implementation filter was written to match this same wrong format, the test passes — but it
validates a message that real git never generates. A grep for \(cherry picked across the entire
repo returns zero results, confirming the actual git format is never exercised.

@commitlint/rules/src/signed-off-by.test.ts[21-28]
@commitlint/rules/src/signed-off-by.test.ts[123-131]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The test fixture `withSignoffAndCherryPick` uses `cherry picked from commit 123` without parentheses. The actual output of `git cherry-pick -x` is `(cherry picked from commit &lt;sha&gt;)`. The fixture must be updated to reflect the real format so the test provides meaningful coverage.

## Issue Context
The implementation filter and the fixture were both written with the wrong format, so they agree with each other but both disagree with reality. Fixing only the fixture (without fixing the implementation) will cause the test to fail, which is the correct signal that the implementation also needs to be fixed.

## Fix Focus Areas
- @commitlint/rules/src/signed-off-by.test.ts[21-28]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the signed-off-by rule where cherry-picked commits were incorrectly rejected. The rule now treats cherry-picked commits the same as regular commits by filtering out the cherry-pick trailer line when checking if the last line is a "Signed-off-by" trailer.

Changes:

  • Modified the signed-off-by rule to skip lines starting with "(cherry picked from commit" when determining the last meaningful line
  • Added test coverage to verify that cherry-pick markers are properly ignored

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
@commitlint/rules/src/signed-off-by.ts Added filter to skip cherry-pick trailer lines
@commitlint/rules/src/signed-off-by.test.ts Added test case and test data for cherry-pick scenario

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@escapedcat
Copy link
Member

Thanks! Please have a look at the open comments

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@escapedcat
Copy link
Member

escapedcat commented Feb 18, 2026

Some more comments. Have a look and tackle what's valid please, thanks!

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>
@mzedel mzedel force-pushed the fix/signed-off-by-cherries branch from e8be3cc to 08471b7 Compare February 18, 2026 19:15
@mzedel
Copy link
Contributor Author

mzedel commented Feb 18, 2026

@escapedcat thanks for looking into this!
So far we haven't gotten to automated reviews, so I appreciate the experience as an added benefit 😃!

@escapedcat
Copy link
Member

So far we haven't gotten to automated reviews, so I appreciate the experience as an added benefit 😃!

You're welcome! copilot reviews are really helpful.

This was referenced Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants