summaryrefslogtreecommitdiffstats
path: root/pkg/integration/tests/worktree/crud.go
blob: 504d47b726a82f5bab16c523ba2b7859ac5b9744 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package worktree

import (
	"github.com/jesseduffield/lazygit/pkg/config"
	. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var Crud = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "From the worktrees view, add a work tree, switch to it, switch back, and remove it",
	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().
			Lines(
				Contains("mybranch"),
			)

		t.Views().Status().
			Lines(
				Contains("repo → mybranch"),
			)

		t.Views().Worktrees().
			Focus().
			Lines(
				Contains("repo (main)"),
			).
			Press(keys.Universal.New).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("Worktree")).
					Select(Contains(`Create worktree from ref`).DoesNotContain(("detached"))).
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New worktree base ref")).
					InitialText(Equals("mybranch")).
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New worktree path")).
					Type("../linked-worktree").
					Confirm()

				t.ExpectPopup().Prompt().
					Title(Equals("New branch name (leave blank to checkout mybranch)")).
					Type("newbranch").
					Confirm()
			}).
			Lines(
				Contains("linked-worktree").IsSelected(),
				Contains("repo (main)"),
			).
			// confirm we're still in the same view
			IsFocused()

		// status panel includes the worktree if it's a linked worktree
		t.Views().Status().
			Lines(
				Contains("repo(linked-worktree) → newbranch"),
			)

		t.Views().Branches().
			Lines(
				Contains("newbranch"),
				Contains("mybranch"),
			)

		t.Views().Worktrees().
			// confirm we can't remove the current worktree
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Alert().
					Title(Equals("Error")).
					Content(Equals("You cannot remove the current worktree!")).
					Confirm()
			}).
			// confirm we cannot remove the main worktree
			NavigateToLine(Contains("repo (main)")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Alert().
					Title(Equals("Error")).
					Content(Equals("You cannot remove the main worktree!")).
					Confirm()
			}).
			// switch back to main worktree
			Press(keys.Universal.Select).
			Lines(
				Contains("repo (main)").IsSelected(),
				Contains("linked-worktree"),
			)

		t.Views().Branches().
			Lines(
				Contains("mybranch"),
				Contains("newbranch"),
			)

		t.Views().Worktrees().
			// remove linked worktree
			NavigateToLine(Contains("linked-worktree")).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Confirmation().
					Title(Equals("Remove worktree")).
					Content(Contains("Are you sure you want to remove worktree 'linked-worktree'?")).
					Confirm()
			}).
			Lines(
				Contains("repo (main)").IsSelected(),
			)
	},
})