File: commit_switch_to_editor_skip_hooks.go

package info (click to toggle)
lazygit 0.57.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,748 kB
  • sloc: sh: 153; makefile: 76
file content (64 lines) | stat: -rw-r--r-- 1,925 bytes parent folder | download | duplicates (2)
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
package commit

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

var CommitSwitchToEditorSkipHooks = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Commit, then switch from built-in commit message panel to editor",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupConfig:  func(config *config.AppConfig) {},
	SetupRepo: func(shell *Shell) {
		shell.CreateFile(".git/hooks/pre-commit", blockingHook)
		shell.MakeExecutable(".git/hooks/pre-commit")
		shell.CreateFile("file1", "file1 content")
		shell.CreateFile("file2", "file2 content")

		// Set an editor that appends a line to the existing message. Since
		// git adds all this "# Please enter the commit message for your changes"
		// stuff, this will result in an extra blank line before the added line.
		shell.SetConfig("core.editor", "sh -c 'echo third line >>.git/COMMIT_EDITMSG'")
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Commits().
			IsEmpty()

		checkBlockingHook(t, keys)

		t.Views().Files().
			IsFocused().
			Lines(
				Equals("▼ /").IsSelected(),
				Equals("  ?? file1"),
				Equals("  ?? file2"),
			).
			SelectNextItem().
			PressPrimaryAction(). // stage one of the files
			Press(keys.Files.CommitChangesWithoutHook)

		t.ExpectPopup().CommitMessagePanel().
			Type("first line").
			SwitchToDescription().
			Type("second line").
			SwitchToSummary().
			SwitchToEditor()
		t.Views().Commits().
			Lines(
				Contains("first line"),
			)

		t.Views().Commits().Focus()
		t.Views().Main().Content(MatchesRegexp(`first line\n\s*\n\s*second line\n\s*\n\s*third line`))

		// Now check that the preserved commit message was cleared:
		t.Views().Files().
			Focus().
			PressPrimaryAction(). // stage the other file
			Press(keys.Files.CommitChanges)

		t.ExpectPopup().CommitMessagePanel().
			InitialText(Equals(""))
	},
})