@@ -15,6 +15,10 @@ The current branch
1515Create a PR even if the only commits are from dotnet-maestro[bot]
1616. PARAMETER QuietComments
1717Do not tag commiters, do not comment on PR updates. Reduces GitHub notifications
18+ . PARAMETER ResetToTargetPaths
19+ Semicolon-separated list of glob patterns for files to reset to the target branch version.
20+ After the merge branch is created, files matching these patterns will be checked out from
21+ the target branch and committed, resolving potential merge conflicts for these files.
1822#>
1923[CmdletBinding (SupportsShouldProcess = $true )]
2024param (
@@ -36,7 +40,10 @@ param(
3640
3741 [switch ]$AllowAutomatedCommits ,
3842
39- [switch ]$QuietComments
43+ [switch ]$QuietComments ,
44+
45+ [Alias (' r' )]
46+ [string ]$ResetToTargetPaths = " "
4047)
4148
4249$ErrorActionPreference = ' stop'
@@ -105,6 +112,62 @@ function GetCommitterGitHubName($sha) {
105112 return $null
106113}
107114
115+ function ResetFilesToTargetBranch ($patterns , $targetBranch ) {
116+ if (-not $patterns -or $patterns.Count -eq 0 ) {
117+ return
118+ }
119+
120+ Write-Host " Resetting files to $targetBranch for patterns: $ ( $patterns -join ' , ' ) "
121+
122+ # Verify the target branch exists
123+ $branchExists = & git rev- parse -- verify " origin/$targetBranch " 2>&1
124+ if ($LASTEXITCODE -ne 0 ) {
125+ Write-Warning " Target branch 'origin/$targetBranch ' does not exist. Skipping file reset."
126+ return
127+ }
128+
129+ foreach ($pattern in $patterns ) {
130+ $pattern = $pattern.Trim ()
131+ if (-not $pattern ) {
132+ continue
133+ }
134+
135+ Write-Host " Processing pattern: $pattern "
136+
137+ # Use git checkout to reset files matching the pattern to the target branch
138+ # The -- is needed to separate the revision from the pathspec
139+ try {
140+ # First check if there are any files matching the pattern in the target branch
141+ $matchingFiles = & git ls- tree - r -- name- only " origin/$targetBranch " -- $pattern 2>&1
142+ if ($LASTEXITCODE -ne 0 ) {
143+ Write-Warning " Failed to list files for pattern '$pattern ': $matchingFiles "
144+ continue
145+ }
146+
147+ if ($matchingFiles ) {
148+ Write-Host " Found files matching pattern '$pattern ': $ ( $matchingFiles -join ' , ' ) "
149+ Invoke-Block { & git checkout " origin/$targetBranch " -- $pattern }
150+
151+ # Check if there are any changes to commit
152+ $status = & git status -- porcelain
153+ if ($status ) {
154+ # Add all changes (the checkout already modified the specific files)
155+ Invoke-Block { & git add - A }
156+ Invoke-Block { & git commit - m " Reset '$pattern ' to $targetBranch " }
157+ Write-Host -f Green " Successfully reset '$pattern ' to $targetBranch "
158+ } else {
159+ Write-Host " No changes to commit for pattern '$pattern '"
160+ }
161+ } else {
162+ Write-Host -f Yellow " No files found matching pattern '$pattern ' in $targetBranch "
163+ }
164+ }
165+ catch {
166+ Write-Warning " Failed to reset pattern '$pattern ' to $targetBranch . Error: $_ "
167+ }
168+ }
169+ }
170+
108171# see https://git-scm.com/docs/pretty-formats
109172$formatString = ' %h %cn <%ce>: %s (%cr)'
110173
@@ -151,6 +214,12 @@ try {
151214 $mergeBranchName = " merge/$MergeFromBranch -to-$MergeToBranch "
152215 Invoke-Block { & git checkout - B $mergeBranchName }
153216
217+ # Reset specified files to target branch if ResetToTargetPaths is configured
218+ if ($ResetToTargetPaths ) {
219+ $patterns = $ResetToTargetPaths -split " ;"
220+ ResetFilesToTargetBranch $patterns $MergeToBranch
221+ }
222+
154223 $remoteName = ' origin'
155224 $prOwnerName = $RepoOwner
156225 $prRepoName = $RepoName
0 commit comments