From 8515c74722a15c6205c7c3f26b7da6e139d28a9e Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 16 Jul 2025 13:14:08 +0200 Subject: [PATCH] Add test that demonstrates problem with showing filtered history of file with renames The test shows that selecting a commit before the rename shows an empty diff, and selecting the rename itself shows an added file rather than a rename. --- pkg/integration/components/shell.go | 4 + .../show_diffs_for_renamed_file.go | 128 ++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 3 files changed, 133 insertions(+) create mode 100644 pkg/integration/tests/filter_by_path/show_diffs_for_renamed_file.go diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index 6b711e5a8..4c833f2ab 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -235,6 +235,10 @@ func (self *Shell) DeleteFileAndAdd(fileName string) *Shell { GitAdd(fileName) } +func (self *Shell) RenameFileInGit(oldName string, newName string) *Shell { + return self.RunCommand([]string{"git", "mv", oldName, newName}) +} + // creates commits 01, 02, 03, ..., n with a new file in each // The reason for padding with zeroes is so that it's easier to do string // matches on the commit messages when there are many of them diff --git a/pkg/integration/tests/filter_by_path/show_diffs_for_renamed_file.go b/pkg/integration/tests/filter_by_path/show_diffs_for_renamed_file.go new file mode 100644 index 000000000..3d91e391c --- /dev/null +++ b/pkg/integration/tests/filter_by_path/show_diffs_for_renamed_file.go @@ -0,0 +1,128 @@ +package filter_by_path + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var ShowDiffsForRenamedFile = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Filter commits by file path for a file that was renamed, and verify that it shows the diffs correctly", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + }, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("oldFile", "a\nb\nc\n") + shell.Commit("add old file") + shell.UpdateFileAndAdd("oldFile", "x\nb\nc\n") + shell.Commit("update old file") + shell.CreateFileAndAdd("unrelatedFile", "content of unrelated file\n") + shell.Commit("add unrelated file") + shell.RenameFileInGit("oldFile", "newFile") + shell.Commit("rename file") + shell.UpdateFileAndAdd("newFile", "y\nb\nc\n") + shell.UpdateFileAndAdd("unrelatedFile", "updated content of unrelated file\n") + shell.Commit("update both files") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("update both files").IsSelected(), + Contains("rename file"), + Contains("add unrelated file"), + Contains("update old file"), + Contains("add old file"), + ). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Equals("▼ /").IsSelected(), + Equals(" M newFile"), + Equals(" M unrelatedFile"), + ). + SelectNextItem(). + Press(keys.Universal.FilteringMenu) + + t.ExpectPopup().Menu().Title(Equals("Filtering")). + Select(Contains("Filter by 'newFile'")).Confirm() + + t.Views().Commits(). + IsFocused(). + Lines( + Contains("update both files").IsSelected(), + Contains("rename file"), + Contains("update old file"), + Contains("add old file"), + ) + + t.Views().Main().ContainsLines( + Equals(" update both files"), + Equals("---"), + Equals(" newFile | 2 +-"), + Equals(" 1 file changed, 1 insertion(+), 1 deletion(-)"), + Equals(""), + Equals("diff --git a/newFile b/newFile"), + Contains("index"), + Equals("--- a/newFile"), + Equals("+++ b/newFile"), + Equals("@@ -1,3 +1,3 @@"), + Equals("-x"), + Equals("+y"), + Equals(" b"), + Equals(" c"), + ) + + t.Views().Commits().SelectNextItem() + + t.Views().Main().ContainsLines( + Equals(" rename file"), + Equals("---"), + /* EXPECTED: + Equals(" oldFile => newFile | 0"), + Equals(" 1 file changed, 0 insertions(+), 0 deletions(-)"), + Equals(""), + Equals("diff --git a/oldFile b/newFile"), + Equals("similarity index 100%"), + Equals("rename from oldFile"), + Equals("rename to newFile"), + ACTUAL: */ + Equals(" newFile | 3 +++"), + Equals(" 1 file changed, 3 insertions(+)"), + Equals(""), + Equals("diff --git a/newFile b/newFile"), + Equals("new file mode 100644"), + Contains("index"), + Equals("--- /dev/null"), + Equals("+++ b/newFile"), + Equals("@@ -0,0 +1,3 @@"), + Equals("+x"), + Equals("+b"), + Equals("+c"), + ) + + t.Views().Commits().SelectNextItem() + + /* EXPECTED: + t.Views().Main().ContainsLines( + Equals(" update old file"), + Equals("---"), + Equals(" oldFile | 2 +-"), + Equals(" 1 file changed, 1 insertion(+), 1 deletion(-)"), + Equals(""), + Equals("diff --git a/oldFile b/oldFile"), + Contains("index"), + Equals("--- a/oldFile"), + Equals("+++ b/oldFile"), + Equals("@@ -1,3 +1,3 @@"), + Equals("-a"), + Equals("+x"), + Equals(" b"), + Equals(" c"), + ) + ACTUAL: */ + t.Views().Main().IsEmpty() + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 4a8754284..1c5f5d75f 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -235,6 +235,7 @@ var tests = []*components.IntegrationTest{ filter_by_path.CliArg, filter_by_path.KeepSameCommitSelectedOnExit, filter_by_path.SelectFile, + filter_by_path.ShowDiffsForRenamedFile, filter_by_path.TypeFile, interactive_rebase.AdvancedInteractiveRebase, interactive_rebase.AmendCommitWithConflict,