Skip to content

Commit 6b5b493

Browse files
authored
Fix support for Git copy status when status.renames=copies (#4892)
Fixes: #4890 - Fix file status parsing to handle Git copy operations when `status.renames=copies` is configured - Extend status parser to recognize both "R" (rename) and "C" (copy) prefixes - Add comprehensive test coverage for copy status codes The same issue from #4890 now is fixed <img width="602" height="453" alt="image" src="https://github.com/user-attachments/assets/c5b0dc4b-8f77-4867-b601-65faa91d6607" />
2 parents 1fd771f + e6f3313 commit 6b5b493

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)