diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index 39cda5bd493..1976bf3867d 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -61,6 +61,10 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions return self.c.WithWaitingStatus(waitingStatus, f) } + // Switch to the branches context _before_ starting to check out the branch, so that we see the + // inline status. This is a no-op if the branches panel is already focused. + self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{}) + return withCheckoutStatus(func(gocui.Task) error { if err := self.c.Git().Branch.Checkout(ref, cmdOptions); err != nil { // 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 @@ -109,11 +113,6 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions // Shows a prompt to choose between creating a new branch or checking out a detached head func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchName string) error { checkout := func(branchName string) error { - // Switch to the branches context _before_ starting to check out the - // branch, so that we see the inline status - if self.c.Context().Current() != self.c.Contexts().Branches { - self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{}) - } return self.CheckoutRef(branchName, types.CheckoutRefOptions{}) } diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go index c6fa60bd2cb..c8a02df874f 100644 --- a/pkg/gui/controllers/tags_controller.go +++ b/pkg/gui/controllers/tags_controller.go @@ -155,7 +155,6 @@ func (self *TagsController) checkout(tag *models.Tag) error { if err := self.c.Helpers().Refs.CheckoutRef(tag.FullRefName(), types.CheckoutRefOptions{}); err != nil { return err } - self.c.Context().Push(self.c.Contexts().Branches, types.OnFocusOpts{}) return nil } diff --git a/pkg/integration/tests/commit/checkout.go b/pkg/integration/tests/commit/checkout.go index ddd20c4ec98..688207372ff 100644 --- a/pkg/integration/tests/commit/checkout.go +++ b/pkg/integration/tests/commit/checkout.go @@ -42,14 +42,17 @@ var Checkout = NewIntegrationTest(NewIntegrationTestArgs{ Tooltip(Contains("Disabled: No branches found at selected commit.")). Select(MatchesRegexp("Checkout commit [a-f0-9]+ as detached head")). Confirm() - t.Views().Branches().Lines( - Contains("* (HEAD detached at"), - Contains("branch1"), - Contains("branch2"), - Contains("master"), - ) + t.Views().Branches(). + IsFocused(). + Lines( + Contains("* (HEAD detached at").IsSelected(), + Contains("branch1"), + Contains("branch2"), + Contains("master"), + ) t.Views().Commits(). + Focus(). NavigateToLine(Contains("two")). PressPrimaryAction() @@ -63,10 +66,12 @@ var Checkout = NewIntegrationTest(NewIntegrationTestArgs{ ). Select(Contains("Checkout branch 'master'")). Confirm() - t.Views().Branches().Lines( - Contains("master"), - Contains("branch1"), - Contains("branch2"), - ) + t.Views().Branches(). + IsFocused(). + Lines( + Contains("master").IsSelected(), + Contains("branch1"), + Contains("branch2"), + ) }, }) diff --git a/pkg/integration/tests/undo/undo_checkout_and_drop.go b/pkg/integration/tests/undo/undo_checkout_and_drop.go index 6c095b029d1..cccf0c8d85e 100644 --- a/pkg/integration/tests/undo/undo_checkout_and_drop.go +++ b/pkg/integration/tests/undo/undo_checkout_and_drop.go @@ -102,11 +102,13 @@ var UndoCheckoutAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ Confirm() t.Views().Branches(). + IsFocused(). Lines( Contains("master").IsSelected(), Contains("other_branch"), ) }). + Focus(). Lines( Contains("three").IsSelected(), Contains("two"), @@ -135,11 +137,13 @@ var UndoCheckoutAndDrop = NewIntegrationTest(NewIntegrationTestArgs{ Confirm() t.Views().Branches(). + IsFocused(). Lines( Contains("other_branch").IsSelected(), Contains("master"), ) }). + Focus(). Press(keys.Universal.Redo). Tap(confirmRedoDrop). Lines(