From 2c9187acb9f7df0988d40db75d0c52c6c1238d26 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 12 Aug 2026 10:38:12 +0200 Subject: [PATCH] Pass the previous path when diffing a filtered directory in the files panel Restricting the diff to the files that a filter leaves visible drops the delete-side entry of a staged rename, so git shows the file as an addition instead. Its commit files counterpart already passes both paths; this brings the files panel in line. --- pkg/gui/controllers/files_controller.go | 4 +++- .../tests/file/directory_diff_with_renamed_files.go | 11 ----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index be3348897..5d8cf1c41 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -650,7 +650,9 @@ func (self *FilesController) pathOverridesForDiff(node *filetree.FileNode) []str if !node.IsFile() && self.context().IsFiltering() { var paths []string _ = node.ForEachFile(func(file *models.File) error { - paths = append(paths, file.Path) + // For a rename we need to pass both paths so that git detects it as + // a rename rather than an unrelated delete and add. + paths = append(paths, file.Names()...) return nil }) return paths diff --git a/pkg/integration/tests/file/directory_diff_with_renamed_files.go b/pkg/integration/tests/file/directory_diff_with_renamed_files.go index bd4e667c2..101f56950 100644 --- a/pkg/integration/tests/file/directory_diff_with_renamed_files.go +++ b/pkg/integration/tests/file/directory_diff_with_renamed_files.go @@ -98,22 +98,11 @@ var DirectoryDiffWithRenamedFiles = NewIntegrationTest(NewIntegrationTestArgs{ ) t.Views().Main(). - /* EXPECTED: ContainsLines( Equals("diff --git a/file1 b/dir/file1"), Equals("similarity index 100%"), Equals("rename from file1"), Equals("rename to dir/file1"), ) - ACTUAL: */ - ContainsLines( - Equals("diff --git a/dir/file1 b/dir/file1"), - Equals("new file mode 100644"), - Contains("index"), - Equals("--- /dev/null"), - Equals("+++ b/dir/file1"), - Equals("@@ -0,0 +1 @@"), - Equals("+file1 content"), - ) }, })