From 61f0801bd366e959437676ae72b2d9fe98c4b8af Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Wed, 12 Sep 2018 15:20:35 +0200 Subject: [PATCH 1/5] Add ammend commit action. --- pkg/commands/git.go | 8 ++++++-- pkg/gui/commit_message_panel.go | 3 ++- pkg/gui/files_panel.go | 27 +++++++++++++++++++++++++++ pkg/gui/keybindings.go | 7 +++++++ pkg/i18n/dutch.go | 3 +++ pkg/i18n/english.go | 3 +++ pkg/i18n/polish.go | 3 +++ 7 files changed, 51 insertions(+), 3 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 5744fa6aa12..a6f9e2f9c0f 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -299,8 +299,12 @@ func (c *GitCommand) usingGpg() bool { } // Commit commits to git -func (c *GitCommand) Commit(message string) (*exec.Cmd, error) { - command := fmt.Sprintf("git commit -m %s", c.OSCommand.Quote(message)) +func (c *GitCommand) Commit(message string, amend bool) (*exec.Cmd, error) { + amendParam := "" + if amend { + amendParam = "--amend " + } + command := fmt.Sprintf("git commit %s-m %s", amendParam, c.OSCommand.Quote(message)) if c.usingGpg() { return c.OSCommand.PrepareSubProcess(c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, command), nil } diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index e23c47da086..2c3d086c7a0 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -12,7 +12,8 @@ func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error { if message == "" { return gui.createErrorPanel(g, gui.Tr.SLocalize("CommitWithoutMessageErr")) } - sub, err := gui.GitCommand.Commit(message) + amendCommit := v.Title == gui.Tr.SLocalize("AmendLastCommit") + sub, err := gui.GitCommand.Commit(message, amendCommit) if err != nil { // TODO need to find a way to send through this error if err != gui.Errors.ErrSubProcess { diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index bfcc938bb2c..235cb12d816 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -198,10 +198,37 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error { if len(gui.stagedFiles()) == 0 && !gui.State.HasMergeConflicts { return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit")) } + commitMessageView := gui.getCommitMessageView(g) + if commitMessageView.Title == gui.Tr.SLocalize("AmendLastCommit") { + commitMessageView.Clear() + commitMessageView.SetCursor(0, 0) + } + + commitMessageView.Title = gui.Tr.SLocalize("CommitMessage") + g.Update(func(g *gocui.Gui) error { + g.SetViewOnTop("commitMessage") + gui.switchFocus(g, filesView, commitMessageView) + gui.RenderCommitLength() + return nil + }) + return nil +} + +func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) error { + if len(gui.stagedFiles()) == 0 && !gui.State.HasMergeConflicts { + return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit")) + } + commitMessageView := gui.getCommitMessageView(g) + commitMessageView.Clear() + commitMessageView.Title = gui.Tr.SLocalize("AmendLastCommit") + g.Update(func(g *gocui.Gui) error { g.SetViewOnTop("commitMessage") gui.switchFocus(g, filesView, commitMessageView) + lastCommitName := gui.State.Commits[0].Name + commitMessageView.Write([]byte(lastCommitName)) + commitMessageView.SetCursor(len(lastCommitName), 0) gui.RenderCommitLength() return nil }) diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index c8ed7d3c814..3eb8785d2f9 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1,6 +1,7 @@ package gui import "github.com/jesseduffield/gocui" +import "strings" // Binding - a keybinding mapping a key and modifier to a handler. The keypress // is only handled if the given view has focus, or handled globally if the view @@ -98,6 +99,12 @@ func (gui *Gui) GetKeybindings() []Binding { Modifier: gocui.ModNone, Handler: gui.handleCommitPress, Description: gui.Tr.SLocalize("CommitChanges"), + }, { + ViewName: "files", + Key: 'M', + Modifier: gocui.ModNone, + Handler: gui.handleAmendCommitPress, + Description: strings.ToLower(gui.Tr.SLocalize("AmendLastCommit")), }, { ViewName: "files", Key: 'C', diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index cd1282de27f..ef10625d5f3 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -34,6 +34,9 @@ func addDutch(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "CommitChanges", Other: "Commit Veranderingen", + }, &i18n.Message{ + ID: "AmendLastCommit", + Other: "Wijzig laatste commit", }, &i18n.Message{ ID: "CommitChangesWithEditor", Other: "commit Veranderingen met de git editor", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 4f009c075b7..796e6db6225 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -42,6 +42,9 @@ func addEnglish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "CommitChanges", Other: "commit changes", + }, &i18n.Message{ + ID: "AmendLastCommit", + Other: "Amend last commit", }, &i18n.Message{ ID: "CommitChangesWithEditor", Other: "commit changes using git editor", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index c64ab87b8d5..d4f204a3f36 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -32,6 +32,9 @@ func addPolish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "CommitChanges", Other: "commituj zmiany", + }, &i18n.Message{ + ID: "AmendLastCommit", + Other: "Zmień ostatnie zatwierdzenie", }, &i18n.Message{ ID: "CommitChangesWithEditor", Other: "commituj zmiany używając edytora z gita", From 28fe3d6cf989e9fe40292a5b40ed9bc2a8cdeaa6 Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Tue, 25 Sep 2018 22:11:51 +0200 Subject: [PATCH 2/5] Use confirmation popup for amending last commit. --- pkg/gui/commit_message_panel.go | 3 +-- pkg/gui/files_panel.go | 30 ++++++++++-------------------- pkg/gui/keybindings.go | 3 +-- pkg/i18n/dutch.go | 5 ++++- pkg/i18n/english.go | 5 ++++- pkg/i18n/polish.go | 5 ++++- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index 93a3e150388..c26b5573a81 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -12,8 +12,7 @@ func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error { if message == "" { return gui.createErrorPanel(g, gui.Tr.SLocalize("CommitWithoutMessageErr")) } - amendCommit := v.Title == gui.Tr.SLocalize("AmendLastCommit") - sub, err := gui.GitCommand.Commit(message, amendCommit) + sub, err := gui.GitCommand.Commit(message, false) if err != nil { // TODO need to find a way to send through this error if err != gui.Errors.ErrSubProcess { diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index c0d01136a12..d76ba57919a 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -201,14 +201,7 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error { if len(gui.stagedFiles()) == 0 && !gui.State.HasMergeConflicts { return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit")) } - commitMessageView := gui.getCommitMessageView(g) - if commitMessageView.Title == gui.Tr.SLocalize("AmendLastCommit") { - commitMessageView.Clear() - commitMessageView.SetCursor(0, 0) - } - - commitMessageView.Title = gui.Tr.SLocalize("CommitMessage") g.Update(func(g *gocui.Gui) error { g.SetViewOnTop("commitMessage") gui.switchFocus(g, filesView, commitMessageView) @@ -222,20 +215,17 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro if len(gui.stagedFiles()) == 0 && !gui.State.HasMergeConflicts { return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit")) } - commitMessageView := gui.getCommitMessageView(g) - commitMessageView.Clear() - commitMessageView.Title = gui.Tr.SLocalize("AmendLastCommit") + title := strings.Title(gui.Tr.SLocalize("AmendLastCommit")) + question := gui.Tr.SLocalize("SureToAmend") + return gui.createConfirmationPanel(g, filesView, title, question, func(g *gocui.Gui, v *gocui.View) error { + lastCommitMsg := gui.State.Commits[0].Name + _, err := gui.GitCommand.Commit(lastCommitMsg, true) + if err != nil { + gui.createErrorPanel(g, err.Error()) + } - g.Update(func(g *gocui.Gui) error { - g.SetViewOnTop("commitMessage") - gui.switchFocus(g, filesView, commitMessageView) - lastCommitName := gui.State.Commits[0].Name - commitMessageView.Write([]byte(lastCommitName)) - commitMessageView.SetCursor(len(lastCommitName), 0) - gui.RenderCommitLength() - return nil - }) - return nil + return gui.refreshFiles(g) + }, nil) } // handleCommitEditorPress - handle when the user wants to commit changes via diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 44df7b68626..b242028c6e0 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -2,7 +2,6 @@ package gui import ( "github.com/jesseduffield/gocui" - "strings" ) // Binding - a keybinding mapping a key and modifier to a handler. The keypress @@ -131,7 +130,7 @@ func (gui *Gui) GetKeybindings() []*Binding { Key: 'M', Modifier: gocui.ModNone, Handler: gui.handleAmendCommitPress, - Description: strings.ToLower(gui.Tr.SLocalize("AmendLastCommit")), + Description: gui.Tr.SLocalize("AmendLastCommit"), }, { ViewName: "files", Key: 'C', diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index ef10625d5f3..56e93fdc6be 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -36,7 +36,10 @@ func addDutch(i18nObject *i18n.Bundle) error { Other: "Commit Veranderingen", }, &i18n.Message{ ID: "AmendLastCommit", - Other: "Wijzig laatste commit", + Other: "wijzig laatste commit", + }, &i18n.Message{ + ID: "SureToAmend", + Other: "Weet je zeker dat je de laatste commit wilt wijzigen? U kunt het commit-bericht wijzigen vanuit het commits-paneel.", }, &i18n.Message{ ID: "CommitChangesWithEditor", Other: "commit Veranderingen met de git editor", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index bfa1de83e4f..41ce71bd24c 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -44,7 +44,10 @@ func addEnglish(i18nObject *i18n.Bundle) error { Other: "commit changes", }, &i18n.Message{ ID: "AmendLastCommit", - Other: "Amend last commit", + Other: "amend last commit", + }, &i18n.Message{ + ID: "SureToAmend", + Other: "Are you sure you want to amend last commit? You can change commit message from commits panel.", }, &i18n.Message{ ID: "CommitChangesWithEditor", Other: "commit changes using git editor", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index d4f204a3f36..74b4106a571 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -34,7 +34,10 @@ func addPolish(i18nObject *i18n.Bundle) error { Other: "commituj zmiany", }, &i18n.Message{ ID: "AmendLastCommit", - Other: "Zmień ostatnie zatwierdzenie", + Other: "zmień ostatnie zatwierdzenie", + }, &i18n.Message{ + ID: "SureToAmend", + Other: "Czy na pewno chcesz zmienić ostatnie zatwierdzenie? Możesz zmienić komunikat zatwierdzenia z panelu zatwierdzeń.", }, &i18n.Message{ ID: "CommitChangesWithEditor", Other: "commituj zmiany używając edytora z gita", From 5f7ac97a39cf473823e290acfe59a01dfa031625 Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Sat, 6 Oct 2018 07:40:12 +0200 Subject: [PATCH 3/5] Refresh side panels and use uppercase HEAD in all git commands that requires it. --- pkg/commands/git.go | 6 +++--- pkg/gui/files_panel.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 4539e4431c4..87ee69c8cc3 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -221,11 +221,11 @@ func (c *GitCommand) ResetHard() error { // UpstreamDifferenceCount checks how many pushables/pullables there are for the // current branch func (c *GitCommand) UpstreamDifferenceCount() (string, string) { - pushableCount, err := c.OSCommand.RunCommandWithOutput("git rev-list @{u}..head --count") + pushableCount, err := c.OSCommand.RunCommandWithOutput("git rev-list @{u}..HEAD --count") if err != nil { return "?", "?" } - pullableCount, err := c.OSCommand.RunCommandWithOutput("git rev-list head..@{u} --count") + pullableCount, err := c.OSCommand.RunCommandWithOutput("git rev-list HEAD..@{u} --count") if err != nil { return "?", "?" } @@ -236,7 +236,7 @@ func (c *GitCommand) UpstreamDifferenceCount() (string, string) { // to the remote branch of the current branch, a map is returned to ease look up func (c *GitCommand) GetCommitsToPush() map[string]bool { pushables := map[string]bool{} - o, err := c.OSCommand.RunCommandWithOutput("git rev-list @{u}..head --abbrev-commit") + o, err := c.OSCommand.RunCommandWithOutput("git rev-list @{u}..HEAD --abbrev-commit") if err != nil { return pushables } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index d76ba57919a..b16492dfdfd 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -224,7 +224,7 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro gui.createErrorPanel(g, err.Error()) } - return gui.refreshFiles(g) + return gui.refreshSidePanels(g) }, nil) } From 190309e5c1c939b4de5c366b31dea265e78cb4f3 Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Mon, 8 Oct 2018 21:19:45 +0200 Subject: [PATCH 4/5] Check if there is any commit to amend and use 'A' instead of 'M' as shortcut. --- pkg/commands/git.go | 4 ++-- pkg/gui/files_panel.go | 5 +++++ pkg/gui/keybindings.go | 4 ++-- pkg/i18n/dutch.go | 3 +++ pkg/i18n/english.go | 3 +++ pkg/i18n/polish.go | 3 +++ 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index c7de19b3acf..ffaf9fce64b 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -317,9 +317,9 @@ func (c *GitCommand) usingGpg() bool { func (c *GitCommand) Commit(message string, amend bool) (*exec.Cmd, error) { amendParam := "" if amend { - amendParam = "--amend " + amendParam = "--amend" } - command := fmt.Sprintf("git commit %s-m %s", amendParam, c.OSCommand.Quote(message)) + command := fmt.Sprintf("git commit %s -m %s", amendParam, c.OSCommand.Quote(message)) if c.usingGpg() { return c.OSCommand.PrepareSubProcess(c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, command), nil } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index b16492dfdfd..19d7b934259 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -217,6 +217,11 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro } title := strings.Title(gui.Tr.SLocalize("AmendLastCommit")) question := gui.Tr.SLocalize("SureToAmend") + + if len(gui.State.Commits) == 0 { + return gui.createErrorPanel(g, gui.Tr.SLocalize("NoCommitToAmend")) + } + return gui.createConfirmationPanel(g, filesView, title, question, func(g *gocui.Gui, v *gocui.View) error { lastCommitMsg := gui.State.Commits[0].Name _, err := gui.GitCommand.Commit(lastCommitMsg, true) diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index b242028c6e0..78271a3f778 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -127,7 +127,7 @@ func (gui *Gui) GetKeybindings() []*Binding { Description: gui.Tr.SLocalize("CommitChanges"), }, { ViewName: "files", - Key: 'M', + Key: 'A', Modifier: gocui.ModNone, Handler: gui.handleAmendCommitPress, Description: gui.Tr.SLocalize("AmendLastCommit"), @@ -188,7 +188,7 @@ func (gui *Gui) GetKeybindings() []*Binding { Description: gui.Tr.SLocalize("stashFiles"), }, { ViewName: "files", - Key: 'A', + Key: 'M', Modifier: gocui.ModNone, Handler: gui.handleAbortMerge, Description: gui.Tr.SLocalize("abortMerge"), diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 56e93fdc6be..6b24a517406 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -40,6 +40,9 @@ func addDutch(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "SureToAmend", Other: "Weet je zeker dat je de laatste commit wilt wijzigen? U kunt het commit-bericht wijzigen vanuit het commits-paneel.", + }, &i18n.Message{ + ID: "NoCommitToAmend", + Other: "Er is geen verplichting om te wijzigen.", }, &i18n.Message{ ID: "CommitChangesWithEditor", Other: "commit Veranderingen met de git editor", diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 41ce71bd24c..9ead5a54e49 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -48,6 +48,9 @@ func addEnglish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "SureToAmend", Other: "Are you sure you want to amend last commit? You can change commit message from commits panel.", + }, &i18n.Message{ + ID: "NoCommitToAmend", + Other: "There's no commit to amend.", }, &i18n.Message{ ID: "CommitChangesWithEditor", Other: "commit changes using git editor", diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go index 74b4106a571..c37bfe97282 100644 --- a/pkg/i18n/polish.go +++ b/pkg/i18n/polish.go @@ -38,6 +38,9 @@ func addPolish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "SureToAmend", Other: "Czy na pewno chcesz zmienić ostatnie zatwierdzenie? Możesz zmienić komunikat zatwierdzenia z panelu zatwierdzeń.", + }, &i18n.Message{ + ID: "NoCommitToAmend", + Other: "Nie ma zobowiązania do zmiany.", }, &i18n.Message{ ID: "CommitChangesWithEditor", Other: "commituj zmiany używając edytora z gita", From 4287f8ae905237abf3de181461255406c6d0b51d Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Mon, 8 Oct 2018 22:19:42 +0200 Subject: [PATCH 5/5] Fix tests and add test scenarios for amend. --- pkg/commands/git.go | 4 +- pkg/commands/git_test.go | 81 +++++++++++++++++++++++++++++++++++++--- pkg/gui/files_panel.go | 2 +- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index ffaf9fce64b..0e974b567a8 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -317,9 +317,9 @@ func (c *GitCommand) usingGpg() bool { func (c *GitCommand) Commit(message string, amend bool) (*exec.Cmd, error) { amendParam := "" if amend { - amendParam = "--amend" + amendParam = " --amend" } - command := fmt.Sprintf("git commit %s -m %s", amendParam, c.OSCommand.Quote(message)) + command := fmt.Sprintf("git commit%s -m %s", amendParam, c.OSCommand.Quote(message)) if c.usingGpg() { return c.OSCommand.PrepareSubProcess(c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, command), nil } diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index 25820558a07..ebb9de1363d 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -561,7 +561,7 @@ func TestGitCommandUpstreamDifferentCount(t *testing.T) { { "Can't retrieve pullable count", func(cmd string, args ...string) *exec.Cmd { - if args[1] == "head..@{u}" { + if args[1] == "HEAD..@{u}" { return exec.Command("test") } @@ -575,7 +575,7 @@ func TestGitCommandUpstreamDifferentCount(t *testing.T) { { "Retrieve pullable and pushable count", func(cmd string, args ...string) *exec.Cmd { - if args[1] == "head..@{u}" { + if args[1] == "HEAD..@{u}" { return exec.Command("echo", "10") } @@ -889,7 +889,76 @@ func TestGitCommandCommit(t *testing.T) { gitCmd := newDummyGitCommand() gitCmd.getGlobalGitConfig = s.getGlobalGitConfig gitCmd.OSCommand.command = s.command - s.test(gitCmd.Commit("test")) + s.test(gitCmd.Commit("test", false)) + }) + } +} + +func TestGitCommandCommitAmendFromFiles(t *testing.T) { + type scenario struct { + testName string + command func(string, ...string) *exec.Cmd + getGlobalGitConfig func(string) (string, error) + test func(*exec.Cmd, error) + } + + scenarios := []scenario{ + { + "Amend commit using gpg", + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "bash", cmd) + assert.EqualValues(t, []string{"-c", `git commit --amend -m 'test'`}, args) + + return exec.Command("echo") + }, + func(string) (string, error) { + return "true", nil + }, + func(cmd *exec.Cmd, err error) { + assert.NotNil(t, cmd) + assert.Nil(t, err) + }, + }, + { + "Amend commit without using gpg", + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"commit", "--amend", "-m", "test"}, args) + + return exec.Command("echo") + }, + func(string) (string, error) { + return "false", nil + }, + func(cmd *exec.Cmd, err error) { + assert.Nil(t, cmd) + assert.Nil(t, err) + }, + }, + { + "Amend commit without using gpg with an error", + func(cmd string, args ...string) *exec.Cmd { + assert.EqualValues(t, "git", cmd) + assert.EqualValues(t, []string{"commit", "--amend", "-m", "test"}, args) + + return exec.Command("test") + }, + func(string) (string, error) { + return "false", nil + }, + func(cmd *exec.Cmd, err error) { + assert.Nil(t, cmd) + assert.Error(t, err) + }, + }, + } + + for _, s := range scenarios { + t.Run(s.testName, func(t *testing.T) { + gitCmd := newDummyGitCommand() + gitCmd.getGlobalGitConfig = s.getGlobalGitConfig + gitCmd.OSCommand.command = s.command + s.test(gitCmd.Commit("test", true)) }) } } @@ -1507,7 +1576,7 @@ func TestGitCommandGetCommits(t *testing.T) { switch args[0] { case "rev-list": - assert.EqualValues(t, []string{"rev-list", "@{u}..head", "--abbrev-commit"}, args) + assert.EqualValues(t, []string{"rev-list", "@{u}..HEAD", "--abbrev-commit"}, args) return exec.Command("echo") case "log": assert.EqualValues(t, []string{"log", "--oneline", "-30"}, args) @@ -1534,7 +1603,7 @@ func TestGitCommandGetCommits(t *testing.T) { switch args[0] { case "rev-list": - assert.EqualValues(t, []string{"rev-list", "@{u}..head", "--abbrev-commit"}, args) + assert.EqualValues(t, []string{"rev-list", "@{u}..HEAD", "--abbrev-commit"}, args) return exec.Command("echo", "8a2bb0e") case "log": assert.EqualValues(t, []string{"log", "--oneline", "-30"}, args) @@ -1577,7 +1646,7 @@ func TestGitCommandGetCommits(t *testing.T) { switch args[0] { case "rev-list": - assert.EqualValues(t, []string{"rev-list", "@{u}..head", "--abbrev-commit"}, args) + assert.EqualValues(t, []string{"rev-list", "@{u}..HEAD", "--abbrev-commit"}, args) return exec.Command("echo", "8a2bb0e") case "log": assert.EqualValues(t, []string{"log", "--oneline", "-30"}, args) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 19d7b934259..a00bd2843de 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -226,7 +226,7 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro lastCommitMsg := gui.State.Commits[0].Name _, err := gui.GitCommand.Commit(lastCommitMsg, true) if err != nil { - gui.createErrorPanel(g, err.Error()) + return gui.createErrorPanel(g, err.Error()) } return gui.refreshSidePanels(g)