Skip to content

Commit 788855a

Browse files
Bump: detect file-actually-changed in AutoUpdatedVersions.props
The dependency loop's per-edit hasChanges flag was stale when cross-family edits cancelled out (e.g. Metalama.Compiler toggled 2026.0->2026.1->2026.0 on Vsx 2026.1 PrePublish), causing an empty <<DEPENDENCIES_UPDATED>> commit that failed with "nothing to commit". WriteIfDifferent is now called unconditionally and its return value drives both the dry-run log and the commit gate. WriteIfDifferent gains an optional dry parameter to support the dry-mode path. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 84e832c commit 788855a

2 files changed

Lines changed: 47 additions & 38 deletions

File tree

src/PostSharp.Engineering.BuildTools/Build/Files/AutoUpdatedVersionsFile.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,11 @@ public static bool TryWrite(
288288
thisMainVersionElement.Value = versionComponents.MainVersion;
289289
}
290290

291-
// Write changes (always try to write to handle formatting and condition changes).
292-
if ( !dry )
293-
{
294-
hasChanges = TextFileHelper.WriteIfDifferent( thisAutoUpdatedVersionsFilePath, thisAutoUpdatedVersionsDocument, context );
295-
}
296-
else if ( hasChanges )
291+
// Always compare against the file on disk to handle formatting and condition changes,
292+
// and to reset the stale per-edit hasChanges flag when in-memory edits cancel out.
293+
hasChanges = TextFileHelper.WriteIfDifferent( thisAutoUpdatedVersionsFilePath, thisAutoUpdatedVersionsDocument, context, dry );
294+
295+
if ( dry && hasChanges )
297296
{
298297
context.Console.WriteMessage( $"New content for '{thisAutoUpdatedVersionsFilePath}':" );
299298
context.Console.WriteMessage( thisAutoUpdatedVersionsDocument.ToNiceString() );
@@ -308,13 +307,15 @@ public static bool TryWrite(
308307
public static bool TryWriteAndCommit( BuildContext context, bool dry )
309308
{
310309
// Go through all dependencies and update their fixed version in AutoUpdatedVersions.props file.
311-
if ( !TryWrite( context, dry, out var dependenciesUpdated, out _, out _, out _ ) )
310+
// Gate on hasChanges (whether the file was actually written), not on the per-dependency edit flag:
311+
// cross-family edits can cancel out, leaving the file unchanged on disk.
312+
if ( !TryWrite( context, dry, out _, out var hasChanges, out _, out _ ) )
312313
{
313314
return false;
314315
}
315316

316-
// Commit and push if dependencies versions were updated in previous step.
317-
if ( dependenciesUpdated )
317+
// Commit and push if the AutoUpdatedVersions.props file was changed.
318+
if ( hasChanges )
318319
{
319320
if ( dry )
320321
{
Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
1-
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2-
3-
using PostSharp.Engineering.BuildTools.Build;
4-
using System.IO;
5-
using System.Xml.Linq;
6-
7-
namespace PostSharp.Engineering.BuildTools.Utilities;
8-
9-
internal static class TextFileHelper
10-
{
11-
public static bool WriteIfDifferent( string path, XDocument content, BuildContext context ) => WriteIfDifferent( path, content.ToNiceString(), context );
12-
13-
public static bool WriteIfDifferent( string path, string content, BuildContext context )
14-
{
15-
if ( File.Exists( path ) && content == File.ReadAllText( path ) )
16-
{
17-
context.Console.WriteMessage( $"The file '{path}' is up to date." );
18-
19-
return false;
20-
}
21-
else
22-
{
23-
context.Console.WriteMessage( $"Writing '{path}'." );
24-
Directory.CreateDirectory( Path.GetDirectoryName( path )! );
25-
File.WriteAllText( path, content );
26-
27-
return true;
28-
}
29-
}
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
using PostSharp.Engineering.BuildTools.Build;
4+
using System.IO;
5+
using System.Xml.Linq;
6+
7+
namespace PostSharp.Engineering.BuildTools.Utilities;
8+
9+
internal static class TextFileHelper
10+
{
11+
public static bool WriteIfDifferent( string path, XDocument content, BuildContext context, bool dry = false )
12+
=> WriteIfDifferent( path, content.ToNiceString(), context, dry );
13+
14+
public static bool WriteIfDifferent( string path, string content, BuildContext context, bool dry = false )
15+
{
16+
if ( File.Exists( path ) && content == File.ReadAllText( path ) )
17+
{
18+
context.Console.WriteMessage( $"The file '{path}' is up to date." );
19+
20+
return false;
21+
}
22+
else
23+
{
24+
if ( dry )
25+
{
26+
context.Console.WriteMessage( $"Dry run: would write '{path}'." );
27+
}
28+
else
29+
{
30+
context.Console.WriteMessage( $"Writing '{path}'." );
31+
Directory.CreateDirectory( Path.GetDirectoryName( path )! );
32+
File.WriteAllText( path, content );
33+
}
34+
35+
return true;
36+
}
37+
}
3038
}

0 commit comments

Comments
 (0)