Skip to content

Commit e987d4b

Browse files
committed
Swap position of checkout-commit and checkout-branch menu items
Jesse's comment from #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 #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.
1 parent 1909545 commit e987d4b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

pkg/gui/controllers/helpers/refs_helper.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,17 @@ func (self *RefsHelper) CreateCheckoutMenu(commit *models.Commit) error {
278278
})
279279

280280
hash := commit.Hash
281-
var menuItems []*types.MenuItem
281+
282+
menuItems := []*types.MenuItem{
283+
{
284+
LabelColumns: []string{fmt.Sprintf(self.c.Tr.Actions.CheckoutCommitAsDetachedHead, utils.ShortHash(hash))},
285+
OnPress: func() error {
286+
self.c.LogAction(self.c.Tr.Actions.CheckoutCommit)
287+
return self.CheckoutRef(hash, types.CheckoutRefOptions{})
288+
},
289+
Key: 'd',
290+
},
291+
}
282292

283293
if len(branches) > 0 {
284294
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 {
304314
})
305315
}
306316

307-
menuItems = append(menuItems, &types.MenuItem{
308-
LabelColumns: []string{fmt.Sprintf(self.c.Tr.Actions.CheckoutCommitAsDetachedHead, utils.ShortHash(hash))},
309-
OnPress: func() error {
310-
self.c.LogAction(self.c.Tr.Actions.CheckoutCommit)
311-
return self.CheckoutRef(hash, types.CheckoutRefOptions{})
312-
},
313-
Key: 'd',
314-
})
315-
316317
return self.c.Menu(types.CreateMenuOptions{
317318
Title: self.c.Tr.Actions.CheckoutBranchOrCommit,
318319
Items: menuItems,

pkg/integration/tests/commit/checkout.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ var Checkout = NewIntegrationTest(NewIntegrationTestArgs{
3232
t.ExpectPopup().Menu().
3333
Title(Contains("Checkout branch or commit")).
3434
Lines(
35-
Contains("Checkout branch").IsSelected(),
36-
MatchesRegexp("Checkout commit [a-f0-9]+ as detached head"),
35+
MatchesRegexp("Checkout commit [a-f0-9]+ as detached head").IsSelected(),
36+
Contains("Checkout branch"),
3737
Contains("Cancel"),
3838
).
39+
Select(Contains("Checkout branch")).
3940
Tooltip(Contains("Disabled: No branches found at selected commit.")).
4041
Select(MatchesRegexp("Checkout commit [a-f0-9]+ as detached head")).
4142
Confirm()
@@ -53,9 +54,9 @@ var Checkout = NewIntegrationTest(NewIntegrationTestArgs{
5354
t.ExpectPopup().Menu().
5455
Title(Contains("Checkout branch or commit")).
5556
Lines(
56-
Contains("Checkout branch 'branch1'").IsSelected(),
57+
MatchesRegexp("Checkout commit [a-f0-9]+ as detached head").IsSelected(),
58+
Contains("Checkout branch 'branch1'"),
5759
Contains("Checkout branch 'master'"),
58-
MatchesRegexp("Checkout commit [a-f0-9]+ as detached head"),
5960
Contains("Cancel"),
6061
).
6162
Select(Contains("Checkout branch 'master'")).

0 commit comments

Comments
 (0)