Skip to content

Commit 8515c74

Browse files
committed
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.
1 parent b8dfba8 commit 8515c74

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

pkg/integration/components/shell.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ func (self *Shell) DeleteFileAndAdd(fileName string) *Shell {
235235
GitAdd(fileName)
236236
}
237237

238+
func (self *Shell) RenameFileInGit(oldName string, newName string) *Shell {
239+
return self.RunCommand([]string{"git", "mv", oldName, newName})
240+
}
241+
238242
// creates commits 01, 02, 03, ..., n with a new file in each
239243
// The reason for padding with zeroes is so that it's easier to do string
240244
// matches on the commit messages when there are many of them
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package filter_by_path
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var ShowDiffsForRenamedFile = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Filter commits by file path for a file that was renamed, and verify that it shows the diffs correctly",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
},
14+
SetupRepo: func(shell *Shell) {
15+
shell.CreateFileAndAdd("oldFile", "a\nb\nc\n")
16+
shell.Commit("add old file")
17+
shell.UpdateFileAndAdd("oldFile", "x\nb\nc\n")
18+
shell.Commit("update old file")
19+
shell.CreateFileAndAdd("unrelatedFile", "content of unrelated file\n")
20+
shell.Commit("add unrelated file")
21+
shell.RenameFileInGit("oldFile", "newFile")
22+
shell.Commit("rename file")
23+
shell.UpdateFileAndAdd("newFile", "y\nb\nc\n")
24+
shell.UpdateFileAndAdd("unrelatedFile", "updated content of unrelated file\n")
25+
shell.Commit("update both files")
26+
},
27+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
28+
t.Views().Commits().
29+
Focus().
30+
Lines(
31+
Contains("update both files").IsSelected(),
32+
Contains("rename file"),
33+
Contains("add unrelated file"),
34+
Contains("update old file"),
35+
Contains("add old file"),
36+
).
37+
PressEnter()
38+
39+
t.Views().CommitFiles().
40+
IsFocused().
41+
Lines(
42+
Equals("▼ /").IsSelected(),
43+
Equals(" M newFile"),
44+
Equals(" M unrelatedFile"),
45+
).
46+
SelectNextItem().
47+
Press(keys.Universal.FilteringMenu)
48+
49+
t.ExpectPopup().Menu().Title(Equals("Filtering")).
50+
Select(Contains("Filter by 'newFile'")).Confirm()
51+
52+
t.Views().Commits().
53+
IsFocused().
54+
Lines(
55+
Contains("update both files").IsSelected(),
56+
Contains("rename file"),
57+
Contains("update old file"),
58+
Contains("add old file"),
59+
)
60+
61+
t.Views().Main().ContainsLines(
62+
Equals(" update both files"),
63+
Equals("---"),
64+
Equals(" newFile | 2 +-"),
65+
Equals(" 1 file changed, 1 insertion(+), 1 deletion(-)"),
66+
Equals(""),
67+
Equals("diff --git a/newFile b/newFile"),
68+
Contains("index"),
69+
Equals("--- a/newFile"),
70+
Equals("+++ b/newFile"),
71+
Equals("@@ -1,3 +1,3 @@"),
72+
Equals("-x"),
73+
Equals("+y"),
74+
Equals(" b"),
75+
Equals(" c"),
76+
)
77+
78+
t.Views().Commits().SelectNextItem()
79+
80+
t.Views().Main().ContainsLines(
81+
Equals(" rename file"),
82+
Equals("---"),
83+
/* EXPECTED:
84+
Equals(" oldFile => newFile | 0"),
85+
Equals(" 1 file changed, 0 insertions(+), 0 deletions(-)"),
86+
Equals(""),
87+
Equals("diff --git a/oldFile b/newFile"),
88+
Equals("similarity index 100%"),
89+
Equals("rename from oldFile"),
90+
Equals("rename to newFile"),
91+
ACTUAL: */
92+
Equals(" newFile | 3 +++"),
93+
Equals(" 1 file changed, 3 insertions(+)"),
94+
Equals(""),
95+
Equals("diff --git a/newFile b/newFile"),
96+
Equals("new file mode 100644"),
97+
Contains("index"),
98+
Equals("--- /dev/null"),
99+
Equals("+++ b/newFile"),
100+
Equals("@@ -0,0 +1,3 @@"),
101+
Equals("+x"),
102+
Equals("+b"),
103+
Equals("+c"),
104+
)
105+
106+
t.Views().Commits().SelectNextItem()
107+
108+
/* EXPECTED:
109+
t.Views().Main().ContainsLines(
110+
Equals(" update old file"),
111+
Equals("---"),
112+
Equals(" oldFile | 2 +-"),
113+
Equals(" 1 file changed, 1 insertion(+), 1 deletion(-)"),
114+
Equals(""),
115+
Equals("diff --git a/oldFile b/oldFile"),
116+
Contains("index"),
117+
Equals("--- a/oldFile"),
118+
Equals("+++ b/oldFile"),
119+
Equals("@@ -1,3 +1,3 @@"),
120+
Equals("-a"),
121+
Equals("+x"),
122+
Equals(" b"),
123+
Equals(" c"),
124+
)
125+
ACTUAL: */
126+
t.Views().Main().IsEmpty()
127+
},
128+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ var tests = []*components.IntegrationTest{
235235
filter_by_path.CliArg,
236236
filter_by_path.KeepSameCommitSelectedOnExit,
237237
filter_by_path.SelectFile,
238+
filter_by_path.ShowDiffsForRenamedFile,
238239
filter_by_path.TypeFile,
239240
interactive_rebase.AdvancedInteractiveRebase,
240241
interactive_rebase.AmendCommitWithConflict,

0 commit comments

Comments
 (0)