Skip to content

Don't fail inter-branch merge when existing PR can't be fast-forwarded - #17091

Merged
akoeplinger merged 1 commit into
mainfrom
marcpopMSFT-improveinterbranchflowfailures
Jul 14, 2026
Merged

akoeplinger merged 1 commit into
mainfrom
marcpopMSFT-improveinterbranchflowfailures

Conversation

@marcpopMSFT

Copy link
Copy Markdown
Member

Problem

The inter-branch merge workflow (inter-branch-merge.ps1) updates an existing merge/<from>-to-<to> PR with a plain (non-force) git push. When that PR branch has diverged from the freshly generated merge branch, the push is rejected as non-fast-forward. This happens routinely when:

The rejection was already caught, but git's exit code (1) leaked through as the process exit code (there is no later native command under -QuietComments, and no exit 0), so the job failed red. Result: notification noise and a sea of red on the dotnet/sdk actions dashboard even though nothing was actually wrong.

There is no "neutral" conclusion available for a normal workflow job (that only exists via the Checks API for GitHub Apps), so the fix makes the benign case report success.

Fix

In the existing-PR update path only:

  • Preserved: the non-force fast-forward push. When it can fast-forward, the PR is updated exactly as before.
  • Swallowed (success): only a non-fast-forward rejection ([rejected] / non-fast-forward / fetch first / tip of your current branch is behind). The existing PR is left untouched and the job succeeds. LASTEXITCODE is reset so the rejection no longer leaks as the process exit code.
  • Still fails (red): any other push failure now throws instead of being silently caught. Previously the blanket catch also hid auth/network/permission errors — so this is actually stricter than before.

All earlier steps (fetch/checkout/reset/ResetToTargetPaths/PR lookup) are untouched and still fail normally. The non-PR path (force-push + create PR) and comment behavior are unchanged.

Validation

  • Parser::ParseFile — no parse errors.
  • Reproduced a real non-fast-forward rejection with throwaway git repos: git push exits 1 → classified benign → LASTEXITCODE reset to 0 → shell exits 0. A fast-forwardable push still takes the success branch; non-matching errors fall through to throw.

Fixes #16606

The inter-branch merge workflow does a non-force push to update an
existing merge/<from>-to-<to> PR. When that PR branch has diverged
(manual conflict-resolution commits, or a regenerated ResetToTargetPaths
commit), the push is rejected as non-fast-forward. The rejection was
caught but git's exit code (1) leaked through as the process exit code,
so the job failed red -- creating notification noise and a red actions
dashboard even though nothing was actually wrong.

Now the existing-PR update path distinguishes a benign non-fast-forward
rejection (leave the PR untouched, succeed) from a genuine push failure
(auth/network/permissions), which still throws and fails the job. The
fast-forward update behavior is preserved for repos that rely on it.

Fixes #16606

Co-authored-by: Copilot <[email protected]>
Copilot-Session: db9119eb-05f0-44f4-a5ca-ffc406876b29
@marcpopMSFT

Copy link
Copy Markdown
Member Author

@lbussell per our conversation earlier today. Proposed fix to swallow the error when the branch can't be fast forwarded so we stop getting red actions and notifications of failing builds.

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 adjusts the inter-branch merge workflow script to avoid failing the workflow job when updating an existing merge/<from>-to-<to> PR branch cannot be fast-forwarded, while still failing on genuine git push errors (auth/network/permissions).

Changes:

  • Reworks the “existing PR update” branch push to capture git push output/exit code and explicitly classify non-fast-forward rejection as a benign condition.
  • Resets LASTEXITCODE to prevent a benign non-fast-forward rejection from leaking as the overall PowerShell process exit code.
  • Tightens failure handling by throwing on non-benign push failures instead of blanket-catching and warning.

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

@marcpopMSFT
marcpopMSFT requested a review from a team July 10, 2026 17:22
@akoeplinger
akoeplinger merged commit a879e5a into main Jul 14, 2026
3 of 5 checks passed
@akoeplinger
akoeplinger deleted the marcpopMSFT-improveinterbranchflowfailures branch July 14, 2026 18:48
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 15, 2026
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.

The inter branch merge workflow fails if there have been manual commits to the merge/ branch

3 participants