diff options
author | Rob Bast <rob.bast@gmail.com> | 2018-08-15 15:02:01 +0200 |
---|---|---|
committer | Rob Bast <rob.bast@gmail.com> | 2018-08-20 08:37:16 +0200 |
commit | 8e3df6b981c8d501fcaecf6689aa7f78c25920fa (patch) | |
tree | 3675bb17fd2a1e064114a724f75825956170762c /pkg | |
parent | 64cf8f5b107a310e6729b68ba8d7638effd3966d (diff) |
add option to force delete given branch
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/git.go | 10 | ||||
-rw-r--r-- | pkg/gui/branches_panel.go | 13 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 1 | ||||
-rw-r--r-- | pkg/i18n/dutch.go | 3 | ||||
-rw-r--r-- | pkg/i18n/english.go | 3 |
5 files changed, 26 insertions, 4 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 557e6a8c0..45219b5c0 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -223,8 +223,14 @@ func (c *GitCommand) NewBranch(name string) error { } // DeleteBranch delete branch -func (c *GitCommand) DeleteBranch(branch string) error { - return c.OSCommand.RunCommand("git branch -d " + branch) +func (c *GitCommand) DeleteBranch(branch string, force bool) error { + var command string + if force { + command = "git branch -D " + } else { + command = "git branch -d " + } + return c.OSCommand.RunCommand(command + branch) } // ListStash list stash diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 67e0ceb07..886b4c493 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -62,20 +62,28 @@ func (gui *Gui) handleNewBranch(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleDeleteBranch(g *gocui.Gui, v *gocui.View) error { + gui.deleteBranch(g, v, false) +} + +func (gui *Gui) handleForceDeleteBranch(g *gocui.Gui, v *gocui.View) error { + gui.deleteBranch(g, v, true) +} + +func (gui *Gui) deleteBranch(g *gocui.Gui, v *gocui.View, force bool) error { checkedOutBranch := gui.State.Branches[0] selectedBranch := gui.getSelectedBranch(v) if checkedOutBranch.Name == selectedBranch.Name { return gui.createErrorPanel(g, gui.Tr.SLocalize("CantDeleteCheckOutBranch")) } + title := gui.Tr.SLocalize("DeleteBranch") message := gui.Tr.TemplateLocalize( "DeleteBranchMessage", Teml{ "selectedBranchName": selectedBranch.Name, }, ) - title := gui.Tr.SLocalize("DeleteBranch") return gui.createConfirmationPanel(g, v, title, message, func(g *gocui.Gui, v *gocui.View) error { - if err := gui.GitCommand.DeleteBranch(selectedBranch.Name); err != nil { + if err := gui.GitCommand.DeleteBranch(selectedBranch.Name, force); err != nil { return gui.createErrorPanel(g, err.Error()) } return gui.refreshSidePanels(g) @@ -108,6 +116,7 @@ func (gui *Gui) renderBranchesOptions(g *gocui.Gui) error { "c": gui.Tr.SLocalize("checkoutByName"), "n": gui.Tr.SLocalize("newBranch"), "d": gui.Tr.SLocalize("deleteBranch"), + "D": gui.Tr.SLocalize("forceDeleteBranch"), "← → ↑ ↓": gui.Tr.SLocalize("navigate"), }) } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 68cccda6b..e0351b88e 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -57,6 +57,7 @@ func (gui *Gui) keybindings(g *gocui.Gui) error { {ViewName: "branches", Key: 'F', Modifier: gocui.ModNone, Handler: gui.handleForceCheckout}, {ViewName: "branches", Key: 'n', Modifier: gocui.ModNone, Handler: gui.handleNewBranch}, {ViewName: "branches", Key: 'd', Modifier: gocui.ModNone, Handler: gui.handleDeleteBranch}, + {ViewName: "branches", Key: 'D', Modifier: gocui.ModNone, Handler: gui.handleForceDeleteBranch}, {ViewName: "branches", Key: 'm', Modifier: gocui.ModNone, Handler: gui.handleMerge}, {ViewName: "commits", Key: 's', Modifier: gocui.ModNone, Handler: gui.handleCommitSquashDown}, {ViewName: "commits", Key: 'r', Modifier: gocui.ModNone, Handler: gui.handleRenameCommit}, diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go index 60133e662..a02c7c4bc 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -152,6 +152,9 @@ func addDutch(i18nObject *i18n.Bundle) error { ID: "deleteBranch", Other: "verwijder branch", }, &i18n.Message{ + ID: "forceDeleteBranch", + Other: "verwijder branch (forceer)", + }, &i18n.Message{ ID: "NoBranchesThisRepo", Other: "Geen branches voor deze repo", }, &i18n.Message{ diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index bebe9b282..db51fcdc4 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -160,6 +160,9 @@ func addEnglish(i18nObject *i18n.Bundle) error { ID: "deleteBranch", Other: "delete branch", }, &i18n.Message{ + ID: "forceDeleteBranch", + Other: "delete branch (force)", + }, &i18n.Message{ ID: "NoBranchesThisRepo", Other: "No branches for this repo", }, &i18n.Message{ |