Skip to content

Commit 5946796

Browse files
committed
Show inline waiting status when checking out a local branch
1 parent ad1961c commit 5946796

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

pkg/gui/controllers/helpers/refs_helper.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/jesseduffield/gocui"
88
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
99
"github.com/jesseduffield/lazygit/pkg/commands/models"
10+
"github.com/jesseduffield/lazygit/pkg/gui/context"
1011
"github.com/jesseduffield/lazygit/pkg/gui/style"
1112
"github.com/jesseduffield/lazygit/pkg/gui/types"
1213
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -53,7 +54,7 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
5354

5455
refreshOptions := types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true}
5556

56-
return self.c.WithWaitingStatus(waitingStatus, func(gocui.Task) error {
57+
f := func(gocui.Task) error {
5758
if err := self.c.Git().Branch.Checkout(ref, cmdOptions); err != nil {
5859
// note, this will only work for english-language git commands. If we force git to use english, and the error isn't this one, then the user will receive an english command they may not understand. I'm not sure what the best solution to this is. Running the command once in english and a second time in the native language is one option
5960

@@ -93,19 +94,29 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
9394
onSuccess()
9495

9596
return self.c.Refresh(refreshOptions)
97+
}
98+
99+
localBranch, found := lo.Find(self.c.Model().Branches, func(branch *models.Branch) bool {
100+
return branch.Name == ref
96101
})
102+
if found {
103+
return self.c.WithInlineStatus(localBranch, types.ItemOperationCheckingOut, context.LOCAL_BRANCHES_CONTEXT_KEY, f)
104+
} else {
105+
return self.c.WithWaitingStatus(waitingStatus, f)
106+
}
97107
}
98108

99109
// Shows a prompt to choose between creating a new branch or checking out a detached head
100110
func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchName string) error {
101111
checkout := func(branchName string) error {
102-
if err := self.CheckoutRef(branchName, types.CheckoutRefOptions{}); err != nil {
103-
return err
104-
}
112+
// Switch to the branches context _before_ starting to check out the
113+
// branch, so that we see the inline status
105114
if self.c.CurrentContext() != self.c.Contexts().Branches {
106-
return self.c.PushContext(self.c.Contexts().Branches)
115+
if err := self.c.PushContext(self.c.Contexts().Branches); err != nil {
116+
return err
117+
}
107118
}
108-
return nil
119+
return self.CheckoutRef(branchName, types.CheckoutRefOptions{})
109120
}
110121

111122
// If a branch with this name already exists locally, just check it out. We

pkg/gui/presentation/item_operations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func ItemOperationToString(itemOperation types.ItemOperation, tr *i18n.Translati
1919
return tr.DeletingStatus
2020
case types.ItemOperationFetching:
2121
return tr.FetchingStatus
22+
case types.ItemOperationCheckingOut:
23+
return tr.CheckingOutStatus
2224
}
2325

2426
return ""

pkg/gui/types/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ const (
309309
ItemOperationFastForwarding
310310
ItemOperationDeleting
311311
ItemOperationFetching
312+
ItemOperationCheckingOut
312313
)
313314

314315
type HasUrn interface {

0 commit comments

Comments
 (0)