Repository: jesseduffield/lazygit (language: go)

Issue:
Swap position of checkout-commit and checkout-branch menu items
We recently added a new option to check out a commit's branch from within the commits, reflog, and sub-commits panels:

![Image](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](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.


Discussion / hints:

Fix patch:
diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go
index 1aa4d8dc3a2..02af116b54e 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,


Test patch:
diff --git a/pkg/integration/tests/commit/checkout.go b/pkg/integration/tests/commit/checkout.go
index 455aa273ca3..7815e89de38 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'")).