From e67bc45d484b79f420ba7ba951aea49c512d19d3 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Sun, 11 May 2025 16:58:53 -0400 Subject: [PATCH] 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. --- pkg/commands/git_commands/branch.go | 18 ++++++--- pkg/gui/controllers/status_controller.go | 14 ++++++- .../log_cmd_status_panel_all_branches_log.go | 38 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 pkg/integration/tests/status/log_cmd_status_panel_all_branches_log.go diff --git a/pkg/commands/git_commands/branch.go b/pkg/commands/git_commands/branch.go index 9b02845d4..e634b27ec 100644 --- a/pkg/commands/git_commands/branch.go +++ b/pkg/commands/git_commands/branch.go @@ -255,18 +255,24 @@ func (self *BranchCommands) Merge(branchName string, opts MergeOpts) error { return self.cmd.New(cmdArgs).Run() } -func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj { - // Only choose between non-empty, non-identical commands - candidates := lo.Uniq(lo.WithoutEmpty(self.UserConfig().Git.AllBranchesLogCmds)) +// Only choose between non-empty, non-identical commands +func (self *BranchCommands) allBranchesLogCandidates() []string { + return lo.Uniq(lo.WithoutEmpty(self.UserConfig().Git.AllBranchesLogCmds)) +} - n := len(candidates) +func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj { + candidates := self.allBranchesLogCandidates() i := self.allBranchesLogCmdIndex - self.allBranchesLogCmdIndex = uint8((int(i) + 1) % n) - return self.cmd.New(str.ToArgv(candidates[i])).DontLog() } +func (self *BranchCommands) RotateAllBranchesLogIdx() { + n := len(self.allBranchesLogCandidates()) + i := self.allBranchesLogCmdIndex + self.allBranchesLogCmdIndex = uint8((int(i) + 1) % n) +} + func (self *BranchCommands) IsBranchMerged(branch *models.Branch, mainBranches *MainBranches) (bool, error) { branchesToCheckAgainst := []string{"HEAD"} if branch.RemoteBranchStoredLocally() { diff --git a/pkg/gui/controllers/status_controller.go b/pkg/gui/controllers/status_controller.go index 8d173f46c..41ed5c496 100644 --- a/pkg/gui/controllers/status_controller.go +++ b/pkg/gui/controllers/status_controller.go @@ -60,7 +60,7 @@ func (self *StatusController) GetKeybindings(opts types.KeybindingsOpts) []*type }, { Key: opts.GetKey(opts.Config.Status.AllBranchesLogGraph), - Handler: func() error { self.showAllBranchLogs(); return nil }, + Handler: func() error { self.switchToOrRotateAllBranchesLogs(); return nil }, Description: self.c.Tr.AllBranchesLogGraph, }, } @@ -190,6 +190,18 @@ func (self *StatusController) showAllBranchLogs() { }) } +// Switches to the all branches view, or, if already on that view, +// rotates to the next command in the list, and then renders it. +func (self *StatusController) switchToOrRotateAllBranchesLogs() { + // A bit of a hack to ensure we only rotate to the next branch log command + // if we currently are looking at a branch log. Otherwise, we should just show + // the current index (if we are coming from the dashboard). + if self.c.Views().Main.Title == self.c.Tr.LogTitle { + self.c.Git().Branch.RotateAllBranchesLogIdx() + } + self.showAllBranchLogs() +} + func (self *StatusController) showDashboard() { versionStr := "master" version, err := types.ParseVersionNumber(self.c.GetConfig().GetVersion()) diff --git a/pkg/integration/tests/status/log_cmd_status_panel_all_branches_log.go b/pkg/integration/tests/status/log_cmd_status_panel_all_branches_log.go new file mode 100644 index 000000000..828459426 --- /dev/null +++ b/pkg/integration/tests/status/log_cmd_status_panel_all_branches_log.go @@ -0,0 +1,38 @@ +package status + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var LogCmdStatusPanelAllBranchesLog = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Cycle between two different log commands in the Status view when it has status panel AllBranchesLog", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + config.GetUserConfig().Git.AllBranchesLogCmds = []string{`echo "view1"`, `echo "view2"`} + config.GetUserConfig().Gui.StatusPanelView = "allBranchesLog" + }, + SetupRepo: func(shell *Shell) {}, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Status(). + Focus() + t.Views().Main().Content(Contains("view1")) + + // We head to the branches view and return + t.Views().Branches(). + Focus() + t.Views().Status(). + Focus() + + t.Views().Main().Content(Contains("view1").DoesNotContain("view2")) + + t.Views().Status(). + Press(keys.Status.AllBranchesLogGraph) + t.Views().Main().Content(Contains("view2").DoesNotContain("view1")) + + t.Views().Status(). + Press(keys.Status.AllBranchesLogGraph) + t.Views().Main().Content(Contains("view1").DoesNotContain("view2")) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 0a2a4f46c..23a05fa5c 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -360,6 +360,7 @@ var tests = []*components.IntegrationTest{ status.ClickToFocus, status.ClickWorkingTreeStateToOpenRebaseOptionsMenu, status.LogCmd, + status.LogCmdStatusPanelAllBranchesLog, status.ShowDivergenceFromBaseBranch, submodule.Add, submodule.Enter,