Skip to content

Commit d25851a

Browse files
committed
fix: ensure consistent line endings in git fallback strategy
Fixed an issue where tests would fail on GitHub Windows runners but pass on local Windows machines due to line ending differences. The fix ensures consistent line ending handling by: 1. Normalizing CRLF to LF when reading files in the git fallback strategy 2. Disabling Git's automatic line ending conversion 3. Maintaining consistent line ending usage throughout text operations
1 parent 1fa79ba commit d25851a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

.changeset/curvy-cows-cry.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
fix: ensure consistent line endings in git fallback strategy
6+
7+
Fixed a cross-platform issue where tests would fail on GitHub Windows runners but pass on local Windows machines due to line ending differences. The fix ensures consistent line ending handling by:
8+
9+
1. Normalizing CRLF to LF when reading files in the git fallback strategy
10+
2. Disabling Git's automatic line ending conversion using core.autocrlf setting
11+
3. Maintaining consistent line ending usage throughout the text operations

src/core/diff/strategies/new-unified/edit-strategies.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ export async function applyGitFallback(hunk: Hunk, content: string[]): Promise<E
157157
await git.init()
158158
await git.addConfig("user.name", "Temp")
159159
await git.addConfig("user.email", "[email protected]")
160+
// Prevent Git from automatically converting line endings
161+
await git.addConfig("core.autocrlf", "false")
160162

161163
const filePath = path.join(tmpDir.name, "file.txt")
162164

@@ -168,6 +170,7 @@ export async function applyGitFallback(hunk: Hunk, content: string[]): Promise<E
168170
.filter((change) => change.type === "context" || change.type === "add")
169171
.map((change) => change.originalLine || change.indent + change.content)
170172

173+
// Ensure consistent line endings (LF only) in all text operations
171174
const searchText = searchLines.join("\n")
172175
const replaceText = replaceLines.join("\n")
173176
const originalText = content.join("\n")
@@ -195,7 +198,9 @@ export async function applyGitFallback(hunk: Hunk, content: string[]): Promise<E
195198
await git.raw(["cherry-pick", "--minimal", replaceCommit.commit])
196199

197200
const newText = fs.readFileSync(filePath, "utf-8")
198-
const newLines = newText.split("\n")
201+
// Normalize line endings to LF before splitting
202+
const normalizedText = newText.replace(/\r\n/g, "\n")
203+
const newLines = normalizedText.split("\n")
199204
return {
200205
confidence: 1,
201206
result: newLines,
@@ -212,6 +217,8 @@ export async function applyGitFallback(hunk: Hunk, content: string[]): Promise<E
212217
await git.init()
213218
await git.addConfig("user.name", "Temp")
214219
await git.addConfig("user.email", "[email protected]")
220+
// Prevent Git from automatically converting line endings
221+
await git.addConfig("core.autocrlf", "false")
215222

216223
fs.writeFileSync(filePath, searchText)
217224
await git.add("file.txt")
@@ -237,7 +244,9 @@ export async function applyGitFallback(hunk: Hunk, content: string[]): Promise<E
237244
await git.raw(["cherry-pick", "--minimal", replaceHash])
238245

239246
const newText = fs.readFileSync(filePath, "utf-8")
240-
const newLines = newText.split("\n")
247+
// Normalize line endings to LF before splitting
248+
const normalizedText = newText.replace(/\r\n/g, "\n")
249+
const newLines = normalizedText.split("\n")
241250
return {
242251
confidence: 1,
243252
result: newLines,

0 commit comments

Comments
 (0)