Skip to content

Commit cceff63

Browse files
Merge pull request #2339 from jesseduffield/integration-tests-5
2 parents 31bdd27 + 5c42e1a commit cceff63

File tree

209 files changed

+344
-559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+344
-559
lines changed

pkg/gui/confirmation_panel.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,13 @@ func (gui *Gui) clearConfirmationViewKeyBindings() {
290290

291291
func (gui *Gui) refreshSuggestions() {
292292
gui.suggestionsAsyncHandler.Do(func() func() {
293-
suggestions := gui.findSuggestions(gui.c.GetPromptInput())
294-
return func() { gui.setSuggestions(suggestions) }
293+
findSuggestionsFn := gui.findSuggestions
294+
if findSuggestionsFn != nil {
295+
suggestions := gui.findSuggestions(gui.c.GetPromptInput())
296+
return func() { gui.setSuggestions(suggestions) }
297+
} else {
298+
return func() {}
299+
}
295300
})
296301
}
297302

pkg/integration/components/shell.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,32 @@ func (self *Shell) SetConfig(key string, value string) *Shell {
170170
self.RunCommand(fmt.Sprintf(`git config --local "%s" %s`, key, value))
171171
return self
172172
}
173+
174+
// creates a clone of the repo in a sibling directory and adds the clone
175+
// as a remote, then fetches it.
176+
func (self *Shell) CloneIntoRemote(name string) *Shell {
177+
self.RunCommand(fmt.Sprintf("git clone --bare . ../%s", name))
178+
self.RunCommand(fmt.Sprintf("git remote add %s ../%s", name, name))
179+
self.RunCommand(fmt.Sprintf("git fetch %s", name))
180+
181+
return self
182+
}
183+
184+
// e.g. branch: 'master', upstream: 'origin/master'
185+
func (self *Shell) SetBranchUpstream(branch string, upstream string) *Shell {
186+
self.RunCommand(fmt.Sprintf("git branch --set-upstream-to=%s %s", upstream, branch))
187+
188+
return self
189+
}
190+
191+
func (self *Shell) RemoveRemoteBranch(remoteName string, branch string) *Shell {
192+
self.RunCommand(fmt.Sprintf("git -C ../%s branch -d %s", remoteName, branch))
193+
194+
return self
195+
}
196+
197+
func (self *Shell) HardReset(ref string) *Shell {
198+
self.RunCommand(fmt.Sprintf("git reset --hard %s", ref))
199+
200+
return self
201+
}

pkg/integration/tests/file/exclude_gitignore.go

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 GitIgnore = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Verify that we can't ignore the .gitignore file, then ignore/exclude other files",
10+
ExtraCmdArgs: "",
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
},
14+
SetupRepo: func(shell *Shell) {
15+
shell.CreateFile(".gitignore", "")
16+
shell.CreateFile("toExclude", "")
17+
shell.CreateFile("toIgnore", "")
18+
},
19+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
20+
t.Views().Files().
21+
IsFocused().
22+
Lines(
23+
Contains(`?? .gitignore`).IsSelected(),
24+
Contains(`?? toExclude`),
25+
Contains(`?? toIgnore`),
26+
).
27+
Press(keys.Files.IgnoreFile).
28+
// ensure we can't exclude the .gitignore file
29+
Tap(func() {
30+
t.ExpectPopup().Menu().Title(Equals("ignore or exclude file")).Select(Contains("add to .git/info/exclude")).Confirm()
31+
32+
t.ExpectPopup().Alert().Title(Equals("Error")).Content(Equals("Cannot exclude .gitignore")).Confirm()
33+
}).
34+
Press(keys.Files.IgnoreFile).
35+
// ensure we can't ignore the .gitignore file
36+
Tap(func() {
37+
t.ExpectPopup().Menu().Title(Equals("ignore or exclude file")).Select(Contains("add to .gitignore")).Confirm()
38+
39+
t.ExpectPopup().Alert().Title(Equals("Error")).Content(Equals("Cannot ignore .gitignore")).Confirm()
40+
41+
t.FileSystem().FileContent(".gitignore", Equals(""))
42+
t.FileSystem().FileContent(".git/info/exclude", DoesNotContain(".gitignore"))
43+
}).
44+
SelectNextItem().
45+
Press(keys.Files.IgnoreFile).
46+
// exclude a file
47+
Tap(func() {
48+
t.ExpectPopup().Menu().Title(Equals("ignore or exclude file")).Select(Contains("add to .git/info/exclude")).Confirm()
49+
50+
t.FileSystem().FileContent(".gitignore", Equals(""))
51+
t.FileSystem().FileContent(".git/info/exclude", Contains("toExclude"))
52+
}).
53+
SelectNextItem().
54+
Press(keys.Files.IgnoreFile).
55+
// ignore a file
56+
Tap(func() {
57+
t.ExpectPopup().Menu().Title(Equals("ignore or exclude file")).Select(Contains("add to .gitignore")).Confirm()
58+
59+
t.FileSystem().FileContent(".gitignore", Equals("toIgnore\n"))
60+
t.FileSystem().FileContent(".git/info/exclude", Contains("toExclude"))
61+
})
62+
},
63+
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 CliArg = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Filter commits by file path, using CLI arg",
10+
ExtraCmdArgs: "-f filterFile",
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
},
14+
SetupRepo: func(shell *Shell) {
15+
commonSetup(shell)
16+
},
17+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
18+
postFilterTest(t)
19+
},
20+
})
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 SelectFile = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Filter commits by file path, by finding file in UI and filtering on it",
10+
ExtraCmdArgs: "",
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
},
14+
SetupRepo: func(shell *Shell) {
15+
commonSetup(shell)
16+
},
17+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
18+
t.Views().Commits().
19+
Focus().
20+
Lines(
21+
Contains(`only filterFile`).IsSelected(),
22+
Contains(`only otherFile`),
23+
Contains(`both files`),
24+
).
25+
PressEnter()
26+
27+
// when you click into the commit itself, you see all files from that commit
28+
t.Views().CommitFiles().
29+
IsFocused().
30+
Lines(
31+
Contains(`filterFile`).IsSelected(),
32+
).
33+
Press(keys.Universal.FilteringMenu)
34+
35+
t.ExpectPopup().Menu().Title(Equals("Filtering")).Select(Contains("filter by 'filterFile'")).Confirm()
36+
37+
postFilterTest(t)
38+
},
39+
})
40+
41+
func commonSetup(shell *Shell) {
42+
shell.CreateFileAndAdd("filterFile", "original filterFile content")
43+
shell.CreateFileAndAdd("otherFile", "original otherFile content")
44+
shell.Commit("both files")
45+
46+
shell.UpdateFileAndAdd("otherFile", "new otherFile content")
47+
shell.Commit("only otherFile")
48+
49+
shell.UpdateFileAndAdd("filterFile", "new filterFile content")
50+
shell.Commit("only filterFile")
51+
}
52+
53+
func postFilterTest(t *TestDriver) {
54+
t.Views().Information().Content(Contains("filtering by 'filterFile'"))
55+
56+
t.Views().Commits().
57+
IsFocused().
58+
Lines(
59+
Contains(`only filterFile`).IsSelected(),
60+
Contains(`both files`),
61+
).
62+
SelectNextItem().
63+
PressEnter()
64+
65+
// we only show the filtered file's changes in the main view
66+
t.Views().Main().
67+
Content(Contains("filterFile").DoesNotContain("otherFile"))
68+
69+
// when you click into the commit itself, you see all files from that commit
70+
t.Views().CommitFiles().
71+
IsFocused().
72+
Lines(
73+
Contains(`filterFile`),
74+
Contains(`otherFile`),
75+
)
76+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 TypeFile = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Filter commits by file path, by finding file in UI and filtering on it",
10+
ExtraCmdArgs: "",
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
},
14+
SetupRepo: func(shell *Shell) {
15+
commonSetup(shell)
16+
},
17+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
18+
t.Views().Files().
19+
IsFocused().
20+
Press(keys.Universal.FilteringMenu)
21+
22+
t.ExpectPopup().Menu().
23+
Title(Equals("Filtering")).
24+
Select(Contains("enter path to filter by")).
25+
Confirm()
26+
27+
t.ExpectPopup().Prompt().
28+
Title(Equals("Enter path:")).
29+
Type("filterF").
30+
SuggestionLines(Equals("filterFile")).
31+
ConfirmFirstSuggestion()
32+
33+
postFilterTest(t)
34+
},
35+
})
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package sync
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var FetchPrune = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Fetch from the remote with the 'prune' option set in the git config",
10+
ExtraCmdArgs: "",
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
config.UserConfig.Git.AutoFetch = false
14+
},
15+
SetupRepo: func(shell *Shell) {
16+
// This option makes it so that git checks for deleted branches in the remote
17+
// upon fetching.
18+
shell.SetConfig("fetch.prune", "true")
19+
20+
shell.EmptyCommit("my commit message")
21+
22+
shell.NewBranch("branch_to_remove")
23+
shell.Checkout("master")
24+
shell.CloneIntoRemote("origin")
25+
shell.SetBranchUpstream("master", "origin/master")
26+
shell.SetBranchUpstream("branch_to_remove", "origin/branch_to_remove")
27+
28+
// # unbenownst to our test repo we're removing the branch on the remote, so upon
29+
// # fetching with prune: true we expect git to realise the remote branch is gone
30+
shell.RemoveRemoteBranch("origin", "branch_to_remove")
31+
},
32+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
33+
t.Views().Branches().
34+
Lines(
35+
Contains("master"),
36+
Contains("branch_to_remove").DoesNotContain("upstream gone"),
37+
)
38+
39+
t.Views().Files().
40+
IsFocused().
41+
Press(keys.Files.Fetch)
42+
43+
t.Views().Branches().
44+
Lines(
45+
Contains("master"),
46+
Contains("branch_to_remove").Contains("upstream gone"),
47+
)
48+
},
49+
})
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package sync
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var RenameBranchAndPull = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Rename a branch to no longer match its upstream, then pull from the upstream",
10+
ExtraCmdArgs: "",
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
config.UserConfig.Git.AutoFetch = false
14+
},
15+
SetupRepo: func(shell *Shell) {
16+
shell.EmptyCommit("one")
17+
shell.EmptyCommit("two")
18+
19+
shell.CloneIntoRemote("origin")
20+
shell.SetBranchUpstream("master", "origin/master")
21+
22+
// remove the 'two' commit so that we have something to pull from the remote
23+
shell.HardReset("HEAD^")
24+
},
25+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
26+
t.Views().Commits().
27+
Lines(
28+
Contains("one"),
29+
)
30+
31+
t.Views().Branches().
32+
Focus().
33+
Lines(
34+
Contains("master"),
35+
).
36+
Press(keys.Branches.RenameBranch).
37+
Tap(func() {
38+
t.ExpectPopup().Confirmation().
39+
Title(Equals("rename branch")).
40+
Content(Equals("This branch is tracking a remote. This action will only rename the local branch name, not the name of the remote branch. Continue?")).
41+
Confirm()
42+
43+
t.ExpectPopup().Prompt().
44+
Title(Contains("Enter new branch name")).
45+
InitialText(Equals("master")).
46+
Type("-local").
47+
Confirm()
48+
}).
49+
Press(keys.Universal.PullFiles)
50+
51+
t.Views().Commits().
52+
Lines(
53+
Contains("two"),
54+
Contains("one"),
55+
)
56+
},
57+
})

0 commit comments

Comments
 (0)