Skip to content

Commit fe6a76a

Browse files
author
Chris McDonnell
committed
Split behavior of rendering allBranchesLogCmd and switching to next cmd
This now allows for leaving the status panel and returning back to the same command. When you have StatusPanelView = allBranchesLog, this means you can easily toggle back and forth to other views. When you have StatusPanelView = dashboard, the situation is a bit more complex. Previous behavior would _always_ rotate the index of the active allBranchesLogCmds in the background. Interestingly, it would do so in the background, so when you first pressed `a`, you would see the first item in your list, but the actual index being stored was that of your 2nd item. Now, we have flipped the order so that when you see the first item in your list, the actual index being stored is still `0`. The rotation then only happens when you click `a` for the 2nd time, and then you will see the 2nd item in your list. It is possible that some users were relying on the odd behavior. In that they might go: * Press `1` * Press `a` * See their first log command * Press `2` * Press `a` * See their second log command Now, their behavior would be: * Press `1` * Press `a` * See their first log command * Press `2` * Press `a` * See their first log command I think in most cases, this new behavior is preferable. It makes more sense that their first `a` click is a "switch views" directive, and their later clicks a "rotate through the commands". There is no way out of this without changing some behavior. If `a` _always_ rotates, then it _must_ rotate prior to rendering the view, otherwise users of allBranchesLog will see nothing happen on their first `a` press. If it rotates prior to rendering the view, then users of SatusPanelView = dashboard will see their 2nd list item on their first `a` click, which seems worse than this new behavior.
1 parent 5d30409 commit fe6a76a

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed

pkg/commands/git_commands/branch.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,16 +255,22 @@ func (self *BranchCommands) Merge(branchName string, opts MergeOpts) error {
255255
return self.cmd.New(cmdArgs).Run()
256256
}
257257

258+
// Only choose between non-empty, non-identical commands
259+
func (self *BranchCommands) allBranchesLogCandidates() []string {
260+
return lo.Uniq(lo.WithoutEmpty(self.UserConfig().Git.AllBranchesLogCmds))
261+
}
262+
258263
func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj {
259-
// Only choose between non-empty, non-identical commands
260-
candidates := lo.Uniq(lo.WithoutEmpty(self.UserConfig().Git.AllBranchesLogCmds))
264+
candidates := self.allBranchesLogCandidates()
261265

262-
n := len(candidates)
266+
i := self.allBranchesLogCmdIndex
267+
return self.cmd.New(str.ToArgv(candidates[i])).DontLog()
268+
}
263269

270+
func (self *BranchCommands) RotateAllBranchesLogIdx() {
271+
n := len(self.allBranchesLogCandidates())
264272
i := self.allBranchesLogCmdIndex
265273
self.allBranchesLogCmdIndex = uint8((int(i) + 1) % n)
266-
267-
return self.cmd.New(str.ToArgv(candidates[i])).DontLog()
268274
}
269275

270276
func (self *BranchCommands) IsBranchMerged(branch *models.Branch, mainBranches *MainBranches) (bool, error) {

pkg/gui/controllers/status_controller.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (self *StatusController) GetKeybindings(opts types.KeybindingsOpts) []*type
6060
},
6161
{
6262
Key: opts.GetKey(opts.Config.Status.AllBranchesLogGraph),
63-
Handler: func() error { self.showAllBranchLogs(); return nil },
63+
Handler: func() error { self.switchToOrRotateAllBranchesLogs(); return nil },
6464
Description: self.c.Tr.AllBranchesLogGraph,
6565
},
6666
}
@@ -190,6 +190,18 @@ func (self *StatusController) showAllBranchLogs() {
190190
})
191191
}
192192

193+
// Switches to the all branches view, or, if already on that view,
194+
// rotates to the next command in the list, and then renders it.
195+
func (self *StatusController) switchToOrRotateAllBranchesLogs() {
196+
// A bit of a hack to ensure we only rotate to the next branch log command
197+
// if we currently are looking at a branch log. Otherwise, we should just show
198+
// the current index (if we are coming from the dashboard).
199+
if self.c.Views().Main.Title == self.c.Tr.LogTitle {
200+
self.c.Git().Branch.RotateAllBranchesLogIdx()
201+
}
202+
self.showAllBranchLogs()
203+
}
204+
193205
func (self *StatusController) showDashboard() {
194206
versionStr := "master"
195207
version, err := types.ParseVersionNumber(self.c.GetConfig().GetVersion())
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package status
2+
3+
import (
4+
"github.com/jesseduffield/lazygit/pkg/config"
5+
. "github.com/jesseduffield/lazygit/pkg/integration/components"
6+
)
7+
8+
var LogCmdStatusPanelAllBranchesLog = NewIntegrationTest(NewIntegrationTestArgs{
9+
Description: "Cycle between two different log commands in the Status view when it has status panel AllBranchesLog",
10+
ExtraCmdArgs: []string{},
11+
Skip: false,
12+
SetupConfig: func(config *config.AppConfig) {
13+
config.GetUserConfig().Git.AllBranchesLogCmds = []string{`echo "view1"`, `echo "view2"`}
14+
config.GetUserConfig().Gui.StatusPanelView = "allBranchesLog"
15+
},
16+
SetupRepo: func(shell *Shell) {},
17+
Run: func(t *TestDriver, keys config.KeybindingConfig) {
18+
t.Views().Status().
19+
Focus()
20+
t.Views().Main().Content(Contains("view1"))
21+
22+
// We head to the branches view and return
23+
t.Views().Branches().
24+
Focus()
25+
t.Views().Status().
26+
Focus()
27+
28+
t.Views().Main().Content(Contains("view1").DoesNotContain("view2"))
29+
30+
t.Views().Status().
31+
Focus().
32+
Press(keys.Status.AllBranchesLogGraph)
33+
t.Views().Main().Content(Contains("view2").DoesNotContain("view1"))
34+
35+
t.Views().Status().
36+
Focus().
37+
Press(keys.Status.AllBranchesLogGraph)
38+
t.Views().Main().Content(Contains("view1").DoesNotContain("view2"))
39+
},
40+
})

pkg/integration/tests/test_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ var tests = []*components.IntegrationTest{
360360
status.ClickToFocus,
361361
status.ClickWorkingTreeStateToOpenRebaseOptionsMenu,
362362
status.LogCmd,
363+
status.LogCmdStatusPanelAllBranchesLog,
363364
status.ShowDivergenceFromBaseBranch,
364365
submodule.Add,
365366
submodule.Enter,

0 commit comments

Comments
 (0)