mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
start removing direct calls to cmd.New from gui
This commit is contained in:
@ -39,19 +39,33 @@ func (self *CommitCommands) ResetToCommit(sha string, strength string, envVars [
|
|||||||
Run()
|
Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitCommands) CommitCmdObj(message string, flags string) oscommands.ICmdObj {
|
func (self *CommitCommands) CommitCmdObj(message string) oscommands.ICmdObj {
|
||||||
splitMessage := strings.Split(message, "\n")
|
splitMessage := strings.Split(message, "\n")
|
||||||
lineArgs := ""
|
lineArgs := ""
|
||||||
for _, line := range splitMessage {
|
for _, line := range splitMessage {
|
||||||
lineArgs += fmt.Sprintf(" -m %s", self.cmd.Quote(line))
|
lineArgs += fmt.Sprintf(" -m %s", self.cmd.Quote(line))
|
||||||
}
|
}
|
||||||
|
|
||||||
flagsStr := ""
|
skipHookPrefix := self.UserConfig.Git.SkipHookPrefix
|
||||||
if flags != "" {
|
noVerifyFlag := ""
|
||||||
flagsStr = fmt.Sprintf(" %s", flags)
|
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
|
// Get the subject of the HEAD commit
|
||||||
|
@ -252,7 +252,7 @@ func (self *PatchCommands) PullPatchIntoNewCommit(commits []*models.Commit, comm
|
|||||||
|
|
||||||
head_message, _ := self.commit.GetHeadCommitMessage()
|
head_message, _ := self.commit.GetHeadCommitMessage()
|
||||||
new_message := fmt.Sprintf("Split from \"%s\"", head_message)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -14,17 +14,8 @@ func (gui *Gui) handleCommitConfirm() error {
|
|||||||
if message == "" {
|
if message == "" {
|
||||||
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
|
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 {
|
cmdObj := gui.GitCommand.Commit.CommitCmdObj(message)
|
||||||
flags = append(flags, "--signoff")
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdObj := gui.GitCommand.Commit.CommitCmdObj(message, strings.Join(flags, " "))
|
|
||||||
gui.logAction(gui.Tr.Actions.Commit)
|
gui.logAction(gui.Tr.Actions.Commit)
|
||||||
|
|
||||||
_ = gui.returnFromContext()
|
_ = gui.returnFromContext()
|
||||||
|
@ -471,17 +471,9 @@ func (gui *Gui) handleCommitEditorPress() error {
|
|||||||
return gui.promptToStageAllAndRetry(gui.handleCommitEditorPress)
|
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)
|
gui.logAction(gui.Tr.Actions.Commit)
|
||||||
return gui.runSubprocessWithSuspenseAndRefresh(
|
return gui.runSubprocessWithSuspenseAndRefresh(
|
||||||
gui.GitCommand.Cmd.New(cmdStr),
|
gui.GitCommand.Commit.CommitEditorCmdObj(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user