diff --git a/pkg/commands/git_commands/branch.go b/pkg/commands/git_commands/branch.go index a55278b5b..38ac35137 100644 --- a/pkg/commands/git_commands/branch.go +++ b/pkg/commands/git_commands/branch.go @@ -277,6 +277,7 @@ func (self *BranchCommands) Merge(branchName string, variant MergeVariant) error cmdArgs := NewGitCmd("merge"). Arg("--no-edit"). + ArgIf(self.UserConfig().Git.Commit.SignOff, "--signoff"). Arg(strings.Fields(self.UserConfig().Git.Merging.Args)...). Arg(extraArgs...). Arg(branchName). diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index d067e9831..876c874fb 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -91,7 +91,7 @@ func (self *CommitCommands) CommitCmdObj(summary string, description string, for skipHookPrefix := self.UserConfig().Git.SkipHookPrefix cmdArgs := NewGitCmd("commit"). ArgIf(forceSkipHooks || (skipHookPrefix != "" && strings.HasPrefix(summary, skipHookPrefix)), "--no-verify"). - ArgIf(self.signoffFlag() != "", self.signoffFlag()). + ArgIf(self.UserConfig().Git.Commit.SignOff, "--signoff"). Arg(messageArgs...). ToArgv() @@ -112,7 +112,7 @@ func (self *CommitCommands) CommitInEditorWithMessageFileCmdObj(tmpMessageFile s ArgIf(forceSkipHooks, "--no-verify"). Arg("--edit"). Arg("--file="+tmpMessageFile). - ArgIf(self.signoffFlag() != "", self.signoffFlag()). + ArgIf(self.UserConfig().Git.Commit.SignOff, "--signoff"). ToArgv()) } @@ -141,19 +141,12 @@ func (self *CommitCommands) commitMessageArgs(summary string, description string // runs git commit without the -m argument meaning it will invoke the user's editor func (self *CommitCommands) CommitEditorCmdObj() *oscommands.CmdObj { cmdArgs := NewGitCmd("commit"). - ArgIf(self.signoffFlag() != "", self.signoffFlag()). + ArgIf(self.UserConfig().Git.Commit.SignOff, "--signoff"). ToArgv() return self.cmd.New(cmdArgs) } -func (self *CommitCommands) signoffFlag() string { - if self.UserConfig().Git.Commit.SignOff { - return "--signoff" - } - return "" -} - func (self *CommitCommands) GetCommitMessage(commitHash string) (string, error) { cmdArgs := NewGitCmd("log"). Arg("--format=%B", "--max-count=1", commitHash). @@ -272,6 +265,7 @@ func (self *CommitCommands) ShowFileContentCmdObj(hash string, filePath string) func (self *CommitCommands) Revert(hashes []string, isMerge bool) error { cmdArgs := NewGitCmd("revert"). ArgIf(isMerge, "-m", "1"). + ArgIf(self.UserConfig().Git.Commit.SignOff, "--signoff"). Arg(hashes...). ToArgv() diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index 74278b18d..100e5e90f 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -560,6 +560,7 @@ func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error { hasMergeCommit := lo.SomeBy(commits, func(c *models.Commit) bool { return c.IsMerge() }) cmdArgs := NewGitCmd("cherry-pick"). Arg("--allow-empty"). + ArgIf(self.UserConfig().Git.Commit.SignOff, "--signoff"). ArgIf(self.version.IsAtLeast(2, 45, 0), "--empty=keep", "--keep-redundant-commits"). ArgIf(hasMergeCommit, "-m1"). Arg(lo.Reverse(lo.Map(commits, func(c *models.Commit, _ int) string { return c.Hash() }))...).