Skip to content

Commit 605ab26

Browse files
committed
Fix support for Git copy status when status.renames=copies
Fixes #4890 When Git is configured with status.renames=copies, it can produce status codes starting with "C" (copy) in addition to "R" (rename). The file loader was only checking for "R" prefixes, causing copy operations to be parsed incorrectly and breaking file staging. This fix extends the status parser to handle both "R" and "C" prefixes, ensuring proper support for Git's copy detection feature. Fixes file staging issues when using status.renames=copies configuration.
1 parent 60a7d6a commit 605ab26

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

pkg/commands/git_commands/file_loader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ func (self *FileLoader) gitStatus(opts GitStatusOptions) ([]FileStatus, error) {
201201
PreviousPath: "",
202202
}
203203

204-
if strings.HasPrefix(status.Change, "R") {
205-
// if a line starts with 'R' then the next line is the original file.
204+
if strings.HasPrefix(status.Change, "R") || strings.HasPrefix(status.Change, "C") {
205+
// if a line starts with 'R' (rename) or 'C' (copy) then the next line is the original file.
206206
status.PreviousPath = splitLines[i+1]
207207
status.StatusString = fmt.Sprintf("%s %s -> %s", status.Change, status.PreviousPath, status.Path)
208208
i++

pkg/commands/git_commands/file_loader_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,43 @@ func TestFileGetStatusFiles(t *testing.T) {
192192
},
193193
},
194194
},
195+
{
196+
testName: "Copied files",
197+
similarityThreshold: 50,
198+
runner: oscommands.NewFakeRunner(t).
199+
ExpectGitArgs([]string{"status", "--untracked-files=yes", "--porcelain", "-z", "--find-renames=50%"},
200+
"C copy1.txt\x00original.txt\x00CM copy2.txt\x00original.txt",
201+
nil,
202+
),
203+
expectedFiles: []*models.File{
204+
{
205+
Path: "copy1.txt",
206+
PreviousPath: "original.txt",
207+
HasStagedChanges: true,
208+
HasUnstagedChanges: false,
209+
Tracked: true,
210+
Added: false,
211+
Deleted: false,
212+
HasMergeConflicts: false,
213+
HasInlineMergeConflicts: false,
214+
DisplayString: "C original.txt -> copy1.txt",
215+
ShortStatus: "C ",
216+
},
217+
{
218+
Path: "copy2.txt",
219+
PreviousPath: "original.txt",
220+
HasStagedChanges: true,
221+
HasUnstagedChanges: true,
222+
Tracked: true,
223+
Added: false,
224+
Deleted: false,
225+
HasMergeConflicts: false,
226+
HasInlineMergeConflicts: false,
227+
DisplayString: "CM original.txt -> copy2.txt",
228+
ShortStatus: "CM",
229+
},
230+
},
231+
},
195232
}
196233

197234
for _, s := range scenarios {

0 commit comments

Comments
 (0)