Disallow checking out another branch while the current one is being pulled

This commit is contained in:
Stefan Haller 2023-09-25 21:36:01 +02:00
parent 3d6965ccbb
commit fd9d7cb7bb
2 changed files with 18 additions and 3 deletions

View file

@ -34,9 +34,10 @@ func NewBranchesController(
func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
return []*types.Binding{ return []*types.Binding{
{ {
Key: opts.GetKey(opts.Config.Universal.Select), Key: opts.GetKey(opts.Config.Universal.Select),
Handler: self.checkSelected(self.press), Handler: self.checkSelected(self.press),
Description: self.c.Tr.Checkout, GetDisabledReason: self.getDisabledReasonForPress,
Description: self.c.Tr.Checkout,
}, },
{ {
Key: opts.GetKey(opts.Config.Universal.New), Key: opts.GetKey(opts.Config.Universal.New),
@ -299,6 +300,18 @@ func (self *BranchesController) press(selectedBranch *models.Branch) error {
return self.c.Helpers().Refs.CheckoutRef(selectedBranch.Name, types.CheckoutRefOptions{}) return self.c.Helpers().Refs.CheckoutRef(selectedBranch.Name, types.CheckoutRefOptions{})
} }
func (self *BranchesController) getDisabledReasonForPress() string {
currentBranch := self.c.Helpers().Refs.GetCheckedOutRef()
if currentBranch != nil {
op := self.c.State().GetItemOperation(currentBranch)
if op == types.ItemOperationFastForwarding || op == types.ItemOperationPulling {
return self.c.Tr.CantCheckoutBranchWhilePulling
}
}
return ""
}
func (self *BranchesController) worktreeForBranch(branch *models.Branch) (*models.Worktree, bool) { func (self *BranchesController) worktreeForBranch(branch *models.Branch) (*models.Worktree, bool) {
return git_commands.WorktreeForBranch(branch, self.c.Model().Worktrees) return git_commands.WorktreeForBranch(branch, self.c.Model().Worktrees)
} }

View file

@ -57,6 +57,7 @@ type TranslationSet struct {
ResetFilter string ResetFilter string
MergeConflictsTitle string MergeConflictsTitle string
Checkout string Checkout string
CantCheckoutBranchWhilePulling string
NoChangedFiles string NoChangedFiles string
SoftReset string SoftReset string
AlreadyCheckedOutBranch string AlreadyCheckedOutBranch string
@ -846,6 +847,7 @@ func EnglishTranslationSet() TranslationSet {
Scroll: "Scroll", Scroll: "Scroll",
MergeConflictsTitle: "Merge conflicts", MergeConflictsTitle: "Merge conflicts",
Checkout: "Checkout", Checkout: "Checkout",
CantCheckoutBranchWhilePulling: "You cannot checkout another branch while pulling the current branch",
FileFilter: "Filter files by status", FileFilter: "Filter files by status",
FilterStagedFiles: "Show only staged files", FilterStagedFiles: "Show only staged files",
FilterUnstagedFiles: "Show only unstaged files", FilterUnstagedFiles: "Show only unstaged files",