Skip to content

Commit 6d20d47

Browse files
PureWeenCopilot
andcommitted
Fix inter-branch-merge to create proper merge commit when using ResetToTargetPaths
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>
1 parent 0a948ff commit 6d20d47

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

.github/workflows/scripts/inter-branch-merge.ps1

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ function ResetFilesToTargetBranch($patterns, $targetBranch) {
126126
return
127127
}
128128

129-
# Configure git user for the commit
130-
# Use GitHub Actions bot identity
131-
Invoke-Block { & git config user.name "github-actions[bot]" }
132-
Invoke-Block { & git config user.email "41898282+github-actions[bot]@users.noreply.github.com" }
133-
134129
# Track which patterns had changes
135130
$processedPatterns = @()
136131

@@ -181,6 +176,11 @@ $formatString = '%h %cn <%ce>: %s (%cr)'
181176

182177
try {
183178
Invoke-Block { & git fetch --quiet origin }
179+
180+
# Configure git user for any commits (merge commits, reset commits)
181+
Invoke-Block { & git config user.name "github-actions[bot]" }
182+
Invoke-Block { & git config user.email "41898282+github-actions[bot]@users.noreply.github.com" }
183+
184184
Invoke-Block { & git checkout --quiet $MergeToBranch }
185185
Invoke-Block { & git reset --hard origin/$MergeToBranch }
186186

@@ -220,13 +220,28 @@ try {
220220
Write-Host $committersList
221221

222222
$mergeBranchName = "merge/$MergeFromBranch-to-$MergeToBranch"
223-
Invoke-Block { & git checkout -B $mergeBranchName }
224223

225-
# Reset specified files to target branch if ResetToTargetPaths is configured
224+
# When ResetToTargetPaths is configured, we need to create a proper merge commit
225+
# so that the target branch content is included. Without this, the merge branch
226+
# would just be the source branch with some files overwritten, missing all
227+
# target-only changes (APIs, fixes, platform versions, etc.).
226228
if ($ResetToTargetPaths) {
229+
# Start from the target branch and merge source into it
230+
Invoke-Block { & git checkout -B $mergeBranchName "origin/$MergeToBranch" }
231+
232+
# Merge source branch. Use -X theirs to auto-resolve conflicts in favor of
233+
# the source branch, since ResetToTargetPaths will overwrite target-wins files
234+
# in the next step anyway.
235+
Invoke-Block { & git merge --no-ff "origin/$MergeFromBranch" -X theirs -m "Merge branch '$MergeFromBranch' into $MergeToBranch" }
236+
227237
$patterns = $ResetToTargetPaths -split ";"
228238
ResetFilesToTargetBranch $patterns $MergeToBranch
229239
}
240+
else {
241+
# Without ResetToTargetPaths, the original behavior is fine: create a branch
242+
# from the source and let GitHub's merge button do the actual merge.
243+
Invoke-Block { & git checkout -B $mergeBranchName }
244+
}
230245

231246
$remoteName = 'origin'
232247
$prOwnerName = $RepoOwner

0 commit comments

Comments
 (0)