Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/commands/git_commands/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -278,14 +278,24 @@ func (self *BranchCommands) allBranchesLogCandidates() []string {
func (self *BranchCommands) AllBranchesLogCmdObj() *oscommands.CmdObj {
candidates := self.allBranchesLogCandidates()

if self.allBranchesLogCmdIndex >= len(candidates) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to test this? isnt this impossible?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a real crash that I ran into during testing. You can reproduce this by configuring three log commands, pressing a to select the last one of those, and then (while lazygit is running) editing the config file again to remove one of the log commands. When you return to lazygit it will reload the config file, and crash.

PS It's always a good idea to look at commit messages when reviewing a PR, it's mentioned there.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS It's always a good idea to look at commit messages when reviewing a PR, it's mentioned there.

thats the reason why i use lazygit ❤️

self.allBranchesLogCmdIndex = 0
}

i := self.allBranchesLogCmdIndex
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)
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) {
Expand Down
8 changes: 6 additions & 2 deletions pkg/gui/controllers/status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})
Expand All @@ -196,7 +200,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()
Expand Down
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type TranslationSet struct {
RegularMergeTooltip string
NormalTitle string
LogTitle string
LogXOfYTitle string
CommitSummary string
CredentialsUsername string
CredentialsPassword string
Expand Down Expand Up @@ -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",
Expand Down