mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
Use DisabledReason when deleting branches is not possible
Two cases: trying to delete the currently checked-out branch, or deleting the upstream of a branch that doesn't have one.
This commit is contained in:
parent
7f9818cfa2
commit
75aed98c35
@ -468,7 +468,6 @@ func (self *BranchesController) forceDelete(branch *models.Branch) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *BranchesController) delete(branch *models.Branch) error {
|
func (self *BranchesController) delete(branch *models.Branch) error {
|
||||||
menuItems := []*types.MenuItem{}
|
|
||||||
checkedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef()
|
checkedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef()
|
||||||
|
|
||||||
localDeleteItem := &types.MenuItem{
|
localDeleteItem := &types.MenuItem{
|
||||||
@ -479,25 +478,18 @@ func (self *BranchesController) delete(branch *models.Branch) error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
if checkedOutBranch.Name == branch.Name {
|
if checkedOutBranch.Name == branch.Name {
|
||||||
localDeleteItem = &types.MenuItem{
|
localDeleteItem.DisabledReason = self.c.Tr.CantDeleteCheckOutBranch
|
||||||
Label: self.c.Tr.DeleteLocalBranch,
|
|
||||||
Key: 'c',
|
|
||||||
Tooltip: self.c.Tr.CantDeleteCheckOutBranch,
|
|
||||||
OnPress: func() error {
|
|
||||||
return self.c.ErrorMsg(self.c.Tr.CantDeleteCheckOutBranch)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
menuItems = append(menuItems, localDeleteItem)
|
|
||||||
|
|
||||||
if branch.IsTrackingRemote() && !branch.UpstreamGone {
|
remoteDeleteItem := &types.MenuItem{
|
||||||
menuItems = append(menuItems, &types.MenuItem{
|
Label: self.c.Tr.DeleteRemoteBranch,
|
||||||
Label: self.c.Tr.DeleteRemoteBranch,
|
Key: 'r',
|
||||||
Key: 'r',
|
OnPress: func() error {
|
||||||
OnPress: func() error {
|
return self.remoteDelete(branch)
|
||||||
return self.remoteDelete(branch)
|
},
|
||||||
},
|
}
|
||||||
})
|
if !branch.IsTrackingRemote() || branch.UpstreamGone {
|
||||||
|
remoteDeleteItem.DisabledReason = self.c.Tr.UpstreamNotSetError
|
||||||
}
|
}
|
||||||
|
|
||||||
menuTitle := utils.ResolvePlaceholderString(
|
menuTitle := utils.ResolvePlaceholderString(
|
||||||
@ -509,7 +501,7 @@ func (self *BranchesController) delete(branch *models.Branch) error {
|
|||||||
|
|
||||||
return self.c.Menu(types.CreateMenuOptions{
|
return self.c.Menu(types.CreateMenuOptions{
|
||||||
Title: menuTitle,
|
Title: menuTitle,
|
||||||
Items: menuItems,
|
Items: []*types.MenuItem{localDeleteItem, remoteDeleteItem},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user