Skip to content

Add backport apply command - #3414

Open
tianyiy-tim wants to merge 1 commit into
aws:backport-stack/analyzefrom
tianyiy-tim:add-backport-apply
Open

Add backport apply command#3414
tianyiy-tim wants to merge 1 commit into
aws:backport-stack/analyzefrom
tianyiy-tim:add-backport-apply

Conversation

@tianyiy-tim

@tianyiy-tim tianyiy-tim commented Aug 10, 2026

Copy link
Copy Markdown
Member

Issues:

Addresses P425131803

Description of changes:

analyze only reports which branches are affected. Acting on that still means cherry-picking the fix onto each branch by hand, which for a fix that hits seven branches is seven rounds of the same work.

This pull request adds apply, which cherry-picks the fix onto one local branch per affected branch, named backport-<release branch>-<fix>.

Stacked on #3389. The base here is backport-stack/analyze, a scaffolding branch holding that PR's commits, so this diff is only the 7 files this change touches. I will retarget it to main once #3389 merges. Please don't merge it into the scaffolding branch.

Call-outs:

  • Each pick runs in its own worktree, so the branch you have checked out never moves and a half-finished cherry-pick can't strand your working tree mid-merge.

  • A clean pick leaves the branch and removes its worktree. A conflict keeps the worktree, stopped mid-cherry-pick, so you can fix it in place.

  • Branches that analyze could not settle are left out. Cherry-picking onto one of those would be a guess.

  • Cherry-picks pass -x so the commit carries the "cherry picked from commit" line. That's one of the three signals analyze uses to spot a branch that already has the fix, so without it the tool couldn't recognise its own backports on a later run.

  • Each branch is cut from the same remote-tracking release branch analyze judged, not from origin. Locally origin is usually a fork that is behind on the release branches, and a backport built on a base the analysis never saw can cherry-pick cleanly and still be the wrong change.

  • Nothing is pushed and no pull request is opened. That's the next one.

Testing:

Unit tests - 19 new, 141 total:

python3 -m unittest testing.test_engine

They cover the branch naming, which branches get picked, the run file it reads, that the worktree starts from the ref analyze judged rather than origin, and that a clean pick removes its worktree while a conflict keeps it.

Real fix - ran apply for ac3aee310 across all 7 release branches: 2 applied cleanly and 5 conflicted. Confirmed the conflicted worktrees were left mid-cherry-pick with UU markers, the clean picks produced commits on top of the release branch with the original subject kept, and the -x trailer is written and found by branch_mentions_cherry_pick.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@tianyiy-tim
tianyiy-tim force-pushed the backport-stack/analyze branch from 6d91d1c to 2186b59 Compare August 10, 2026 18:09
@tianyiy-tim
tianyiy-tim force-pushed the backport-stack/analyze branch from 2186b59 to 86a29a2 Compare August 10, 2026 21:43
@tianyiy-tim
tianyiy-tim force-pushed the backport-stack/analyze branch from 86a29a2 to bb4edf2 Compare August 10, 2026 22:20
@tianyiy-tim
tianyiy-tim force-pushed the backport-stack/analyze branch from bb4edf2 to 49f8504 Compare August 11, 2026 17:53
@tianyiy-tim
tianyiy-tim force-pushed the backport-stack/analyze branch from 49f8504 to 8618685 Compare August 12, 2026 16:46
@tianyiy-tim
tianyiy-tim force-pushed the add-backport-apply branch 2 times, most recently from 93dad97 to e57e9ed Compare August 13, 2026 18:39
@tianyiy-tim
tianyiy-tim marked this pull request as ready for review August 13, 2026 19:19
@tianyiy-tim
tianyiy-tim requested a review from a team as a code owner August 13, 2026 19:19

@nhatnghiho nhatnghiho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good job with this PR! Few minor comments below

Comment thread util/backport/src/main.py
Comment on lines +48 to +52
p.add_argument(
"--yes",
action="store_true",
help="Skips the confirm. Useful for test scripts",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It isn't very clear to me why we need --yes? Can you elaborate more in the help message why test scripts need it?

Comment thread util/backport/README.md
│ ├── replay_fixes.py # replays real fixes and grades them
│ ├── fixes.txt # 39 real fixes to replay
│ └── answer_key.txt # which branches each one should flag
└── .backport-runs/ # the last analyze result, not checked in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: add a section in your README explaining the structure of the runstate files in .backport-runs/

Reads the run analyze saved and cherry-picks the fix onto one local branch per
affected branch, named backport-<release branch>-<fix>. Branches analyze could
not settle are left out, since picking onto one of those would be a guess

Each pick runs in its own worktree, so the branch you have checked out never
moves and a half finished cherry-pick cannot strand your own working tree mid
merge. A clean pick leaves the branch and removes its worktree, a conflict
keeps the worktree so it can be resolved in place

Each branch is cut from the same remote-tracking release branch analyze judged, not
from wherever origin happens to point. A fork is usually behind on the release
branches, and a backport built on a base the analysis never saw is not the backport
that was asked for

Nothing is pushed and no pull request is opened
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants