Skip to content

Commit e28d34e

Browse files
committed
fix(commands): treat CRLF line endings as checkout artifacts, not drift
A Windows clone with core.autocrlf=true (the Git for Windows default) materializes the vendored charts/talm/ with CRLF while the embedded library is LF-only. The byte-level comparison then reported drift on every command for a content-identical tree, and strictCharts: true hard-failed it. Normalize CRLF to LF at the vendored-read boundary. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 31b6fdb commit e28d34e

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

‎pkg/commands/chart_drift.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,17 @@ func vendoredTalmFiles(rootDir string) (map[string]string, bool, error) {
6868
return errors.Wrapf(err, "reading vendored talm file %q", filePath)
6969
}
7070

71+
// Normalize CRLF to LF before comparing: a Windows clone with
72+
// core.autocrlf=true (the Git for Windows default) materializes the
73+
// vendored tree with CRLF while the embedded library is LF-only.
74+
// Line endings are checkout artifacts, not chart content — without
75+
// this, every command on such a clone reports false drift, and
76+
// strictCharts: true hard-fails a byte-identical-modulo-EOL tree.
77+
content := strings.ReplaceAll(string(data), "\r\n", "\n")
78+
7179
// root.FS() keys are already "/"-separated and relative to base, so
7280
// they match the embedded TalmLibraryFiles output on every platform.
73-
filesMap[filePath] = generated.NormalizeChartMeta(path.Base(filePath), string(data))
81+
filesMap[filePath] = generated.NormalizeChartMeta(path.Base(filePath), content)
7482

7583
return nil
7684
})

‎pkg/commands/chart_drift_test.go‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package commands
1616

1717
import (
18+
"io/fs"
1819
"os"
1920
"path/filepath"
2021
"strings"
@@ -120,6 +121,52 @@ func TestCheckChartDrift_ContentChange_Drift(t *testing.T) {
120121
}
121122
}
122123

124+
// TestCheckChartDrift_CRLFVendoredCopy_NoDrift pins EOL-insensitivity: a
125+
// project cloned on Windows with core.autocrlf=true (the Git for Windows
126+
// default) materializes the vendored charts/talm/ with CRLF endings while
127+
// the embedded library is LF. Line endings are checkout artifacts, not
128+
// chart content — flagging them would WARN on every command for a
129+
// byte-identical-modulo-EOL tree, and hard-fail teams that set
130+
// strictCharts: true precisely for CI enforcement.
131+
func TestCheckChartDrift_CRLFVendoredCopy_NoDrift(t *testing.T) {
132+
root := writeVendoredTalmLibrary(t, "0.30.0")
133+
134+
base := filepath.Join(root, "charts", "talm")
135+
walkErr := filepath.WalkDir(base, func(p string, d fs.DirEntry, err error) error {
136+
if err != nil {
137+
t.Fatalf("walking vendored tree at %q: %v", p, err)
138+
}
139+
140+
if d.IsDir() {
141+
return nil
142+
}
143+
144+
data, readErr := os.ReadFile(p)
145+
if readErr != nil {
146+
t.Fatalf("read %q: %v", p, readErr)
147+
}
148+
149+
crlf := strings.ReplaceAll(string(data), "\n", "\r\n")
150+
if writeErr := os.WriteFile(p, []byte(crlf), 0o644); writeErr != nil {
151+
t.Fatalf("write %q: %v", p, writeErr)
152+
}
153+
154+
return nil
155+
})
156+
if walkErr != nil {
157+
t.Fatalf("converting vendored tree to CRLF: %v", walkErr)
158+
}
159+
160+
drift, msg, err := CheckChartDrift(root, "0.30.0")
161+
if err != nil {
162+
t.Fatalf("CheckChartDrift: %v", err)
163+
}
164+
165+
if drift {
166+
t.Errorf("CRLF line endings were misreported as drift: %s", msg)
167+
}
168+
}
169+
123170
// TestCheckChartDrift_VendoredTalmIsFile_ErrorsGracefully pins that a
124171
// charts/talm that exists as a file (not a directory) is surfaced as an
125172
// error rather than a panic or a spurious drift result. Callers

0 commit comments

Comments
 (0)