@@ -14,25 +14,31 @@ import (
14
14
15
15
type BisectController struct {
16
16
baseController
17
+ * ListControllerTrait [* models.Commit ]
17
18
c * ControllerCommon
18
19
}
19
20
20
21
var _ types.IController = & BisectController {}
21
22
22
23
func NewBisectController (
23
- common * ControllerCommon ,
24
+ c * ControllerCommon ,
24
25
) * BisectController {
25
26
return & BisectController {
26
27
baseController : baseController {},
27
- c : common ,
28
+ c : c ,
29
+ ListControllerTrait : NewListControllerTrait [* models.Commit ](
30
+ c ,
31
+ c .Contexts ().LocalCommits ,
32
+ c .Contexts ().LocalCommits .GetSelected ,
33
+ ),
28
34
}
29
35
}
30
36
31
37
func (self * BisectController ) GetKeybindings (opts types.KeybindingsOpts ) []* types.Binding {
32
38
bindings := []* types.Binding {
33
39
{
34
40
Key : opts .GetKey (opts .Config .Commits .ViewBisectOptions ),
35
- Handler : opts .Guards .OutsideFilterMode (self .checkSelected (self .openMenu )),
41
+ Handler : opts .Guards .OutsideFilterMode (self .withItem (self .openMenu )),
36
42
Description : self .c .Tr .ViewBisectOptions ,
37
43
OpensMenu : true ,
38
44
},
@@ -70,9 +76,19 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
70
76
// If we have a current sha already, then we always want to use that one. If
71
77
// not, we're still picking the initial commits before we really start, so
72
78
// use the selected commit in that case.
73
- shaToMark := lo .Ternary (info .GetCurrentSha () != "" , info .GetCurrentSha (), commit .Sha )
79
+
80
+ bisecting := info .GetCurrentSha () != ""
81
+ shaToMark := lo .Ternary (bisecting , info .GetCurrentSha (), commit .Sha )
74
82
shortShaToMark := utils .ShortSha (shaToMark )
75
83
84
+ // For marking a commit as bad, when we're not already bisecting, we require
85
+ // a single item selected, but once we are bisecting, it doesn't matter because
86
+ // the action applies to the HEAD commit rather than the selected commit.
87
+ var singleItemIfNotBisecting * types.DisabledReason
88
+ if ! bisecting {
89
+ singleItemIfNotBisecting = self .require (self .singleItemSelected ())()
90
+ }
91
+
76
92
menuItems := []* types.MenuItem {
77
93
{
78
94
Label : fmt .Sprintf (self .c .Tr .Bisect .Mark , shortShaToMark , info .NewTerm ()),
@@ -84,7 +100,8 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
84
100
85
101
return self .afterMark (selectCurrentAfter , waitToReselect )
86
102
},
87
- Key : 'b' ,
103
+ DisabledReason : singleItemIfNotBisecting ,
104
+ Key : 'b' ,
88
105
},
89
106
{
90
107
Label : fmt .Sprintf (self .c .Tr .Bisect .Mark , shortShaToMark , info .OldTerm ()),
@@ -96,7 +113,8 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
96
113
97
114
return self .afterMark (selectCurrentAfter , waitToReselect )
98
115
},
99
- Key : 'g' ,
116
+ DisabledReason : singleItemIfNotBisecting ,
117
+ Key : 'g' ,
100
118
},
101
119
{
102
120
Label : fmt .Sprintf (self .c .Tr .Bisect .SkipCurrent , shortShaToMark ),
@@ -108,7 +126,8 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
108
126
109
127
return self .afterMark (selectCurrentAfter , waitToReselect )
110
128
},
111
- Key : 's' ,
129
+ DisabledReason : singleItemIfNotBisecting ,
130
+ Key : 's' ,
112
131
},
113
132
}
114
133
if info .GetCurrentSha () != "" && info .GetCurrentSha () != commit .Sha {
@@ -122,7 +141,8 @@ func (self *BisectController) openMidBisectMenu(info *git_commands.BisectInfo, c
122
141
123
142
return self .afterMark (selectCurrentAfter , waitToReselect )
124
143
},
125
- Key : 'S' ,
144
+ DisabledReason : self .require (self .singleItemSelected ())(),
145
+ Key : 'S' ,
126
146
}))
127
147
}
128
148
menuItems = append (menuItems , lo .ToPtr (types.MenuItem {
@@ -157,7 +177,8 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
157
177
158
178
return self .c .Helpers ().Bisect .PostBisectCommandRefresh ()
159
179
},
160
- Key : 'b' ,
180
+ DisabledReason : self .require (self .singleItemSelected ())(),
181
+ Key : 'b' ,
161
182
},
162
183
{
163
184
Label : fmt .Sprintf (self .c .Tr .Bisect .MarkStart , commit .ShortSha (), info .OldTerm ()),
@@ -173,7 +194,8 @@ func (self *BisectController) openStartBisectMenu(info *git_commands.BisectInfo,
173
194
174
195
return self .c .Helpers ().Bisect .PostBisectCommandRefresh ()
175
196
},
176
- Key : 'g' ,
197
+ DisabledReason : self .require (self .singleItemSelected ())(),
198
+ Key : 'g' ,
177
199
},
178
200
{
179
201
Label : self .c .Tr .Bisect .ChooseTerms ,
@@ -273,21 +295,6 @@ func (self *BisectController) selectCurrentBisectCommit() {
273
295
}
274
296
}
275
297
276
- func (self * BisectController ) checkSelected (callback func (* models.Commit ) error ) func () error {
277
- return func () error {
278
- commit := self .context ().GetSelected ()
279
- if commit == nil {
280
- return nil
281
- }
282
-
283
- return callback (commit )
284
- }
285
- }
286
-
287
- func (self * BisectController ) Context () types.Context {
288
- return self .context ()
289
- }
290
-
291
298
func (self * BisectController ) context () * context.LocalCommitsContext {
292
299
return self .c .Contexts ().LocalCommits
293
300
}
0 commit comments