Skip to content

Fix inter-branch-merge to create proper merge commit when using ResetToTargetPaths#16673

Open
PureWeen wants to merge 1 commit intomainfrom
fix/inter-branch-merge-missing-merge
Open

Fix inter-branch-merge to create proper merge commit when using ResetToTargetPaths#16673
PureWeen wants to merge 1 commit intomainfrom
fix/inter-branch-merge-missing-merge

Conversation

@PureWeen
Copy link
Copy Markdown
Member

@PureWeen PureWeen commented Apr 2, 2026

Problem

When ResetToTargetPaths is configured, the inter-branch-merge.ps1 script creates the merge branch from the source branch HEAD and only resets specified files to the target branch. This means the merge branch is just source + a few overwritten files — it never merges the target branch content. The result is a linear commit (1 parent), not a merge commit (2 parents).

This causes:

  • Missing target-only content: APIs, nullable fixes, platform versions, and other changes that exist only on the target branch are absent
  • Build failures: The PR compiles source code against the wrong SDK/TFM versions since target branch Directory.Build.props (or other non-reset files) are missing
  • Merge conflicts: When the PR is merged, GitHub sees conflicting changes because the target branch changes were never incorporated

Root Cause

The script flow (lines ~189-223):

  1. git checkout MergeFromBranch — switches to source (e.g., main)
  2. git checkout -B merge/main-to-target — creates branch at source HEAD
  3. ResetFilesToTargetBranch — resets specific files to target
  4. No git merge ever happens

How it was discovered

In dotnet/maui PR #34789 (mainnet11.0), the merge branch was missing:

  • Directory.Build.props with _MauiDotNetVersionMajor=11 (had 10 from main)
  • iOS platform version 26.2 (had 26.0 from main)
  • All nullable annotation fixes done on net11.0
  • New APIs like VisualStateManager.InvalidateVisualStates

This required 4 manual fix commits that would have been unnecessary with a proper merge.

Fix

When ResetToTargetPaths is configured:

  1. Start the merge branch from the target branch (not source)
  2. git merge --no-ff source into it to create a proper merge commit
  3. Use -X theirs to auto-resolve conflicts in favor of source (since ResetToTargetPaths will overwrite target-wins files in the next step)
  4. Apply ResetFilesToTargetBranch as before

Without ResetToTargetPaths, the original behavior is preserved.

Local simulation

Tested locally with dotnet/maui (mainnet11.0):

Buggy (current) Fixed (with merge)
Merge commit NO (1 parent) ❌ YES (2 parents) ✅
_MauiDotNetVersionMajor 10 ❌ 11 ✅
IosTargetFrameworkVersion 26.0 ❌ 26.2 ✅
InvalidateVisualStates API MISSING ❌ PRESENT ✅
Source fixes (EscapeForString) present ✅ present ✅

@PureWeen PureWeen force-pushed the fix/inter-branch-merge-missing-merge branch 2 times, most recently from 6ebd4fa to 6d20d47 Compare April 2, 2026 20:39
…ToTargetPaths

When ResetToTargetPaths is configured, the script creates the merge branch
from the source branch HEAD and only resets specified files to the target
branch. This means the merge branch is missing all target-only content
(APIs, platform fixes, version updates, etc.) — it's a linear commit off
source, not a real merge.

This causes:
- Build failures from missing target branch fixes (nullable annotations,
  platform version mismatches, etc.)
- Merge conflicts when the PR is completed because the target branch's
  changes were never incorporated

The fix creates a proper merge commit when ResetToTargetPaths is used:
1. Start the merge branch from the target branch (not source)
2. Merge source into it with --no-ff to create a merge commit
3. Use -X theirs to auto-resolve conflicts (ResetToTargetPaths will
   overwrite target-wins files in the next step anyway)
4. Then apply ResetToTargetPaths as before

Without ResetToTargetPaths, the original behavior is preserved — the
branch is created from source and GitHub's merge button does the merge.

Discovered in dotnet/maui PR #34789 where the main→net11.0 merge was
missing all net11.0-specific content (Directory.Build.props TFMs,
nullable fixes, PublicAPI entries) because the script never merged
net11.0 into the branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@PureWeen PureWeen force-pushed the fix/inter-branch-merge-missing-merge branch from 6d20d47 to a0f3105 Compare April 2, 2026 20:43
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.

Improve automated branch codeflow to avoid having to merge eng\* changes

1 participant