1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

factor out duplicate code into 'ShellCommandFromString'

Signed-off-by: Randshot <randshot@norealm.xyz>
This commit is contained in:
Randshot
2020-07-13 16:00:00 +02:00
committed by Jesse Duffield
parent 39a2122dc0
commit 014e06eefd
2 changed files with 15 additions and 18 deletions

View File

@ -453,15 +453,7 @@ func (c *GitCommand) usingGpg() bool {
func (c *GitCommand) Commit(message string, flags string) (*exec.Cmd, error) {
command := fmt.Sprintf("git commit %s -m %s", flags, c.OSCommand.Quote(message))
if c.usingGpg() {
quotedCommand := ""
// Windows does not seem to like quotes around the command
if c.OSCommand.Platform.os == "windows" {
quotedCommand = command
} else {
quotedCommand = c.OSCommand.Quote(command)
}
return c.OSCommand.ExecutableFromString(fmt.Sprintf("%s %s %s", c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, quotedCommand)), nil
return c.OSCommand.ShellCommandFromString(command), nil
}
return nil, c.OSCommand.RunCommand(command)
@ -478,15 +470,7 @@ func (c *GitCommand) GetHeadCommitMessage() (string, error) {
func (c *GitCommand) AmendHead() (*exec.Cmd, error) {
command := "git commit --amend --no-edit --allow-empty"
if c.usingGpg() {
quotedCommand := ""
// Windows does not seem to like quotes around the command
if c.OSCommand.Platform.os == "windows" {
quotedCommand = command
} else {
quotedCommand = c.OSCommand.Quote(command)
}
return c.OSCommand.ExecutableFromString(fmt.Sprintf("%s %s %s", c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, quotedCommand)), nil
return c.OSCommand.ShellCommandFromString(command), nil
}
return nil, c.OSCommand.RunCommand(command)