Skip to content

Commit 41f89d8

Browse files
stefanhallerjesseduffield
authored andcommitted
Add test that shows problems with git-ignoring files with special characters
For #, !, [, and ], the problem is that it doesn't ignore the file because the special characters need to be quoted. For *, the problem is that it ignores too much (it also hides the abc_def file because the * is treated as a glob).
1 parent d70a405 commit 41f89d8

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 GitignoreSpecialCharacters = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Ignore files with special characters in their names",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
},
14+
SetupRepo: func(shell *Shell) {
15+
shell.CreateFile(".gitignore", "")
16+
shell.CreateFile("#file", "")
17+
shell.CreateFile("file#abc", "")
18+
shell.CreateFile("!file", "")
19+
shell.CreateFile("file!abc", "")
20+
shell.CreateFile("abc*def", "")
21+
shell.CreateFile("abc_def", "")
22+
shell.CreateFile("file[x]", "")
23+
},
24+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
25+
excludeFile := func(fileName string) {
26+
t.Views().Files().
27+
NavigateToLine(Contains(fileName)).
28+
Press(keys.Files.IgnoreFile)
29+
30+
t.ExpectPopup().Menu().
31+
Title(Equals("Ignore or exclude file")).
32+
Select(Contains("Add to .gitignore")).
33+
Confirm()
34+
}
35+
36+
t.Views().Files().
37+
Focus().
38+
Lines(
39+
Equals("▼ /"),
40+
Equals(" ?? !file"),
41+
Equals(" ?? #file"),
42+
Equals(" ?? .gitignore"),
43+
Equals(" ?? abc*def"),
44+
Equals(" ?? abc_def"),
45+
Equals(" ?? file!abc"),
46+
Equals(" ?? file#abc"),
47+
Equals(" ?? file[x]"),
48+
)
49+
50+
excludeFile("#file")
51+
excludeFile("file#abc")
52+
excludeFile("!file")
53+
excludeFile("file!abc")
54+
excludeFile("abc*def")
55+
excludeFile("file[x]")
56+
57+
t.Views().Files().
58+
/* EXPECTED:
59+
Lines(
60+
Equals("▼ /"),
61+
Equals(" ?? .gitignore"),
62+
Equals(" ?? abc_def"),
63+
)
64+
ACTUAL:
65+
As you can see, it did ignore the 'file!abc' and 'file#abc' files
66+
correctly. Those don't need to be quoted because # and ! are only
67+
special at the beginning.
68+
69+
Most of the other files are not ignored properly because their
70+
special characters need to be escaped. For * it's the other way
71+
round: while it does hide 'abc*def', it also hides 'abc_def',
72+
which we don't want.
73+
*/
74+
Lines(
75+
Equals("▼ /"),
76+
Equals(" ?? !file"),
77+
Equals(" ?? #file"),
78+
Equals(" ?? .gitignore"),
79+
Equals(" ?? file[x]"),
80+
)
81+
82+
/* EXPECTED:
83+
t.FileSystem().FileContent(".gitignore", Equals("\\#file\nfile#abc\n\\!file\nfile!abc\nabc\\*def\nfile\\[x\\]\n"))
84+
ACTUAL: */
85+
t.FileSystem().FileContent(".gitignore", Equals("#file\nfile#abc\n!file\nfile!abc\nabc*def\nfile[x]\n"))
86+
},
87+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ var tests = []*components.IntegrationTest{
197197
file.DiscardVariousChanges,
198198
file.DiscardVariousChangesRangeSelect,
199199
file.Gitignore,
200+
file.GitignoreSpecialCharacters,
200201
file.RememberCommitMessageAfterFail,
201202
file.RenameSimilarityThresholdChange,
202203
file.RenamedFiles,

0 commit comments

Comments
 (0)