From 19f88290a228d1d93f1f2380cb95880ecfad1ab3 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 7 Oct 2025 17:19:24 +0200 Subject: [PATCH 1/4] Change allBranchesLogCmdIndex to an int I know that uint was chosen to document that it can't be negative (not sure why the "8" was chosen, though). That's pointless in languages that don't enforce this though: you can subtract 1 from uint8(0) and you'll get something that doesn't make sense; that's not any better than getting -1. I'm not a fan of using unsigned types in general (at least in languages like go or C++), and they usually just make the code more cumbersome without real benefits. --- pkg/commands/git_commands/branch.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git_commands/branch.go b/pkg/commands/git_commands/branch.go index 76b5727c7..37a661748 100644 --- a/pkg/commands/git_commands/branch.go +++ b/pkg/commands/git_commands/branch.go @@ -13,7 +13,7 @@ import ( type BranchCommands struct { *GitCommon - allBranchesLogCmdIndex uint8 // keeps track of current all branches log command + allBranchesLogCmdIndex int // keeps track of current all branches log command } func NewBranchCommands(gitCommon *GitCommon) *BranchCommands { @@ -285,7 +285,7 @@ func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj { func (self *BranchCommands) RotateAllBranchesLogIdx() { n := len(self.allBranchesLogCandidates()) i := self.allBranchesLogCmdIndex - self.allBranchesLogCmdIndex = uint8((int(i) + 1) % n) + self.allBranchesLogCmdIndex = (i + 1) % n } func (self *BranchCommands) IsBranchMerged(branch *models.Branch, mainBranches *MainBranches) (bool, error) { From 220cde13765ca92221325c2a9085562ed2c8d7fe Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 7 Oct 2025 17:22:56 +0200 Subject: [PATCH 2/4] Fix potential crash when reloading the config after removing a branch log command When cycling to the last branch log command, and then editing the config to remove one or more log commands, lazygit would crash with an out of bounds panic when returning to it. Fix this by resetting the log index to 0 when it is out of bounds. (I think resetting to 0 is better than clamping, although it doesn't matter much.) --- pkg/commands/git_commands/branch.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/commands/git_commands/branch.go b/pkg/commands/git_commands/branch.go index 37a661748..4a2fbd51f 100644 --- a/pkg/commands/git_commands/branch.go +++ b/pkg/commands/git_commands/branch.go @@ -278,6 +278,10 @@ func (self *BranchCommands) allBranchesLogCandidates() []string { func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj { candidates := self.allBranchesLogCandidates() + if self.allBranchesLogCmdIndex >= len(candidates) { + self.allBranchesLogCmdIndex = 0 + } + i := self.allBranchesLogCmdIndex return self.cmd.New(str.ToArgv(candidates[i])).DontLog() } From bf56a61b71a52924a2ec64a40d03a16950f35cbe Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 7 Oct 2025 17:05:32 +0200 Subject: [PATCH 3/4] Change condition that determines whether we are showing the dashboard Doesn't make a difference currently, since the title is either StatusTitle when the dashboard is showing, or LogTitle when one of the branch logs is showing. This is going to change in the next commit, though. --- pkg/gui/controllers/status_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/gui/controllers/status_controller.go b/pkg/gui/controllers/status_controller.go index 41ed5c496..35545d11a 100644 --- a/pkg/gui/controllers/status_controller.go +++ b/pkg/gui/controllers/status_controller.go @@ -196,7 +196,7 @@ 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 { + if self.c.Views().Main.Title != self.c.Tr.StatusTitle { self.c.Git().Branch.RotateAllBranchesLogIdx() } self.showAllBranchLogs() From 5d02cba7210c052286dbbe7c09ff8b8d968c5871 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 7 Oct 2025 17:15:19 +0200 Subject: [PATCH 4/4] Show "Log (x of y)" in the title bar when there is more than one branch log command --- pkg/commands/git_commands/branch.go | 6 ++++++ pkg/gui/controllers/status_controller.go | 6 +++++- pkg/i18n/english.go | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/commands/git_commands/branch.go b/pkg/commands/git_commands/branch.go index 4a2fbd51f..13abbd697 100644 --- a/pkg/commands/git_commands/branch.go +++ b/pkg/commands/git_commands/branch.go @@ -292,6 +292,12 @@ func (self *BranchCommands) RotateAllBranchesLogIdx() { self.allBranchesLogCmdIndex = (i + 1) % n } +func (self *BranchCommands) GetAllBranchesLogIdxAndCount() (int, int) { + n := len(self.allBranchesLogCandidates()) + i := self.allBranchesLogCmdIndex + return i, 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 35545d11a..d2c658095 100644 --- a/pkg/gui/controllers/status_controller.go +++ b/pkg/gui/controllers/status_controller.go @@ -181,10 +181,14 @@ func (self *StatusController) showAllBranchLogs() { cmdObj := self.c.Git().Branch.AllBranchesLogCmdObj() task := types.NewRunPtyTask(cmdObj.GetCmd()) + title := self.c.Tr.LogTitle + if i, n := self.c.Git().Branch.GetAllBranchesLogIdxAndCount(); n > 1 { + title = fmt.Sprintf(self.c.Tr.LogXOfYTitle, i+1, n) + } self.c.RenderToMainViews(types.RefreshMainOpts{ Pair: self.c.MainViewPairs().Normal, Main: &types.ViewUpdateOpts{ - Title: self.c.Tr.LogTitle, + Title: title, Task: task, }, }) diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index b750d8ff7..30123efaa 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -30,6 +30,7 @@ type TranslationSet struct { RegularMergeTooltip string NormalTitle string LogTitle string + LogXOfYTitle string CommitSummary string CredentialsUsername string CredentialsPassword string @@ -1110,6 +1111,7 @@ func EnglishTranslationSet() *TranslationSet { MergingTitle: "Main panel (merging)", NormalTitle: "Main panel (normal)", LogTitle: "Log", + LogXOfYTitle: "Log (%d of %d)", CommitSummary: "Commit summary", CredentialsUsername: "Username", CredentialsPassword: "Password",