Skip to content

Commit a09ca59

Browse files
authored
Fix display of renamed files in tree view (#4452)
- **PR Description** Fix a regression (introduced with the root item PR, #4346) that caused renamed files to be displayed with their full path in tree view. While fixing this I noticed that the display of moved files is a bit confusing; for example, you can't distinguish a file being moved from the root level into a directory from one that was renamed inside the directory; see commit message of the first commit for more. I'm not doing anything about this right now, just fix the regression for now. Labeled as "ignore-for-release" because it fixes a regression in code that wasn't released yet. - **Please check if the PR fulfills these requirements** * [x] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [x] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc
2 parents 6fb7942 + b09251e commit a09ca59

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

pkg/gui/presentation/files.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func fileNameAtDepth(node *filetree.Node[models.File], depth int) string {
308308
name := join(splitName[depth:])
309309

310310
if node.File != nil && node.File.IsRename() {
311-
splitPrevName := split(node.File.PreviousPath)
311+
splitPrevName := split("./" + node.File.PreviousPath)
312312

313313
prevName := node.File.PreviousPath
314314
// if the file has just been renamed inside the same directory, we can shave off
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package file
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var RenamedFiles = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Regression test for the display of renamed files in the file tree",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
},
14+
SetupRepo: func(shell *Shell) {
15+
shell.CreateDir("dir")
16+
shell.CreateDir("dir/nested")
17+
shell.CreateFileAndAdd("file1", "file1 content\n")
18+
shell.CreateFileAndAdd("dir/file2", "file2 content\n")
19+
shell.CreateFileAndAdd("dir/nested/file3", "file3 content\n")
20+
shell.Commit("initial commit")
21+
shell.RunCommand([]string{"git", "mv", "file1", "dir/file1"})
22+
shell.RunCommand([]string{"git", "mv", "dir/file2", "dir/file2-renamed"})
23+
shell.RunCommand([]string{"git", "mv", "dir/nested/file3", "file3"})
24+
},
25+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
26+
t.Views().Files().
27+
IsFocused().
28+
Lines(
29+
Equals("▼ /"),
30+
Equals(" ▼ dir"),
31+
Equals(" R file1 → file1"),
32+
Equals(" R file2 → file2-renamed"),
33+
Equals(" R dir/nested/file3 → file3"),
34+
)
35+
},
36+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ var tests = []*components.IntegrationTest{
195195
file.Gitignore,
196196
file.RememberCommitMessageAfterFail,
197197
file.RenameSimilarityThresholdChange,
198+
file.RenamedFiles,
198199
file.StageChildrenRangeSelect,
199200
file.StageDeletedRangeSelect,
200201
file.StageRangeSelect,

0 commit comments

Comments
 (0)