Skip to content

Commit e67bc45

Browse files
Chris McDonnellstefanhaller
authored andcommitted
Split behavior of rendering allBranchesLogCmd and switching to next cmd
This now allows for leaving the status panel and returning back to the same log command. Previously any return to the status panel would result in the next command in the list being shown. Now, you need to press `a`, with a log command being rendered, to rotate to the next allBranchesLogCmd.
1 parent a0ec22c commit e67bc45

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
Press(keys.Status.AllBranchesLogGraph)
32+
t.Views().Main().Content(Contains("view2").DoesNotContain("view1"))
33+
34+
t.Views().Status().
35+
Press(keys.Status.AllBranchesLogGraph)
36+
t.Views().Main().Content(Contains("view1").DoesNotContain("view2"))
37+
},
38+
})

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)