mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-20 05:19:24 +02:00
Merge pull request #151 from alcohol/force-delete-branch
add option to force delete given branch
This commit is contained in:
commit
4d635cd1cd
@ -44,6 +44,7 @@
|
||||
<kbd>c</kbd>: checkout by name
|
||||
<kbd>n</kbd>: new branch
|
||||
<kbd>d</kbd>: delete branch
|
||||
<kbd>D</kbd>: force delete branch
|
||||
</pre>
|
||||
|
||||
## Commits Panel:
|
||||
|
@ -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
|
||||
|
@ -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"),
|
||||
})
|
||||
}
|
||||
|
@ -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},
|
||||
|
@ -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",
|
||||
@ -151,6 +154,9 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
||||
}, &i18n.Message{
|
||||
ID: "deleteBranch",
|
||||
Other: "verwijder branch",
|
||||
}, &i18n.Message{
|
||||
ID: "forceDeleteBranch",
|
||||
Other: "verwijder branch (forceer)",
|
||||
}, &i18n.Message{
|
||||
ID: "NoBranchesThisRepo",
|
||||
Other: "Geen branches voor deze repo",
|
||||
|
@ -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",
|
||||
@ -159,6 +162,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
||||
}, &i18n.Message{
|
||||
ID: "deleteBranch",
|
||||
Other: "delete branch",
|
||||
}, &i18n.Message{
|
||||
ID: "forceDeleteBranch",
|
||||
Other: "delete branch (force)",
|
||||
}, &i18n.Message{
|
||||
ID: "NoBranchesThisRepo",
|
||||
Other: "No branches for this repo",
|
||||
|
Loading…
x
Reference in New Issue
Block a user