Fix inter-branch-merge to create proper merge commit when using ResetToTargetPaths#16673
Open
Fix inter-branch-merge to create proper merge commit when using ResetToTargetPaths#16673
Conversation
6ebd4fa to
6d20d47
Compare
…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>
6d20d47 to
a0f3105
Compare
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.
Problem
When
ResetToTargetPathsis configured, theinter-branch-merge.ps1script 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:
Directory.Build.props(or other non-reset files) are missingRoot Cause
The script flow (lines ~189-223):
git checkout MergeFromBranch— switches to source (e.g.,main)git checkout -B merge/main-to-target— creates branch at source HEADResetFilesToTargetBranch— resets specific files to targetgit mergeever happensHow it was discovered
In dotnet/maui PR #34789 (
main→net11.0), the merge branch was missing:Directory.Build.propswith_MauiDotNetVersionMajor=11(had10from main)26.2(had26.0from main)net11.0VisualStateManager.InvalidateVisualStatesThis required 4 manual fix commits that would have been unnecessary with a proper merge.
Fix
When
ResetToTargetPathsis configured:git merge --no-ffsource into it to create a proper merge commit-X theirsto auto-resolve conflicts in favor of source (sinceResetToTargetPathswill overwrite target-wins files in the next step)ResetFilesToTargetBranchas beforeWithout
ResetToTargetPaths, the original behavior is preserved.Local simulation
Tested locally with dotnet/maui (
main→net11.0):_MauiDotNetVersionMajorIosTargetFrameworkVersionInvalidateVisualStatesAPI