summaryrefslogtreecommitdiffstats
path: root/pkg/integration/tests/submodule/reset.go
blob: fba91bee84e04f1b72fc3e93059e905a73ef448f (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
121
122
123
124
125
126
127
128
package submodule

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

var Reset = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Enter a submodule, create a commit and stage some changes, then reset the submodule from back in the parent repo. This test captures functionality around getting a dirty submodule out of your files panel.",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.UserConfig.CustomCommands = []config.CustomCommand{
			{
				Key:     "e",
				Context: "files",
				Command: "git commit --allow-empty -m \"empty commit\" && echo \"my_file content\" > my_file",
			},
		}
	},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("first commit")
		shell.CloneIntoSubmodule("my_submodule")
		shell.GitAddAll()
		shell.Commit("add submodule")

		shell.CreateFile("other_file", "")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		assertInParentRepo := func() {
			t.Views().Status().Content(Contains("repo"))
		}
		assertInSubmodule := func() {
			t.Views().Status().Content(Contains("my_submodule"))
		}

		assertInParentRepo()

		t.Views().Submodules().Focus().
			Lines(
				Contains("my_submodule").IsSelected(),
			).
			// enter the submodule
			PressEnter()

		assertInSubmodule()

		t.Views().Status().Content(Contains("my_submodule"))

		t.Views().Files().IsFocused().
			Press("e").
			Tap(func() {
				t.Views().Commits().Content(Contains("empty commit"))
				t.Views().Files().Content(Contains("my_file"))
			}).
			Lines(
				Contains("my_file").IsSelected(),
			).
			// stage my_file
			PressPrimaryAction().
			// return to the parent repo
			PressEscape()

		assertInParentRepo()

		t.Views().Submodules().IsFocused()

		t.Views().Main().Content(Contains("Submodule my_submodule contains modified content"))

		t.Views().Files().Focus().
			Lines(
				MatchesRegexp(` M.*my_submodule \(submodule\)`),
				Contains("other_file").IsSelected(),
			).
			// Verify we can't use range select on submodules
			Press(keys.Universal.ToggleRangeSelect).
			SelectPreviousItem().
			Lines(
				MatchesRegexp(` M.*my_submodule \(submodule\)`).IsSelected(),
				Contains("other_file").IsSelected(),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectToast(Contains("Disabled: Range select not supported for submodules"))
			}).
			Press(keys.Universal.ToggleRangeSelect).
			Lines(
				MatchesRegexp(` M.*my_submodule \(submodule\)`).IsSelected(),
				Contains("other_file"),
			).
			Press(keys.Universal.Remove).
			Tap(func() {
				t.ExpectPopup().Menu().
					Title(Equals("my_submodule")).
					Select(Contains("Stash uncommitted submodule changes and update")).
					Confirm()
			}).
			Lines(
				Contains("other_file").IsSelected(),
			)

		t.Views().Submodules().Focus().
			PressEnter()

		assertInSubmodule()

		// submodule has been hard reset to the commit the parent repo specifies
		t.Views().Branches().Lines(
			Contains("HEAD detached").IsSelected(),
			Contains("master"),
		)

		// empty commit is gone
		t.Views().Commits().Lines(
			Contains("first commit").IsSelected(),
		)

		// the staged change has been stashed
		t.Views().Files().IsEmpty()

		t.Views().Stash().Focus().
			Lines(
				Contains("WIP on master").IsSelected(),
			)

		t.Views().Main().Content(Contains("my_file content"))
	},
})