diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-21 23:45:27 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-21 23:45:27 +1000 |
commit | 4d635cd1cd7ed1a32e516d3d93a0449d3c3a130e (patch) | |
tree | 8c3179aae788d168cb9b3929618117dbaad050f6 /pkg | |
parent | 3d49ab666676ede1b3c849d56ccd2099a7701709 (diff) | |
parent | 182e47511626fb01e05b2abcaa589604648959d5 (diff) |
Merge pull request #151 from alcohol/force-delete-branch
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 | 21 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 1 | ||||
-rw-r--r-- | pkg/i18n/dutch.go | 8 | ||||
-rw-r--r-- | pkg/i18n/english.go | 8 |
5 files changed, 41 insertions, 7 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index bf9aa6646..ed42ae28c 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..df4dcff78 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -62,20 +62,34 @@ func (gui *Gui) handleNewBranch(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleDeleteBranch(g *gocui.Gui, v *gocui.View) error { + return gui.deleteBranch(g, v, false) +} + +func (gui *Gui) handleForceDeleteBranch(g *gocui.Gui, v *gocui.View) error { + return 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") + var messageId string + if force { + messageId = "ForceDeleteBranchMessage" + } else { + messageId = "DeleteBranchMessage" + } message := gui.Tr.TemplateLocalize( - "DeleteBranchMessage", + messageId, 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 +122,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..a5bf897b5 100644 --- a/pkg/i18n/dutch.go +++ b/pkg/i18n/dutch.go @@ -132,7 +132,10 @@ func addDutch(i18nObject *i18n.Bundle) error { Other: "Verwijder branch", }, &i18n.Message{ ID: "DeleteBranchMessage", - Other: "Weet je zeker dat je {{.selectedBranchName}} branch wil verwijderen?", + Other: "Weet je zeker dat je branch {{.selectedBranchName}} wil verwijderen?", + }, &i18n.Message{ + ID: "DeleteBranchMessage", + Other: "Weet je zeker dat je branch {{.selectedBranchName}} geforceerd wil verwijderen?", }, &i18n.Message{ ID: "CantMergeBranchIntoItself", Other: "Je kan niet een branch in zichzelf mergen", @@ -152,6 +155,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 c0384136b..2269ffb9f 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -140,7 +140,10 @@ func addEnglish(i18nObject *i18n.Bundle) error { Other: "Delete Branch", }, &i18n.Message{ ID: "DeleteBranchMessage", - Other: "Are you sure you want delete the branch {{.selectedBranchName}} ?", + Other: "Are you sure you want to delete the branch {{.selectedBranchName}} ?", + }, &i18n.Message{ + ID: "ForceDeleteBranchMessage", + Other: "Are you sure you want to force delete the branch {{.selectedBranchName}} ?", }, &i18n.Message{ ID: "CantMergeBranchIntoItself", Other: "You cannot merge a branch into itself", @@ -160,6 +163,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{ |