Skip to content

Commit 654dad4

Browse files
Fixes parsing of git --name-status output by splitting lines on tabs instead of spaces
1 parent e0752f3 commit 654dad4

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

internal/git/operations.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ func parseGitNameStatus(line string) parseGitStatusLine {
3535
return parseGitStatusLine{}
3636
}
3737

38-
parts := strings.Fields(line)
38+
// Git uses tabs to separate fields in --name-status output
39+
parts := strings.Split(line, "\t")
3940
if len(parts) < 2 {
4041
return parseGitStatusLine{}
4142
}
@@ -44,11 +45,11 @@ func parseGitNameStatus(line string) parseGitStatusLine {
4445

4546
// Handle rename/copy status codes (e.g., "R100", "C75")
4647
if len(status) > 1 && (status[0] == 'R' || status[0] == 'C') {
47-
// For rename/copy, we expect: "R100 oldname newname" or "C75 oldname newname"
48+
// For rename/copy, we expect: "R100\toldname\tnewname" or "C75\toldname\tnewname"
4849
if len(parts) >= 3 {
4950
// For renames/copies, both old and new filenames need to be checked
5051
oldFile := parts[1]
51-
newFile := strings.Join(parts[2:], " ") // Handle spaces in new filename
52+
newFile := parts[2]
5253
return parseGitStatusLine{
5354
status: status,
5455
filenames: []string{oldFile, newFile},
@@ -57,7 +58,7 @@ func parseGitNameStatus(line string) parseGitStatusLine {
5758
}
5859

5960
// Handle regular status codes (M, A, D, etc.)
60-
filename := strings.Join(parts[1:], " ") // Handle filenames with spaces
61+
filename := parts[1]
6162
return parseGitStatusLine{
6263
status: status,
6364
filenames: []string{filename},

0 commit comments

Comments
 (0)