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
This commit is contained in:
Stefan Haller 2025-04-08 16:19:19 +02:00 committed by GitHub
commit a09ca592fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 1 deletions

View file

@ -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

View file

@ -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"),
)
},
})

View file

@ -195,6 +195,7 @@ var tests = []*components.IntegrationTest{
file.Gitignore,
file.RememberCommitMessageAfterFail,
file.RenameSimilarityThresholdChange,
file.RenamedFiles,
file.StageChildrenRangeSelect,
file.StageDeletedRangeSelect,
file.StageRangeSelect,