summaryrefslogtreecommitdiffstats
path: root/pkg/commands/commits.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-04-10 11:40:42 +1000
committerJesse Duffield <jessedduffield@gmail.com>2021-04-10 11:54:38 +1000
commite42e7e5cbd9d075ee24ae8f91ba9e12bdd42fafc (patch)
tree61d65a544c056b3bf0384cf6954b81b292eb4b07 /pkg/commands/commits.go
parent93fac1f3124f87009091230f61cc13b5e5473cb5 (diff)
fix commit amend
Diffstat (limited to 'pkg/commands/commits.go')
-rw-r--r--pkg/commands/commits.go28
1 files changed, 13 insertions, 15 deletions
diff --git a/pkg/commands/commits.go b/pkg/commands/commits.go
index 74043518d..3582131a6 100644
--- a/pkg/commands/commits.go
+++ b/pkg/commands/commits.go
@@ -19,20 +19,19 @@ func (c *GitCommand) ResetToCommit(sha string, strength string, options oscomman
return c.OSCommand.RunCommandWithOptions(fmt.Sprintf("git reset --%s %s", strength, sha), options)
}
-// Commit commits to git
-func (c *GitCommand) Commit(message string, flags string) (*exec.Cmd, error) {
+func (c *GitCommand) CommitCmdStr(message string, flags string) string {
splitMessage := strings.Split(message, "\n")
lineArgs := ""
for _, line := range splitMessage {
lineArgs += fmt.Sprintf(" -m %s", c.OSCommand.Quote(line))
}
- command := fmt.Sprintf("git commit %s%s", flags, lineArgs)
- if c.usingGpg() {
- return c.OSCommand.ShellCommandFromString(command), nil
+ flagsStr := ""
+ if flags != "" {
+ flagsStr = fmt.Sprintf(" %s", flags)
}
- return nil, c.OSCommand.RunCommand(command)
+ return fmt.Sprintf("git commit%s%s", flagsStr, lineArgs)
}
// Get the subject of the HEAD commit
@@ -50,18 +49,17 @@ func (c *GitCommand) GetCommitMessage(commitSha string) (string, error) {
}
// AmendHead amends HEAD with whatever is staged in your working tree
-func (c *GitCommand) AmendHead() (*exec.Cmd, error) {
- command := "git commit --amend --no-edit --allow-empty"
- if c.usingGpg() {
- return c.OSCommand.ShellCommandFromString(command), nil
- }
+func (c *GitCommand) AmendHead() error {
+ return c.OSCommand.RunCommand(c.AmendHeadCmdStr())
+}
- return nil, c.OSCommand.RunCommand(command)
+// PrepareCommitAmendHeadSubProcess prepares a subprocess for `git commit --amend --allow-empty`
+func (c *GitCommand) PrepareCommitAmendHeadSubProcess() *exec.Cmd {
+ return c.OSCommand.ShellCommandFromString(c.AmendHeadCmdStr())
}
-// PrepareCommitAmendSubProcess prepares a subprocess for `git commit --amend --allow-empty`
-func (c *GitCommand) PrepareCommitAmendSubProcess() *exec.Cmd {
- return c.OSCommand.PrepareSubProcess("git", "commit", "--amend", "--allow-empty")
+func (c *GitCommand) AmendHeadCmdStr() string {
+ return "git commit --amend --no-edit --allow-empty"
}
func (c *GitCommand) ShowCmdStr(sha string, filterPath string) string {