diff --git a/pkg/gui/presentation/files.go b/pkg/gui/presentation/files.go index f4e232938..d1acd02da 100644 --- a/pkg/gui/presentation/files.go +++ b/pkg/gui/presentation/files.go @@ -308,7 +308,7 @@ func fileNameAtDepth(node *filetree.Node[models.File], depth int) string { name := join(splitName[depth:]) if node.File != nil && node.File.IsRename() { - splitPrevName := split(node.File.PreviousPath) + splitPrevName := split("./" + node.File.PreviousPath) prevName := node.File.PreviousPath // if the file has just been renamed inside the same directory, we can shave off diff --git a/pkg/integration/tests/file/renamed_files.go b/pkg/integration/tests/file/renamed_files.go new file mode 100644 index 000000000..ec2ecc151 --- /dev/null +++ b/pkg/integration/tests/file/renamed_files.go @@ -0,0 +1,36 @@ +package file + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RenamedFiles = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Regression test for the display of renamed files in the file tree", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + }, + SetupRepo: func(shell *Shell) { + shell.CreateDir("dir") + shell.CreateDir("dir/nested") + shell.CreateFileAndAdd("file1", "file1 content\n") + shell.CreateFileAndAdd("dir/file2", "file2 content\n") + shell.CreateFileAndAdd("dir/nested/file3", "file3 content\n") + shell.Commit("initial commit") + shell.RunCommand([]string{"git", "mv", "file1", "dir/file1"}) + shell.RunCommand([]string{"git", "mv", "dir/file2", "dir/file2-renamed"}) + shell.RunCommand([]string{"git", "mv", "dir/nested/file3", "file3"}) + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + Lines( + Equals("▼ /"), + Equals(" ▼ dir"), + Equals(" R file1 → file1"), + Equals(" R file2 → file2-renamed"), + Equals(" R dir/nested/file3 → file3"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 4752e9bde..0d6884071 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -195,6 +195,7 @@ var tests = []*components.IntegrationTest{ file.Gitignore, file.RememberCommitMessageAfterFail, file.RenameSimilarityThresholdChange, + file.RenamedFiles, file.StageChildrenRangeSelect, file.StageDeletedRangeSelect, file.StageRangeSelect,