summaryrefslogtreecommitdiffstats
path: root/pkg/integration/tests/submodule/enter.go
blob: 7b055c2b66e3fd6f370d12c5677b563717970d90 (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
package submodule

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

var Enter = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Enter a submodule, add a commit, and then stage the change in the parent repo",
	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\"",
			},
		}
	},
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("first commit")
		shell.CloneIntoSubmodule("my_submodule")
		shell.GitAddAll()
		shell.Commit("add submodule")
	},
	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().Files().IsFocused().
			Press("e").
			Tap(func() {
				t.Views().Commits().Content(Contains("empty commit"))
			}).
			// return to the parent repo
			PressEscape()

		assertInParentRepo()

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

		// we see the new commit in the submodule is ready to be staged in the parent repo
		t.Views().Main().Content(Contains("> empty commit"))

		t.Views().Files().Focus().
			Lines(
				MatchesRegexp(` M.*my_submodule \(submodule\)`).IsSelected(),
			).
			Tap(func() {
				// main view also shows the new commit when we're looking at the submodule within the files view
				t.Views().Main().Content(Contains("> empty commit"))
			}).
			PressPrimaryAction().
			Press(keys.Files.CommitChanges).
			Tap(func() {
				t.ExpectPopup().CommitMessagePanel().Type("submodule change").Confirm()
			}).
			IsEmpty()

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

		// we no longer report a new commit because we've committed it in the parent repo
		t.Views().Main().Content(DoesNotContain("> empty commit"))
	},
})