Skip to content

Commit 25e0854

Browse files
gfraiteurclaude
andcommitted
UpstreamMerge: force clean repository instead of blocking
Instead of blocking when the repository has uncommitted changes, run git reset --hard followed by git clean -xfd to force a clean state. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1e00f52 commit 25e0854

2 files changed

Lines changed: 39 additions & 9 deletions

File tree

src/PostSharp.Engineering.BuildTools/Tools/Git/UpstreamMerge.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,27 +240,29 @@ public static bool MergeUpstream( BuildContext context, UpstreamMergeSettings se
240240

241241
context.Console.WriteMessage( "Git credentials configured successfully." );
242242

243-
// ==================== STEP 2: Verify Clean Repository ====================
243+
// ==================== STEP 2: Force Clean Repository ====================
244244
context.Console.WriteMessage( "" );
245-
context.Console.WriteMessage( "Step 2: Verifying repository is clean..." );
245+
context.Console.WriteMessage( "Step 2: Force cleaning repository..." );
246246

247-
if ( !GitHelper.TryGetStatus( context, context.RepoDirectory, out var statuses ) )
247+
context.Console.WriteMessage( "Running git reset --hard..." );
248+
249+
if ( !GitHelper.TryResetHard( context ) )
248250
{
249-
context.Console.WriteError( "Failed to get repository status." );
251+
context.Console.WriteError( "Failed to reset repository." );
250252

251253
return false;
252254
}
253255

254-
if ( statuses.Length > 0 )
256+
context.Console.WriteMessage( "Running git clean -xfd..." );
257+
258+
if ( !GitHelper.TryClean( context ) )
255259
{
256-
context.Console.WriteError( "The repository must be clean before running upstream merge." );
257-
context.Console.WriteError( "The following files have uncommitted changes:" );
258-
context.Console.WriteImportantMessage( string.Join( Environment.NewLine, statuses ) );
260+
context.Console.WriteError( "Failed to clean repository." );
259261

260262
return false;
261263
}
262264

263-
context.Console.WriteMessage( "Repository is clean." );
265+
context.Console.WriteMessage( "Repository is now clean." );
264266

265267
// ==================== STEP 3: Identify Product Family Versions ====================
266268
context.Console.WriteMessage( "" );

src/PostSharp.Engineering.BuildTools/Utilities/GitHelper.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,34 @@ public static bool TryDeleteLocalBranch( BuildContext context, string branchName
522522
return true;
523523
}
524524

525+
public static bool TryResetHard( BuildContext context )
526+
{
527+
if ( !ToolInvocationHelper.InvokeTool(
528+
context.Console,
529+
"git",
530+
"reset --hard",
531+
context.RepoDirectory ) )
532+
{
533+
return false;
534+
}
535+
536+
return true;
537+
}
538+
539+
public static bool TryClean( BuildContext context )
540+
{
541+
if ( !ToolInvocationHelper.InvokeTool(
542+
context.Console,
543+
"git",
544+
"clean -xfd",
545+
context.RepoDirectory ) )
546+
{
547+
return false;
548+
}
549+
550+
return true;
551+
}
552+
525553
public static bool TryGetStatus( BuildContext context, string repoDirectory, [NotNullWhen( true )] out string[]? status )
526554
{
527555
if ( !ToolInvocationHelper.InvokeTool(

0 commit comments

Comments
 (0)