Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch between multiple log views #3354

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/Config.md
Expand Up @@ -122,6 +122,7 @@ git:
fetchAll: true # Pass --all flag when running git fetch. Set to false to fetch only origin (or the current branch's upstream remote if there is one)
branchLogCmd: 'git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --'
allBranchesLogCmd: 'git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium'
allBranchesLogCmds: [] # a list of your favorite log commands (pressing 'a' in the status panel will cycle between them)
overrideGpg: false # prevents lazygit from spawning a separate process when using GPG
disableForcePushing: false
parseEmoji: false
Expand Down
2 changes: 1 addition & 1 deletion docs/keybindings/Keybindings_en.md
Expand Up @@ -307,7 +307,7 @@ If you would instead like to start an interactive rebase from the selected commi
| `` e `` | Edit config file | Open file in external editor. |
| `` u `` | Check for update | |
| `` <enter> `` | Switch to a recent repo | |
| `` a `` | Show all branch logs | |
| `` a `` | Show/cycle all branch logs | |

## Sub-commits

Expand Down
16 changes: 15 additions & 1 deletion pkg/commands/git_commands/branch.go
Expand Up @@ -7,10 +7,12 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/mgutz/str"
"github.com/samber/lo"
)

type BranchCommands struct {
*GitCommon
allBranchesLogCmdIndex uint8 // keeps track of current all branches log command
}

func NewBranchCommands(gitCommon *GitCommon) *BranchCommands {
Expand Down Expand Up @@ -219,5 +221,17 @@ func (self *BranchCommands) Merge(branchName string, opts MergeOpts) error {
}

func (self *BranchCommands) AllBranchesLogCmdObj() oscommands.ICmdObj {
return self.cmd.New(str.ToArgv(self.UserConfig.Git.AllBranchesLogCmd)).DontLog()
// Only choose between non-empty, non-identical commands
candidates := lo.Uniq(lo.WithoutEmpty(append([]string{
self.UserConfig.Git.AllBranchesLogCmd,
},
self.UserConfig.Git.AllBranchesLogCmds...,
)))

n := len(candidates)

i := self.allBranchesLogCmdIndex
self.allBranchesLogCmdIndex = uint8((int(i) + 1) % n)

return self.cmd.New(str.ToArgv(candidates[i])).DontLog()
}
2 changes: 2 additions & 0 deletions pkg/config/user_config.go
Expand Up @@ -196,6 +196,8 @@ type GitConfig struct {
BranchLogCmd string `yaml:"branchLogCmd"`
// Command used to display git log of all branches in the main window
AllBranchesLogCmd string `yaml:"allBranchesLogCmd"`
// Commands used to display git log of all branches in the main window, they will be cycled in order of appearance
AllBranchesLogCmds []string `yaml:"allBranchesLogCmds"`
// If true, do not spawn a separate process when using GPG
OverrideGpg bool `yaml:"overrideGpg"`
// If true, do not allow force pushes
Expand Down
2 changes: 1 addition & 1 deletion pkg/i18n/english.go
Expand Up @@ -1168,7 +1168,7 @@ func EnglishTranslationSet() TranslationSet {
MergeBranchTooltip: "Merge selected branch into currently checked out branch.",
ConfirmQuit: `Are you sure you want to quit?`,
SwitchRepo: `Switch to a recent repo`,
AllBranchesLogGraph: `Show all branch logs`,
AllBranchesLogGraph: `Show/cycle all branch logs`,
UnsupportedGitService: `Unsupported git service`,
CreatePullRequest: `Create pull request`,
CopyPullRequestURL: `Copy pull request URL to clipboard`,
Expand Down
33 changes: 33 additions & 0 deletions pkg/integration/tests/status/log_cmd.go
@@ -0,0 +1,33 @@
package status

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var LogCmd = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Cycle between two different log commands in the Status view",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Git.AllBranchesLogCmd = `echo "view1"`
config.UserConfig.Git.AllBranchesLogCmds = []string{`echo "view2"`}
},
SetupRepo: func(shell *Shell) {},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Status().
Focus().
Press(keys.Status.AllBranchesLogGraph)
t.Views().Main().Content(Contains("view1"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd maybe also add the check that it does not contain view2 at the same time. Just to be extra sure it's not displaying view1view2 somehow.


t.Views().Status().
Focus().
Press(keys.Status.AllBranchesLogGraph)
t.Views().Main().Content(Contains("view2").DoesNotContain("view1"))

t.Views().Status().
Focus().
Press(keys.Status.AllBranchesLogGraph)
t.Views().Main().Content(Contains("view1").DoesNotContain("view2"))
},
})
2 changes: 2 additions & 0 deletions pkg/integration/tests/test_list.go
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/tests/reflog"
"github.com/jesseduffield/lazygit/pkg/integration/tests/staging"
"github.com/jesseduffield/lazygit/pkg/integration/tests/stash"
"github.com/jesseduffield/lazygit/pkg/integration/tests/status"
"github.com/jesseduffield/lazygit/pkg/integration/tests/submodule"
"github.com/jesseduffield/lazygit/pkg/integration/tests/sync"
"github.com/jesseduffield/lazygit/pkg/integration/tests/tag"
Expand Down Expand Up @@ -246,6 +247,7 @@ var tests = []*components.IntegrationTest{
stash.StashIncludingUntrackedFiles,
stash.StashStaged,
stash.StashUnstaged,
status.LogCmd,
submodule.Add,
submodule.Enter,
submodule.EnterNested,
Expand Down
7 changes: 7 additions & 0 deletions schema/config.json
Expand Up @@ -481,6 +481,13 @@
"description": "Command used to display git log of all branches in the main window",
"default": "git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium"
},
"allBranchesLogCmds": {
"items": {
"type": "string"
},
"type": "array",
"description": "Commands used to display git log of all branches in the main window, they will be cycled in order of appearance"
},
"overrideGpg": {
"type": "boolean",
"description": "If true, do not spawn a separate process when using GPG"
Expand Down