summaryrefslogtreecommitdiffstats
path: root/pkg/integration
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-24 15:29:23 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-30 18:35:23 +1000
commitb93b9dae888683bb36da141981842a85e8010ff2 (patch)
treea4027264e225ca24beb983acda504cacda54025e /pkg/integration
parent277142fc4b9db9d722b648efb29b6fa905b5fb36 (diff)
Add worktree tests for removing/detaching
Diffstat (limited to 'pkg/integration')
-rw-r--r--pkg/integration/components/shell.go10
-rw-r--r--pkg/integration/tests/test_list.go3
-rw-r--r--pkg/integration/tests/worktree/detach_worktree_from_branch.go48
-rw-r--r--pkg/integration/tests/worktree/force_remove_worktree.go46
-rw-r--r--pkg/integration/tests/worktree/remove_worktree_from_branch.go58
5 files changed, 165 insertions, 0 deletions
diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go
index 809cb1d5b..bfa82c45e 100644
--- a/pkg/integration/components/shell.go
+++ b/pkg/integration/components/shell.go
@@ -261,6 +261,16 @@ func (self *Shell) AddWorktree(base string, path string, newBranchName string) *
})
}
+func (self *Shell) AddFileInWorktree(worktreePath string) *Shell {
+ self.CreateFile(filepath.Join(worktreePath, "content"), "content")
+
+ self.RunCommand([]string{
+ "git", "-C", worktreePath, "add", "content",
+ })
+
+ return self
+}
+
func (self *Shell) MakeExecutable(path string) *Shell {
// 0755 sets the executable permission for owner, and read/execute permissions for group and others
err := os.Chmod(filepath.Join(self.dir, path), 0o755)
diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go
index d2e2848e7..e22ed7334 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -222,6 +222,9 @@ var tests = []*components.IntegrationTest{
undo.UndoDrop,
worktree.AddFromBranch,
worktree.Crud,
+ worktree.DetachWorktreeFromBranch,
+ worktree.ForceRemoveWorktree,
worktree.Rebase,
+ worktree.RemoveWorktreeFromBranch,
worktree.WorktreeInRepo,
}
diff --git a/pkg/integration/tests/worktree/detach_worktree_from_branch.go b/pkg/integration/tests/worktree/detach_worktree_from_branch.go
new file mode 100644
index 000000000..4dd3c23fd
--- /dev/null
+++ b/pkg/integration/tests/worktree/detach_worktree_from_branch.go
@@ -0,0 +1,48 @@
+package worktree
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var DetachWorktreeFromBranch = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Detach a worktree from 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")
+ 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)"),
+ ).
+ NavigateToLine(Contains("newbranch")).
+ Press(keys.Universal.Remove).
+ Tap(func() {
+ t.ExpectPopup().Menu().
+ Title(Equals("Branch newbranch is checked out by worktree linked-worktree")).
+ Select(Equals("Detach worktree")).
+ Confirm()
+ }).
+ Lines(
+ Contains("mybranch"),
+ Contains("newbranch").DoesNotContain("(worktree").IsSelected(),
+ )
+
+ t.Views().Worktrees().
+ Focus().
+ Lines(
+ Contains("repo (main)").IsSelected(),
+ Contains("linked-worktree"),
+ )
+ },
+})
diff --git a/pkg/integration/tests/worktree/force_remove_worktree.go b/pkg/integration/tests/worktree/force_remove_worktree.go
new file mode 100644
index 000000000..23d0b9a88
--- /dev/null
+++ b/pkg/integration/tests/worktree/force_remove_worktree.go
@@ -0,0 +1,46 @@
+package worktree
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var ForceRemoveWorktree = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Force remove a dirty worktree",
+ 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")
+ shell.AddFileInWorktree("../linked-worktree")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Worktrees().
+ Focus().
+ Lines(
+ Contains("repo (main)").IsSelected(),
+ Contains("linked-worktree"),
+ ).
+ NavigateToLine(Contains("linked-worktree")).
+ Press(keys.Universal.Remove).
+ Tap(func() {
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Remove worktree")).
+ Content(Equals("Are you sure you want to remove worktree 'linked-worktree'?")).
+ Confirm()
+
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Remove worktree")).
+ Content(Equals("'linked-worktree' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?")).
+ Confirm()
+ }).
+ Lines(
+ Contains("repo (main)").IsSelected(),
+ )
+ },
+})
diff --git a/pkg/integration/tests/worktree/remove_worktree_from_branch.go b/pkg/integration/tests/worktree/remove_worktree_from_branch.go
new file mode 100644
index 000000000..06c729edb
--- /dev/null
+++ b/pkg/integration/tests/worktree/remove_worktree_from_branch.go
@@ -0,0 +1,58 @@
+package worktree
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+)
+
+var RemoveWorktreeFromBranch = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "Remove a worktree from 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")
+ shell.EmptyCommit("commit 2")
+ shell.EmptyCommit("commit 3")
+ shell.AddWorktree("mybranch", "../linked-worktree", "newbranch")
+ shell.AddFileInWorktree("../linked-worktree")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ t.Views().Branches().
+ Focus().
+ Lines(
+ Contains("mybranch").IsSelected(),
+ Contains("newbranch (worktree)"),
+ ).
+ NavigateToLine(Contains("newbranch")).
+ Press(keys.Universal.Remove).
+ Tap(func() {
+ t.ExpectPopup().Menu().
+ Title(Equals("Branch newbranch is checked out by worktree linked-worktree")).
+ Select(Equals("Remove worktree")).
+ Confirm()
+
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Remove worktree")).
+ Content(Equals("Are you sure you want to remove worktree 'linked-worktree'?")).
+ Confirm()
+
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Remove worktree")).
+ Content(Equals("'linked-worktree' contains modified or untracked files (to be honest, it could contain both). Are you sure you want to remove it?")).
+ Confirm()
+ }).
+ Lines(
+ Contains("mybranch"),
+ Contains("newbranch").DoesNotContain("(worktree").IsSelected(),
+ )
+
+ t.Views().Worktrees().
+ Focus().
+ Lines(
+ Contains("repo (main)").IsSelected(),
+ )
+ },
+})