Skip to content

Prefer complete merged changes when backporting squash-merged PRs - #17218

Merged
akoeplinger merged 1 commit into
dotnet:mainfrom
svick:backport-merged-change
Aug 4, 2026
Merged

Prefer complete merged changes when backporting squash-merged PRs#17218
akoeplinger merged 1 commit into
dotnet:mainfrom
svick:backport-merged-change

Conversation

@svick

@svick svick commented Jul 29, 2026

Copy link
Copy Markdown
Member

Fixes #17205.

The backport workflow currently replays every original PR commit using git am. Intermediate commits can conflict with the target branch even when the final merged change applies cleanly.

This change:

  • Compares a one-parent merged commit's diff with the complete PR diff using git patch-id --verbatim.
  • Cherry-picks the merged commit when it is verified to represent the complete change.
  • Retains git am for multi-commit rebases, two-parent merge commits, unverifiable cases, and workflows specifying additional git am switches.
  • Fetches refs/pull/<number>/head before git am, providing objects required for three-way application of patches from forks.
  • Falls back safely if inspecting or cherry-picking the merged commit fails.

The production workflow script was exercised in dry mode against squash, merge-commit, rebase, missing-object, custom-switch, and conflict scenarios. Here, "dry mode" means the actual inline script ran against temporary local Git repositories with mocked GitHub APIs and intercepted pushes.

Note

This pull request was created with GitHub Copilot.

Prefer verified complete one-parent merge changes and fetch pull request refs before falling back to git am.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 29, 2026 14:15
@svick
svick marked this pull request as ready for review July 29, 2026 14:18

Copilot AI 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.

Pull request overview

This PR updates the reusable backport workflow to avoid replaying intermediate PR commits (via git am) when the final merged PR change can be safely applied as a single commit, reducing unnecessary conflicts—especially for squash-merged PRs and PRs from forks.

Changes:

  • Downloads both the full mailbox patch series and the complete PR diff, then compares patch-ids to verify whether the merged commit represents the full PR change.
  • Preferentially cherry-picks the merged commit when verification succeeds, otherwise falls back to git am.
  • Fetches refs/pull/<number>/head before git am to improve three-way patch application when PR objects aren’t present locally.
Comments suppressed due to low confidence (1)

.github/workflows/backport-base.yml:304

  • merged_diff_file is not guaranteed to exist (e.g., no merge_commit_sha, or merge commit with >2 parents, or verification skipped). git reset HEAD -- ... ${merged_diff_file} will fail if the file is missing, which can break the conflict-resolution flow after a failed git am. Make the reset conditional on the file existing.
              await exec.exec(`git reset HEAD -- ${patch_file} ${diff_file} ${merged_diff_file}`);

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

Comment thread .github/workflows/backport-base.yml
@akoeplinger
akoeplinger merged commit 1e2b532 into dotnet:main Aug 4, 2026
2 of 4 checks passed
@svick
svick deleted the backport-merged-change branch August 4, 2026 10:05
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.

Backport workflow should prefer the merged PR change over replaying intermediate commits

3 participants