-
-
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?
Conversation
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 great start, but it does still need quite a bit of work; see comments below.
pkg/commands/git_commands/commit.go
Outdated
@@ -85,13 +85,11 @@ func (self *CommitCommands) ResetToCommit(hash string, strength string, envVars | |||
Run() | |||
} | |||
|
|||
func (self *CommitCommands) CommitCmdObj(summary string, description string) oscommands.ICmdObj { | |||
func (self *CommitCommands) CommitCmdObj(summary string, description string, verify bool) oscommands.ICmdObj { |
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 super confusing name for this variable; it's backwards. It should be renamed to noVerify
, or probably better to skipHooks
(because variables with no
in them are an invitation for double negations, which I have a strong aversion against).
But see further discussion below.
pkg/commands/git_commands/commit.go
Outdated
cmdArgs := NewGitCmd("commit"). | ||
ArgIf(skipHookPrefix != "" && strings.HasPrefix(summary, skipHookPrefix), "--no-verify"). | ||
ArgIf(verify, "--no-verify"). |
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.
I would propose to keep the previous logic here, and just "or" in the flag. The rationale is that there are several call sites that still want the old logic without having to pass in the flag themselves (I'll annotate them below).
Which means that the flag should probably be called forceSkipHooks
, and be used like this:
ArgIf(forceSkipHooks || (skipHookPrefix != "" && strings.HasPrefix(summary, skipHookPrefix)), "--no-verify").
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.
I can get behind this. I did not particularly like having to put the logic into the handleCommit function anyways.
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.
I adapted the code as you suggested with 97e05e5
configSignoff: false, | ||
configSkipHookPrefix: "", | ||
expectedArgs: []string{"commit", "-m", "test"}, | ||
}, | ||
{ | ||
testName: "Commit with --no-verify flag", | ||
summary: "WIP: test", | ||
verify: true, |
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.
If we do what I suggest above (keeping the prefix logic in CommitCmdObj
), then it would be good to add two more test cases here for the different combinations of prefix vs flag.
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.
See 97e05e5
@@ -303,7 +303,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit( | |||
return err | |||
} | |||
|
|||
if err := self.commit.CommitCmdObj(commitSummary, commitDescription).Run(); err != nil { | |||
if err := self.commit.CommitCmdObj(commitSummary, commitDescription, false).Run(); err != nil { |
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.
@@ -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 comment
The 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.
getCommitSummary func() string | ||
setCommitSummary func(string) | ||
getCommitDescription func() string | ||
// getVerifyFlag func() bool | ||
getCommitSummary func() string | ||
setCommitSummary func(string) | ||
getCommitDescription func() string |
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 should go into the previous commit, I suppose. Also below.
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.
True. I kind of expected you would squash on merge 😄
|
||
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 comment
The 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 fail_hooks_then_commit_no_hooks.go
), and have it write something to a file; we can then check whether the file exists (or what it contains) using t.FileSystem().PathPresent()
or t.FileSystem().FileContent()
.
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.
About 2a4911c:
I adapted this test to use an actual hook but I'm not quite certain this is what you meant. So this is more a draft and I'm happy to reiterate and update the other integration (e.g. CommitSwitchToEditorSkipHooks) tests if necessary.
Like this, the hook would update the file content and if you replace keys.Files.CommitChangesWithoutHook
with keys.Files.CommitChanges
the test fails.
Overall I'm fine with it and it is certainly more explicit but I'm not sure it is that much clearer than just looking at the --no-verify
in the command log for this particular test.
As discussed in #1984, this PR modifies the code such that the
w
command always commits without pre-commit hooks. TheskipHookPrefix
is still considered when starting the commit messaged with the prefix in the regular commit command usingc
.Skipping pre-commits also works when switching to the editor and adding a co author from the the
w
commandI think this PR could also remove the
SkipHookPrefixNotConfigured
text in english and all internationalisations but I was not sure how this is handled.go generate ./...
)Text is internationalised (see here)If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)Docs have been updated if necessary