Skip to content

Commit 52447e5

Browse files
authored
When bisecting, always mark the current commit as good/bad, not the selected (#2837)
2 parents a4772ae + 6794149 commit 52447e5

File tree

9 files changed

+132
-19
lines changed

9 files changed

+132
-19
lines changed

pkg/gui/controllers/bisect_controller.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"github.com/jesseduffield/lazygit/pkg/commands/models"
99
"github.com/jesseduffield/lazygit/pkg/gui/context"
1010
"github.com/jesseduffield/lazygit/pkg/gui/types"
11+
"github.com/jesseduffield/lazygit/pkg/utils"
12+
"github.com/samber/lo"
1113
)
1214

1315
type BisectController struct {
@@ -65,12 +67,18 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
6567
// ref, because we'll be reloading our commits in that case.
6668
waitToReselect := selectCurrentAfter && !self.c.Git().Bisect.ReachableFromStart(info)
6769

70+
// If we have a current sha already, then we always want to use that one. If
71+
// not, we're still picking the initial commits before we really start, so
72+
// use the selected commit in that case.
73+
shaToMark := lo.Ternary(info.GetCurrentSha() != "", info.GetCurrentSha(), commit.Sha)
74+
shortShaToMark := utils.ShortSha(shaToMark)
75+
6876
menuItems := []*types.MenuItem{
6977
{
70-
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.NewTerm()),
78+
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortShaToMark, info.NewTerm()),
7179
OnPress: func() error {
7280
self.c.LogAction(self.c.Tr.Actions.BisectMark)
73-
if err := self.c.Git().Bisect.Mark(commit.Sha, info.NewTerm()); err != nil {
81+
if err := self.c.Git().Bisect.Mark(shaToMark, info.NewTerm()); err != nil {
7482
return self.c.Error(err)
7583
}
7684

@@ -79,10 +87,10 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
7987
Key: 'b',
8088
},
8189
{
82-
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, commit.ShortSha(), info.OldTerm()),
90+
Label: fmt.Sprintf(self.c.Tr.Bisect.Mark, shortShaToMark, info.OldTerm()),
8391
OnPress: func() error {
8492
self.c.LogAction(self.c.Tr.Actions.BisectMark)
85-
if err := self.c.Git().Bisect.Mark(commit.Sha, info.OldTerm()); err != nil {
93+
if err := self.c.Git().Bisect.Mark(shaToMark, info.OldTerm()); err != nil {
8694
return self.c.Error(err)
8795
}
8896

@@ -91,25 +99,39 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
9199
Key: 'g',
92100
},
93101
{
94-
Label: fmt.Sprintf(self.c.Tr.Bisect.Skip, commit.ShortSha()),
102+
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipCurrent, shortShaToMark),
95103
OnPress: func() error {
96104
self.c.LogAction(self.c.Tr.Actions.BisectSkip)
97-
if err := self.c.Git().Bisect.Skip(commit.Sha); err != nil {
105+
if err := self.c.Git().Bisect.Skip(shaToMark); err != nil {
98106
return self.c.Error(err)
99107
}
100108

101109
return self.afterMark(selectCurrentAfter, waitToReselect)
102110
},
103111
Key: 's',
104112
},
105-
{
106-
Label: self.c.Tr.Bisect.ResetOption,
113+
}
114+
if info.GetCurrentSha() != "" && info.GetCurrentSha() != commit.Sha {
115+
menuItems = append(menuItems, lo.ToPtr(types.MenuItem{
116+
Label: fmt.Sprintf(self.c.Tr.Bisect.SkipSelected, commit.ShortSha()),
107117
OnPress: func() error {
108-
return self.c.Helpers().Bisect.Reset()
118+
self.c.LogAction(self.c.Tr.Actions.BisectSkip)
119+
if err := self.c.Git().Bisect.Skip(commit.Sha); err != nil {
120+
return self.c.Error(err)
121+
}
122+
123+
return self.afterMark(selectCurrentAfter, waitToReselect)
109124
},
110-
Key: 'r',
111-
},
125+
Key: 'S',
126+
}))
112127
}
128+
menuItems = append(menuItems, lo.ToPtr(types.MenuItem{
129+
Label: self.c.Tr.Bisect.ResetOption,
130+
OnPress: func() error {
131+
return self.c.Helpers().Bisect.Reset()
132+
},
133+
Key: 'r',
134+
}))
113135

114136
return self.c.Menu(types.CreateMenuOptions{
115137
Title: self.c.Tr.Bisect.BisectMenuTitle,

pkg/i18n/chinese.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ func chineseTranslationSet() TranslationSet {
544544
Bisect: Bisect{
545545
Mark: "将 %s 标记为 %s",
546546
MarkStart: "将 %s 标记为 %s (start bisect)",
547-
Skip: "跳过 %s",
547+
SkipCurrent: "跳过 %s",
548548
ResetTitle: "重置 'git bisect'",
549549
ResetPrompt: "您确定要重置 'git bisect' 吗?",
550550
ResetOption: "重置二分查找",

pkg/i18n/english.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,8 @@ type Bisect struct {
557557
NewTermPrompt string
558558
BisectMenuTitle string
559559
Mark string
560-
Skip string
560+
SkipCurrent string
561+
SkipSelected string
561562
CompleteTitle string
562563
CompletePrompt string
563564
CompletePromptIndeterminate string
@@ -1347,9 +1348,10 @@ func EnglishTranslationSet() TranslationSet {
13471348
BisectMark: "Bisect mark",
13481349
},
13491350
Bisect: Bisect{
1350-
Mark: "Mark %s as %s",
1351+
Mark: "Mark current commit (%s) as %s",
13511352
MarkStart: "Mark %s as %s (start bisect)",
1352-
Skip: "Skip %s",
1353+
SkipCurrent: "Skip current commit (%s)",
1354+
SkipSelected: "Skip selected commit (%s)",
13531355
ResetTitle: "Reset 'git bisect'",
13541356
ResetPrompt: "Are you sure you want to reset 'git bisect'?",
13551357
ResetOption: "Reset bisect",

pkg/i18n/japanese.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ func japaneseTranslationSet() TranslationSet {
577577
Bisect: Bisect{
578578
// Mark: "Mark %s as %s",
579579
// MarkStart: "Mark %s as %s (start bisect)",
580-
Skip: "%s をスキップする",
580+
SkipCurrent: "%s をスキップする",
581581
ResetTitle: "'git bisect' をリセット",
582582
ResetPrompt: "'git bisect' をリセットします。よろしいですか?",
583583
ResetOption: "Bisectをリセット",

pkg/i18n/korean.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ func koreanTranslationSet() TranslationSet {
576576
Bisect: Bisect{
577577
Mark: "Mark %s as %s",
578578
MarkStart: "Mark %s as %s (start bisect)",
579-
Skip: "%s 를 스킵",
579+
SkipCurrent: "%s 를 스킵",
580580
ResetTitle: "'git bisect' 를 리셋",
581581
ResetPrompt: "정말로 'git bisect' 를 리셋하시겠습니까?",
582582
ResetOption: "Bisect를 리셋",

pkg/i18n/russian.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ func RussianTranslationSet() TranslationSet {
671671
Bisect: Bisect{
672672
Mark: "Отметить %s как %s",
673673
MarkStart: "Отметить %s как %s (начать бинарный поиск)",
674-
Skip: "Пропустить %s",
674+
SkipCurrent: "Пропустить %s",
675675
ResetTitle: "Сбросить 'git bisect'",
676676
ResetPrompt: "Вы уверены, что хотите сбросить 'git bisect'?",
677677
ResetOption: "Сбросить бинарный поиск",

pkg/i18n/traditional_chinese.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ func traditionalChineseTranslationSet() TranslationSet {
698698
Bisect: Bisect{
699699
Mark: "將 %s 標記為 %s",
700700
MarkStart: "將 %s 標記為 %s(開始二分查找)",
701-
Skip: "跳過 %s",
701+
SkipCurrent: "跳過 %s",
702702
ResetTitle: "重設 'git bisect'",
703703
ResetPrompt: "你確定要重設 'git bisect' 嗎?",
704704
ResetOption: "重設二分查找",

pkg/integration/tests/bisect/skip.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package bisect
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var Skip = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Start a git bisect and skip a few commits (selected or current)",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupRepo: func(shell *Shell) {
13+
shell.
14+
CreateNCommits(10)
15+
},
16+
SetupConfig: func(cfg *config.AppConfig) {},
17+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
18+
t.Views().Commits().
19+
Focus().
20+
SelectedLine(Contains("commit 10")).
21+
Press(keys.Commits.ViewBisectOptions).
22+
Tap(func() {
23+
t.ExpectPopup().Menu().Title(Equals("Bisect")).Select(MatchesRegexp(`Mark .* as bad`)).Confirm()
24+
}).
25+
NavigateToLine(Contains("commit 01")).
26+
Press(keys.Commits.ViewBisectOptions).
27+
Tap(func() {
28+
t.ExpectPopup().Menu().Title(Equals("Bisect")).Select(MatchesRegexp(`Mark .* as good`)).Confirm()
29+
t.Views().Information().Content(Contains("Bisecting"))
30+
}).
31+
Lines(
32+
Contains("CI commit 10").Contains("<-- bad"),
33+
Contains("CI commit 09").DoesNotContain("<--"),
34+
Contains("CI commit 08").DoesNotContain("<--"),
35+
Contains("CI commit 07").DoesNotContain("<--"),
36+
Contains("CI commit 06").DoesNotContain("<--"),
37+
Contains("CI commit 05").Contains("<-- current").IsSelected(),
38+
Contains("CI commit 04").DoesNotContain("<--"),
39+
Contains("CI commit 03").DoesNotContain("<--"),
40+
Contains("CI commit 02").DoesNotContain("<--"),
41+
Contains("CI commit 01").Contains("<-- good"),
42+
).
43+
Press(keys.Commits.ViewBisectOptions).
44+
Tap(func() {
45+
t.ExpectPopup().Menu().Title(Equals("Bisect")).
46+
// Does not show a "Skip selected commit" entry:
47+
Lines(
48+
Contains("b Mark current commit").Contains("as bad"),
49+
Contains("g Mark current commit").Contains("as good"),
50+
Contains("s Skip current commit"),
51+
Contains("r Reset bisect"),
52+
Contains("Cancel"),
53+
).
54+
Select(Contains("Skip current commit")).Confirm()
55+
}).
56+
// Skipping the current commit selects the new current commit:
57+
Lines(
58+
Contains("CI commit 10").Contains("<-- bad"),
59+
Contains("CI commit 09").DoesNotContain("<--"),
60+
Contains("CI commit 08").DoesNotContain("<--"),
61+
Contains("CI commit 07").DoesNotContain("<--"),
62+
Contains("CI commit 06").Contains("<-- current").IsSelected(),
63+
Contains("CI commit 05").Contains("<-- skipped"),
64+
Contains("CI commit 04").DoesNotContain("<--"),
65+
Contains("CI commit 03").DoesNotContain("<--"),
66+
Contains("CI commit 02").DoesNotContain("<--"),
67+
Contains("CI commit 01").Contains("<-- good"),
68+
).
69+
NavigateToLine(Contains("commit 07")).
70+
Press(keys.Commits.ViewBisectOptions).
71+
Tap(func() {
72+
t.ExpectPopup().Menu().Title(Equals("Bisect")).
73+
// Does show a "Skip selected commit" entry:
74+
Lines(
75+
Contains("b Mark current commit").Contains("as bad"),
76+
Contains("g Mark current commit").Contains("as good"),
77+
Contains("s Skip current commit"),
78+
Contains("S Skip selected commit"),
79+
Contains("r Reset bisect"),
80+
Contains("Cancel"),
81+
).
82+
Select(Contains("Skip selected commit")).Confirm()
83+
}).
84+
// Skipping a selected, non-current commit keeps the selection
85+
// there:
86+
SelectedLine(Contains("CI commit 07").Contains("<-- skipped"))
87+
},
88+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var tests = []*components.IntegrationTest{
3232
bisect.Basic,
3333
bisect.ChooseTerms,
3434
bisect.FromOtherBranch,
35+
bisect.Skip,
3536
branch.CheckoutByName,
3637
branch.CreateTag,
3738
branch.Delete,

0 commit comments

Comments
 (0)