1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

Disallow pulling/pushing a branch while the branch is pushed or pulled

This commit is contained in:
Stefan Haller
2023-09-25 21:34:10 +02:00
parent fd9d7cb7bb
commit 67d6447e12
2 changed files with 22 additions and 6 deletions

View File

@ -31,14 +31,16 @@ func NewSyncController(
func (self *SyncController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { func (self *SyncController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
bindings := []*types.Binding{ bindings := []*types.Binding{
{ {
Key: opts.GetKey(opts.Config.Universal.Push), Key: opts.GetKey(opts.Config.Universal.Push),
Handler: opts.Guards.NoPopupPanel(self.HandlePush), Handler: opts.Guards.NoPopupPanel(self.HandlePush),
Description: self.c.Tr.Push, GetDisabledReason: self.getDisabledReasonForPushOrPull,
Description: self.c.Tr.Push,
}, },
{ {
Key: opts.GetKey(opts.Config.Universal.Pull), Key: opts.GetKey(opts.Config.Universal.Pull),
Handler: opts.Guards.NoPopupPanel(self.HandlePull), Handler: opts.Guards.NoPopupPanel(self.HandlePull),
Description: self.c.Tr.Pull, GetDisabledReason: self.getDisabledReasonForPushOrPull,
Description: self.c.Tr.Pull,
}, },
} }
@ -57,6 +59,18 @@ func (self *SyncController) HandlePull() error {
return self.branchCheckedOut(self.pull)() return self.branchCheckedOut(self.pull)()
} }
func (self *SyncController) getDisabledReasonForPushOrPull() string {
currentBranch := self.c.Helpers().Refs.GetCheckedOutRef()
if currentBranch != nil {
op := self.c.State().GetItemOperation(currentBranch)
if op != types.ItemOperationNone {
return self.c.Tr.CantPullOrPushSameBranchTwice
}
}
return ""
}
func (self *SyncController) branchCheckedOut(f func(*models.Branch) error) func() error { func (self *SyncController) branchCheckedOut(f func(*models.Branch) error) func() error {
return func() error { return func() error {
currentBranch := self.c.Helpers().Refs.GetCheckedOutRef() currentBranch := self.c.Helpers().Refs.GetCheckedOutRef()

View File

@ -58,6 +58,7 @@ type TranslationSet struct {
MergeConflictsTitle string MergeConflictsTitle string
Checkout string Checkout string
CantCheckoutBranchWhilePulling string CantCheckoutBranchWhilePulling string
CantPullOrPushSameBranchTwice string
NoChangedFiles string NoChangedFiles string
SoftReset string SoftReset string
AlreadyCheckedOutBranch string AlreadyCheckedOutBranch string
@ -848,6 +849,7 @@ func EnglishTranslationSet() TranslationSet {
MergeConflictsTitle: "Merge conflicts", MergeConflictsTitle: "Merge conflicts",
Checkout: "Checkout", Checkout: "Checkout",
CantCheckoutBranchWhilePulling: "You cannot checkout another branch while pulling the current branch", CantCheckoutBranchWhilePulling: "You cannot checkout another branch while pulling the current branch",
CantPullOrPushSameBranchTwice: "You cannot push or pull a branch while it is already being pushed or pulled",
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",