mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +02:00
Add integration tests for skipping pre-commit hooks
This commit is contained in:
parent
b2ff09ec0c
commit
4ec41c4414
2 changed files with 81 additions and 0 deletions
80
pkg/integration/tests/commit/commit_skip_hook.go
Normal file
80
pkg/integration/tests/commit/commit_skip_hook.go
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
package commit
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
const preCommitHook = `#!/bin/bash
|
||||||
|
|
||||||
|
exit 1
|
||||||
|
`
|
||||||
|
|
||||||
|
var CommitSkipHook = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Commit with pre-commit hook and skip hook config option in various situations.",
|
||||||
|
ExtraCmdArgs: []string{},
|
||||||
|
Skip: false,
|
||||||
|
SetupConfig: func(testConfig *config.AppConfig) {
|
||||||
|
testConfig.UserConfig.Git.SkipHookPrefix = "skip! "
|
||||||
|
|
||||||
|
},
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
shell.SetConfig("user.email", "Bill@example.com")
|
||||||
|
shell.SetConfig("user.name", "Bill Smith")
|
||||||
|
|
||||||
|
shell.CreateFileAndAdd("initial file", "initial content")
|
||||||
|
shell.Commit("initial commit")
|
||||||
|
|
||||||
|
shell.SetConfig("user.email", "John@example.com")
|
||||||
|
shell.SetConfig("user.name", "John Smith")
|
||||||
|
|
||||||
|
shell.CreateFile(".git/hooks/pre-commit", preCommitHook)
|
||||||
|
shell.MakeExecutable(".git/hooks/pre-commit")
|
||||||
|
|
||||||
|
shell.CreateFileAndAdd("testfile", "I'm just testing pre-commit hooks")
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.Views().Files().
|
||||||
|
Focus().
|
||||||
|
Press(keys.Files.CommitChanges)
|
||||||
|
|
||||||
|
// hook should trigger when creating a regular commit
|
||||||
|
t.ExpectPopup().CommitMessagePanel().Type("my commit message").Confirm()
|
||||||
|
t.ExpectPopup().Alert().Title(Equals("Error")).Content(Contains("Git command failed")).Confirm()
|
||||||
|
|
||||||
|
t.Views().Files().
|
||||||
|
Focus().
|
||||||
|
Press(keys.Files.CommitChanges)
|
||||||
|
|
||||||
|
// we should be able to skip hooks when creating a regular commit
|
||||||
|
t.ExpectPopup().CommitMessagePanel().Clear().Type("skip! my commit message").Confirm()
|
||||||
|
t.Views().Commits().Focus().Lines(
|
||||||
|
Contains("skip! my commit message"),
|
||||||
|
Contains("initial commit"),
|
||||||
|
)
|
||||||
|
|
||||||
|
// we should be able to skip hooks when rewording a commit
|
||||||
|
t.Views().Commits().Focus().Press(keys.Commits.RenameCommit)
|
||||||
|
t.ExpectPopup().CommitMessagePanel().Type(" (reworded)").Confirm()
|
||||||
|
|
||||||
|
/* EXPECTED:
|
||||||
|
t.Views().Commits().IsFocused().
|
||||||
|
Lines(
|
||||||
|
Contains("skip! my commit message (reworded)"),
|
||||||
|
Contains("initial commit"),
|
||||||
|
)
|
||||||
|
ACTUAL:
|
||||||
|
*/
|
||||||
|
t.ExpectPopup().Alert().Title(Equals("Error")).Content(Contains("exit status 1")).Confirm()
|
||||||
|
|
||||||
|
// we should be able to skip hooks when changing authors
|
||||||
|
t.Views().Commits().IsFocused().SelectedLine(Contains("CI").IsSelected())
|
||||||
|
t.Views().Commits().Focus().Press(keys.Commits.ResetCommitAuthor)
|
||||||
|
/* EXPECTED:
|
||||||
|
t.Views().Commits().IsFocused().Lines(Contains("JS").IsSelected())
|
||||||
|
ACTUAL:
|
||||||
|
*/
|
||||||
|
t.ExpectPopup().Alert().Title(Equals("Error")).Content(Contains("exit status 1")).Confirm()
|
||||||
|
|
||||||
|
},
|
||||||
|
})
|
|
@ -71,6 +71,7 @@ var tests = []*components.IntegrationTest{
|
||||||
commit.Commit,
|
commit.Commit,
|
||||||
commit.CommitMultiline,
|
commit.CommitMultiline,
|
||||||
commit.CommitSwitchToEditor,
|
commit.CommitSwitchToEditor,
|
||||||
|
commit.CommitSkipHook,
|
||||||
commit.CommitWipWithPrefix,
|
commit.CommitWipWithPrefix,
|
||||||
commit.CommitWithPrefix,
|
commit.CommitWithPrefix,
|
||||||
commit.CreateAmendCommit,
|
commit.CreateAmendCommit,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue