fix(backports/apply): scope cherry-pick to target package, ignore other-package conflicts - #20541
Merged
Merged
Conversation
…er-package conflicts When a commit on main touches multiple packages and is cherry-picked onto a backport branch that does not include all of those packages, git cherry-pick produces modify/delete (DU) conflicts for absent packages, or UU conflicts when the branch evolved those files independently. The apply command was surfacing these as status: conflict, blocking the backport even when the target package's changes had applied cleanly. Added resetNonPackageChanges() which, after every cherry-pick, iterates git status --porcelain and resets every file outside the target package directory back to HEAD. Files present in HEAD are restored via git checkout HEAD; files absent from HEAD (modify/delete conflicts) are removed via git rm --force. Errors are non-fatal — conflictingFiles() is the authoritative gate for genuine remaining conflicts. Three integration tests added: - TestApplyIntegration_IgnoresConflictsInOtherPackages: DU conflict in absent package resolved via git rm → status: success - TestApplyIntegration_IgnoresRegularConflictInOtherPackage: UU conflict in present package reset to branch version → status: success - TestApplyIntegration_DiscardsCleanChangesInOtherPackage: clean change in other package discarded → status: success Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
mrodm
commented
Aug 5, 2026
| return nil, fmt.Errorf("computing relative package dir: %w", err) | ||
| } | ||
| relPkgDir = filepath.ToSlash(relPkgDir) | ||
| a.resetNonPackageChanges(relPkgDir) |
Collaborator
Author
There was a problem hiding this comment.
If a Pull Request contains changes in two different packages and it is selected to backport to one of those specific packages, this function removes the files that are not related to the selected package.
For instance, a pull request updates kubernetes and security_detection_engine packages. The user selects to backport just the kubernetes package. Then this process ensures that the changes about security_detection_engine are not part of the backport process.
mrodm
marked this pull request as ready for review
August 5, 2026 10:27
💚 Build Succeeded
cc @mrodm |
teresaromero
approved these changes
Aug 5, 2026
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed commit message
Author's Checklist
go test -run TestApplyIntegration ./dev/backports/apply/— all 14 integration tests pass (11 pre-existing + 3 new)dev/backports/apply/— root module build unaffectedHow to test this PR locally
Real-world examples:
status: conflictbefore this fixRelated issues