Skip to content

Commit 0399e7f

Browse files
Bump: compare line-endings-insensitively in WriteIfDifferent
On Windows with autocrlf=true, files come out of git with CRLF while ToNiceString() generates LF. The byte-level inequality caused WriteIfDifferent to report "changed" for files git considers identical, producing a no-op <<DEPENDENCIES_UPDATED>> commit that failed with "nothing to commit" (Metalama.Vsx 2026.1 PrePublish 324426). Normalize line endings before comparison to match git's view of file equality. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 9f5d9fb commit 0399e7f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
22

33
using PostSharp.Engineering.BuildTools.Build;
4+
using System;
45
using System.IO;
56
using System.Xml.Linq;
67

@@ -13,7 +14,12 @@ public static bool WriteIfDifferent( string path, XDocument content, BuildContex
1314

1415
public static bool WriteIfDifferent( string path, string content, BuildContext context, bool dry = false )
1516
{
16-
if ( File.Exists( path ) && content == File.ReadAllText( path ) )
17+
// Compare line-ending-insensitive: on Windows with autocrlf, the on-disk file can have CRLF while
18+
// generated content has LF, making the strings differ even though git considers them identical.
19+
// Without this, we report "changed" but the subsequent `git add`/`git commit` becomes a no-op.
20+
static string NormalizeLineEndings( string s ) => s.Replace( "\r\n", "\n", StringComparison.Ordinal );
21+
22+
if ( File.Exists( path ) && NormalizeLineEndings( content ) == NormalizeLineEndings( File.ReadAllText( path ) ) )
1723
{
1824
context.Console.WriteMessage( $"The file '{path}' is up to date." );
1925

0 commit comments

Comments
 (0)