-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Commit without pre-commit hooks action is independent on prefix #4374
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -481,7 +481,7 @@ func (self *MergeAndRebaseHelper) SquashMergeCommitted(refName, checkedOutBranch | |
"selectedRef": refName, | ||
"currentBranch": checkedOutBranchName, | ||
}) | ||
err = self.c.Git().Commit.CommitCmdObj(message, "").Run() | ||
err = self.c.Git().Commit.CommitCmdObj(message, "", false).Run() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another regression: when setting the squashMergeMessage config to start with the skipHooksPrefix, then we would previously skip the hooks when committing the result of a squash merge. You might argue whether this was intentional, but I do think it makes sense. Again, keeping the prefix logic in CommitCmdObj fixes this. |
||
if err != nil { | ||
return err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package commit | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var fileModHook = `#!/bin/bash | ||
|
||
if [[ -f test-wip-commit-prefix ]]; then | ||
echo "Modified text" > test-wip-commit-prefix | ||
fi | ||
` | ||
|
||
var CommitSkipHooks = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Commit with skip hook using CommitChangesWithoutHook", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(config *config.AppConfig) {}, | ||
SetupRepo: func(shell *Shell) { | ||
shell.CreateFile(".git/hooks/pre-commit", fileModHook) | ||
shell.MakeExecutable(".git/hooks/pre-commit") | ||
|
||
shell.NewBranch("feature/TEST-002") | ||
shell.CreateFile("test-wip-commit-prefix", "Initial text") | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
t.Views().Commits(). | ||
IsEmpty() | ||
|
||
t.Views().Files(). | ||
IsFocused(). | ||
PressPrimaryAction(). | ||
Press(keys.Files.CommitChangesWithoutHook) | ||
|
||
t.ExpectPopup().CommitMessagePanel(). | ||
Title(Equals("Commit summary")). | ||
Type("foo bar"). | ||
Confirm() | ||
|
||
t.FileSystem().FileContent("test-wip-commit-prefix", Equals("Initial text")) | ||
|
||
t.Views().Commits().Focus() | ||
t.Views().Main().Content(Contains("foo bar")) | ||
t.Views().Extras().Content(Contains("--no-verify")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting way of checking whether we passed the no-verify flag, but I'm not sure I like it much. If you had a test that committed twice, once with and once without the flag, you couldn't use this check for the second commit. I'd prefer it if we installed an actual hook (using the technique in |
||
}, | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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("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() | ||
|
||
t.Views().Files(). | ||
IsFocused(). | ||
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`)) | ||
t.Views().Extras().Content(Contains("--no-verify")) | ||
|
||
// 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("")) | ||
}, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a regression; previously it was possible to move a custom patch into a new commit with a WIP prefix and have this skip the hooks; now this is no longer possible. Keeping the prefix logic in CommitCmdObj would fix this.
Note that there are other problems while working with custom patches currently doesn't work well with WIP prefixes; see #3532. But those are unrelated to your PR and can be fixed separately.