diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-24 16:36:11 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-30 18:35:23 +1000 |
commit | a313b1670496e1e73745b5a6a922432fb81ce0e6 (patch) | |
tree | 800cf236aec51172d8cb3badb61f5385b5f3bcab /pkg/integration/tests/worktree | |
parent | b93b9dae888683bb36da141981842a85e8010ff2 (diff) |
Add more worktree tests
Diffstat (limited to 'pkg/integration/tests/worktree')
-rw-r--r-- | pkg/integration/tests/worktree/add_from_branch_detached.go | 46 | ||||
-rw-r--r-- | pkg/integration/tests/worktree/add_from_commit.go | 56 | ||||
-rw-r--r-- | pkg/integration/tests/worktree/bisect.go | 88 | ||||
-rw-r--r-- | pkg/integration/tests/worktree/custom_command.go | 40 | ||||
-rw-r--r-- | pkg/integration/tests/worktree/rebase.go | 33 |
5 files changed, 256 insertions, 7 deletions
diff --git a/pkg/integration/tests/worktree/add_from_branch_detached.go b/pkg/integration/tests/worktree/add_from_branch_detached.go new file mode 100644 index 000000000..584de344e --- /dev/null +++ b/pkg/integration/tests/worktree/add_from_branch_detached.go @@ -0,0 +1,46 @@ +package worktree + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var AddFromBranchDetached = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Add a detached worktree via the branches view", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.NewBranch("mybranch") + shell.CreateFileAndAdd("README.md", "hello world") + shell.Commit("initial commit") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Lines( + Contains("mybranch"), + ). + Press(keys.Worktrees.ViewWorktreeOptions). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Worktree")). + Select(Contains(`Create worktree from mybranch (detached)`)). + Confirm() + + t.ExpectPopup().Prompt(). + Title(Equals("New worktree path")). + Type("../linked-worktree"). + Confirm() + }). + // confirm we're still focused on the branches view + IsFocused(). + Lines( + Contains("(no branch)").IsSelected(), + Contains("mybranch (worktree)"), + ) + + t.Views().Status(). + Content(Contains("repo(linked-worktree)")) + }, +}) diff --git a/pkg/integration/tests/worktree/add_from_commit.go b/pkg/integration/tests/worktree/add_from_commit.go new file mode 100644 index 000000000..a171f74a3 --- /dev/null +++ b/pkg/integration/tests/worktree/add_from_commit.go @@ -0,0 +1,56 @@ +package worktree + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var AddFromCommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Add a worktree via the commits view", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.NewBranch("mybranch") + shell.CreateFileAndAdd("README.md", "hello world") + shell.Commit("initial commit") + shell.EmptyCommit("commit two") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Focus(). + Lines( + Contains("commit two").IsSelected(), + Contains("initial commit"), + ). + NavigateToLine(Contains("initial commit")). + Press(keys.Worktrees.ViewWorktreeOptions). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Worktree")). + Select(MatchesRegexp(`Create worktree from .*`).DoesNotContain("detached")). + Confirm() + + t.ExpectPopup().Prompt(). + Title(Equals("New worktree path")). + Type("../linked-worktree"). + Confirm() + + t.ExpectPopup().Prompt(). + Title(Equals("New branch name")). + Type("newbranch"). + Confirm() + }). + Lines( + Contains("initial commit"), + ) + + // Confirm we're now in the branches view + t.Views().Branches(). + IsFocused(). + Lines( + Contains("newbranch").IsSelected(), + Contains("mybranch (worktree)"), + ) + }, +}) diff --git a/pkg/integration/tests/worktree/bisect.go b/pkg/integration/tests/worktree/bisect.go new file mode 100644 index 000000000..143f8114f --- /dev/null +++ b/pkg/integration/tests/worktree/bisect.go @@ -0,0 +1,88 @@ +package worktree + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +// This is important because `git worktree list` will show a worktree being in a detached head state (which is true) +// when it's in the middle of a bisect, but it won't tell you about the branch it's on. +// Even so, if you attempt to check out that branch from another worktree git won't let you, so we need to +// keep track of the association ourselves. + +// not bothering to test the linked worktree here because it's the same logic as the rebase test + +var Bisect = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Verify that when you start a bisect in a linked worktree, Lazygit still associates the worktree with the branch", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.NewBranch("mybranch") + shell.CreateFileAndAdd("README.md", "hello world") + shell.Commit("initial commit") + shell.EmptyCommit("commit 2") + shell.EmptyCommit("commit 3") + shell.AddWorktree("mybranch", "../linked-worktree", "newbranch") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Lines( + Contains("mybranch").IsSelected(), + Contains("newbranch (worktree)"), + ) + + // start a bisect on the main worktree + t.Views().Commits(). + Focus(). + SelectedLine(Contains("commit 3")). + Press(keys.Commits.ViewBisectOptions). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Bisect")). + Select(MatchesRegexp(`Mark .* as bad`)). + Confirm() + + t.Views().Information().Content(Contains("Bisecting")) + }). + NavigateToLine(Contains("initial commit")). + Press(keys.Commits.ViewBisectOptions). + Tap(func() { + t.ExpectPopup().Menu(). + Title(Equals("Bisect")). + Select(MatchesRegexp(`Mark .* as good`)). + Confirm() + }) + + t.Views().Branches(). + Focus(). + // switch to linked worktree + NavigateToLine(Contains("newbranch")). + Press(keys.Universal.Select). + Tap(func() { + t.ExpectPopup().Confirmation(). + Title(Equals("Switch to worktree")). + Content(Equals("This branch is checked out by worktree linked-worktree. Do you want to switch to that worktree?")). + Confirm() + + t.Views().Information().Content(DoesNotContain("Bisecting")) + }). + Lines( + Contains("newbranch").IsSelected(), + Contains("mybranch (worktree)"), + ) + + // switch back to main worktree + t.Views().Branches(). + Focus(). + NavigateToLine(Contains("mybranch")). + Press(keys.Universal.Select). + Tap(func() { + t.ExpectPopup().Confirmation(). + Title(Equals("Switch to worktree")). + Content(Equals("This branch is checked out by worktree repo. Do you want to switch to that worktree?")). + Confirm() + }) + }, +}) diff --git a/pkg/integration/tests/worktree/custom_command.go b/pkg/integration/tests/worktree/custom_command.go new file mode 100644 index 000000000..2276e59be --- /dev/null +++ b/pkg/integration/tests/worktree/custom_command.go @@ -0,0 +1,40 @@ +package worktree + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var CustomCommand = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Verify that custom commands work with worktrees by deleting a worktree via a custom command", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(cfg *config.AppConfig) { + cfg.UserConfig.CustomCommands = []config.CustomCommand{ + { + Key: "d", + Context: "worktrees", + Command: "git worktree remove {{ .SelectedWorktree.Path | quote }}", + }, + } + }, + SetupRepo: func(shell *Shell) { + shell.NewBranch("mybranch") + shell.CreateFileAndAdd("README.md", "hello world") + shell.Commit("initial commit") + shell.AddWorktree("mybranch", "../linked-worktree", "newbranch") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Worktrees(). + Focus(). + Lines( + Contains("repo (main)"), + Contains("linked-worktree"), + ). + NavigateToLine(Contains("linked-worktree")). + Press("d"). + Lines( + Contains("repo (main)"), + ) + }, +}) diff --git a/pkg/integration/tests/worktree/rebase.go b/pkg/integration/tests/worktree/rebase.go index e8ae59556..8b91702b5 100644 --- a/pkg/integration/tests/worktree/rebase.go +++ b/pkg/integration/tests/worktree/rebase.go @@ -10,8 +10,11 @@ import ( // Even so, if you attempt to check out that branch from another worktree git won't let you, so we need to // keep track of the association ourselves. +// We need different logic for associated the branch depending on whether it's a main worktree or +// linked worktree, so this test handles both. + var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ - Description: "Verify that when you start a rebase in a worktree, Lazygit still associates the worktree with the branch", + Description: "Verify that when you start a rebase in a linked or main worktree, Lazygit still associates the worktree with the branch", ExtraCmdArgs: []string{}, Skip: false, SetupConfig: func(config *config.AppConfig) {}, @@ -27,10 +30,11 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Branches(). Focus(). Lines( - Contains("mybranch"), + Contains("mybranch").IsSelected(), Contains("newbranch (worktree)"), ) + // start a rebase on the main worktree t.Views().Commits(). Focus(). NavigateToLine(Contains("commit 2")). @@ -54,8 +58,19 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ Lines( Contains("newbranch").IsSelected(), Contains("mybranch (worktree)"), - ). - // switch back to main worktree + ) + + // start a rebase on the linked worktree + t.Views().Commits(). + Focus(). + NavigateToLine(Contains("commit 2")). + Press(keys.Universal.Edit) + + t.Views().Information().Content(Contains("Rebasing")) + + // switch back to main worktree + t.Views().Branches(). + Focus(). NavigateToLine(Contains("mybranch")). Press(keys.Universal.Select). Tap(func() { @@ -63,8 +78,12 @@ var Rebase = NewIntegrationTest(NewIntegrationTestArgs{ Title(Equals("Switch to worktree")). Content(Equals("This branch is checked out by worktree repo. Do you want to switch to that worktree?")). Confirm() - - t.Views().Information().Content(Contains("Rebasing")) - }) + }). + Lines( + Contains("(no branch").IsSelected(), + Contains("mybranch"), + // even though the linked worktree is rebasing, we still associate it with the branch + Contains("newbranch (worktree)"), + ) }, }) |