summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-07 19:19:24 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-09 14:09:53 +1100
commite92076d2c299c8171e972171c174261c6ce62d3b (patch)
treef372a446455f3c0bfa2c96dacc5e03b244487324 /pkg
parentd9089098c3adaa007c1a56468c9da31931877712 (diff)
start removing direct calls to cmd.New from gui
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/commits.go24
-rw-r--r--pkg/commands/patch_rebases.go2
-rw-r--r--pkg/gui/commit_message_panel.go11
-rw-r--r--pkg/gui/files_panel.go10
4 files changed, 22 insertions, 25 deletions
diff --git a/pkg/commands/commits.go b/pkg/commands/commits.go
index ba61df5a5..7ae0fe4bd 100644
--- a/pkg/commands/commits.go
+++ b/pkg/commands/commits.go
@@ -39,19 +39,33 @@ func (self *CommitCommands) ResetToCommit(sha string, strength string, envVars [
Run()
}
-func (self *CommitCommands) CommitCmdObj(message string, flags string) oscommands.ICmdObj {
+func (self *CommitCommands) CommitCmdObj(message string) oscommands.ICmdObj {
splitMessage := strings.Split(message, "\n")
lineArgs := ""
for _, line := range splitMessage {
lineArgs += fmt.Sprintf(" -m %s", self.cmd.Quote(line))
}
- flagsStr := ""
- if flags != "" {
- flagsStr = fmt.Sprintf(" %s", flags)
+ skipHookPrefix := self.UserConfig.Git.SkipHookPrefix
+ noVerifyFlag := ""
+ if skipHookPrefix != "" && strings.HasPrefix(message, skipHookPrefix) {
+ noVerifyFlag = " --no-verify"
}
- return self.cmd.New(fmt.Sprintf("git commit%s%s", flagsStr, lineArgs))
+ return self.cmd.New(fmt.Sprintf("git commit%s%s%s", noVerifyFlag, self.signoffFlag(), lineArgs))
+}
+
+// runs git commit without the -m argument meaning it will invoke the user's editor
+func (self *CommitCommands) CommitEditorCmdObj() oscommands.ICmdObj {
+ return self.cmd.New(fmt.Sprintf("git commit%s", self.signoffFlag()))
+}
+
+func (self *CommitCommands) signoffFlag() string {
+ if self.UserConfig.Git.Commit.SignOff {
+ return " --signoff"
+ } else {
+ return ""
+ }
}
// Get the subject of the HEAD commit
diff --git a/pkg/commands/patch_rebases.go b/pkg/commands/patch_rebases.go
index e28c2d8e6..a006f3b71 100644
--- a/pkg/commands/patch_rebases.go
+++ b/pkg/commands/patch_rebases.go
@@ -252,7 +252,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm
head_message, _ := self.commit.GetHeadCommitMessage()
new_message := fmt.Sprintf("Split from \"%s\"", head_message)
- err := self.commit.CommitCmdObj(new_message, "").Run()
+ err := self.commit.CommitCmdObj(new_message).Run()
if err != nil {
return err
}
diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go
index 32ddb5829..962189d5a 100644
--- a/pkg/gui/commit_message_panel.go
+++ b/pkg/gui/commit_message_panel.go
@@ -14,17 +14,8 @@ func (gui *Gui) handleCommitConfirm() error {
if message == "" {
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
}
- flags := []string{}
- skipHookPrefix := gui.UserConfig.Git.SkipHookPrefix
- if skipHookPrefix != "" && strings.HasPrefix(message, skipHookPrefix) {
- flags = append(flags, "--no-verify")
- }
-
- if gui.UserConfig.Git.Commit.SignOff {
- flags = append(flags, "--signoff")
- }
- cmdObj := gui.GitCommand.Commit.CommitCmdObj(message, strings.Join(flags, " "))
+ cmdObj := gui.GitCommand.Commit.CommitCmdObj(message)
gui.logAction(gui.Tr.Actions.Commit)
_ = gui.returnFromContext()
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index fcf8d021c..045970f05 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -471,17 +471,9 @@ func (gui *Gui) handleCommitEditorPress() error {
return gui.promptToStageAllAndRetry(gui.handleCommitEditorPress)
}
- args := []string{"commit"}
-
- if gui.UserConfig.Git.Commit.SignOff {
- args = append(args, "--signoff")
- }
-
- cmdStr := "git " + strings.Join(args, " ")
-
gui.logAction(gui.Tr.Actions.Commit)
return gui.runSubprocessWithSuspenseAndRefresh(
- gui.GitCommand.Cmd.New(cmdStr),
+ gui.GitCommand.Commit.CommitEditorCmdObj(),
)
}