From e987d4b519af6f55edb4ef5ff30d6991abe521c1 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 6 Feb 2025 14:27:25 +0100 Subject: [PATCH] Swap position of checkout-commit and checkout-branch menu items Jesse's comment from https://github.com/jesseduffield/lazygit/issues/4237: We recently added a new option to check out a commit's branch from within the commits, reflog, and sub-commits panels: https://github.com/user-attachments/assets/0a5cf3f2-6803-4709-ae5a-e4addc061012 After using it for some time, I find it annoying that the default option has changed. I rarely find myself wanting to check out a branch from the commits panel, and it's rarer still to want to check out a branch from the reflog and sub-commits panel. Although there may be use cases for this, it is jarring that something you can always do (checkout the commit) is harder to do than something that you can sometimes do (checkout the branch). We've also had a user complain (see https://github.com/jesseduffield/lazygit/pull/4117) about their muscle-memory being broken by the recent change, and I have also fallen victim to this. I don't think that the new branch checkout option is sufficiently useful to dislodge the existing keybinding, so let's swap them. --- pkg/gui/controllers/helpers/refs_helper.go | 21 +++++++++++---------- pkg/integration/tests/commit/checkout.go | 9 +++++---- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index 1aa4d8dc3..02af116b5 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -278,7 +278,17 @@ func (self *RefsHelper) CreateCheckoutMenu(commit *models.Commit) error { }) hash := commit.Hash - var menuItems []*types.MenuItem + + menuItems := []*types.MenuItem{ + { + LabelColumns: []string{fmt.Sprintf(self.c.Tr.Actions.CheckoutCommitAsDetachedHead, utils.ShortHash(hash))}, + OnPress: func() error { + self.c.LogAction(self.c.Tr.Actions.CheckoutCommit) + return self.CheckoutRef(hash, types.CheckoutRefOptions{}) + }, + Key: 'd', + }, + } if len(branches) > 0 { menuItems = append(menuItems, lo.Map(branches, func(branch *models.Branch, index int) *types.MenuItem { @@ -304,15 +314,6 @@ func (self *RefsHelper) CreateCheckoutMenu(commit *models.Commit) error { }) } - menuItems = append(menuItems, &types.MenuItem{ - LabelColumns: []string{fmt.Sprintf(self.c.Tr.Actions.CheckoutCommitAsDetachedHead, utils.ShortHash(hash))}, - OnPress: func() error { - self.c.LogAction(self.c.Tr.Actions.CheckoutCommit) - return self.CheckoutRef(hash, types.CheckoutRefOptions{}) - }, - Key: 'd', - }) - return self.c.Menu(types.CreateMenuOptions{ Title: self.c.Tr.Actions.CheckoutBranchOrCommit, Items: menuItems, diff --git a/pkg/integration/tests/commit/checkout.go b/pkg/integration/tests/commit/checkout.go index 455aa273c..7815e89de 100644 --- a/pkg/integration/tests/commit/checkout.go +++ b/pkg/integration/tests/commit/checkout.go @@ -32,10 +32,11 @@ var Checkout = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectPopup().Menu(). Title(Contains("Checkout branch or commit")). Lines( - Contains("Checkout branch").IsSelected(), - MatchesRegexp("Checkout commit [a-f0-9]+ as detached head"), + MatchesRegexp("Checkout commit [a-f0-9]+ as detached head").IsSelected(), + Contains("Checkout branch"), Contains("Cancel"), ). + Select(Contains("Checkout branch")). Tooltip(Contains("Disabled: No branches found at selected commit.")). Select(MatchesRegexp("Checkout commit [a-f0-9]+ as detached head")). Confirm() @@ -53,9 +54,9 @@ var Checkout = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectPopup().Menu(). Title(Contains("Checkout branch or commit")). Lines( - Contains("Checkout branch 'branch1'").IsSelected(), + MatchesRegexp("Checkout commit [a-f0-9]+ as detached head").IsSelected(), + Contains("Checkout branch 'branch1'"), Contains("Checkout branch 'master'"), - MatchesRegexp("Checkout commit [a-f0-9]+ as detached head"), Contains("Cancel"), ). Select(Contains("Checkout branch 'master'")).