Make the refs shown by the commits view's whole-graph toggle configurable

The whole-graph toggle hardcoded `--all`, which means every ref in the
repo. That is more than most people want: agent harnesses write large
numbers of refs under refs/agents, and stashes are refs too, so both
flood the commits view and bury the commits the user actually cares
about. There was no way to narrow the set short of turning the toggle
off entirely.

Add `git.log.allRefsArgs`, the args spliced into `git log` in place of
`--all`. It defaults to `["--all"]`, so existing behaviour is unchanged,
and can be set to something narrower such as `["--branches",
"--remotes"]`, or to `--all` plus `--exclude` globs.

Args rather than a whole command, as `git.allBranchesLogCmds` takes:
that pane dumps raw output into the main view, whereas the commits view
parses `git log` output field by field, so the pretty format and the
other flags have to stay under lazygit's control.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Jacob Bayer 2026-09-08 04:38:55 -04:00
parent c07f4d381b
commit ed519488ea
5 changed files with 53 additions and 5 deletions

View file

@ -513,10 +513,18 @@ git:
# (`<ctrl+l>` in the commits window by default).
showGraph: always
# displays the whole git graph by default in the commits view (equivalent to
# passing the `--all` argument to `git log`)
# displays the whole git graph by default in the commits view (see `allRefsArgs`
# for which refs that includes)
showWholeGraph: false
# The `git log` args used to select which refs are shown in the commits view
# when showing the whole graph. Defaults to `["--all"]`, which includes every
# ref; set it to something narrower such as `["--branches", "--remotes"]` to
# leave out refs that aren't branches, e.g. stashes or refs written by external
# tooling.
allRefsArgs:
- --all
# How branches are sorted in the local branches view.
# One of: 'date' (default) | 'recency' | 'alphabetical'
# Can be changed from within Lazygit with the Sort Order menu (`s`) in the

View file

@ -606,7 +606,7 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) *oscommands.CmdObj {
cmdArgs := NewGitCmd("log").
Arg(refSpec).
ArgIf(gitLogOrder != "default", "--"+gitLogOrder).
ArgIf(opts.All, "--all").
ArgIf(opts.All, self.UserConfig().Git.Log.AllRefsArgs...).
Arg("--oneline").
Arg(prettyFormat).
Arg("--abbrev=40").

View file

@ -34,6 +34,7 @@ func TestGetCommits(t *testing.T) {
expectedCommitOpts []models.NewCommitOpts
expectedError error
logOrder string
allRefsArgs []string
opts GetCommitsOptions
mainBranches []string
}
@ -61,6 +62,29 @@ func TestGetCommits(t *testing.T) {
expectedCommitOpts: []models.NewCommitOpts{},
expectedError: nil,
},
{
testName: "should pass the default all-refs args when showing the whole graph",
logOrder: "topo-order",
opts: GetCommitsOptions{RefName: "HEAD", RefForPushedStatus: &models.Branch{Name: "mybranch"}, IncludeRebaseCommits: false, All: true},
runner: oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"rev-list", "refs/heads/mybranch", "^mybranch@{u}"}, "", nil).
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--all", "--oneline", "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
expectedCommitOpts: []models.NewCommitOpts{},
expectedError: nil,
},
{
testName: "should pass the configured all-refs args when showing the whole graph",
logOrder: "topo-order",
allRefsArgs: []string{"--branches", "--remotes"},
opts: GetCommitsOptions{RefName: "HEAD", RefForPushedStatus: &models.Branch{Name: "mybranch"}, IncludeRebaseCommits: false, All: true},
runner: oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"rev-list", "refs/heads/mybranch", "^mybranch@{u}"}, "", nil).
ExpectGitArgs([]string{"log", "HEAD", "--topo-order", "--branches", "--remotes", "--oneline", "--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s", "--abbrev=40", "--no-show-signature", "--"}, "", nil),
expectedCommitOpts: []models.NewCommitOpts{},
expectedError: nil,
},
{
testName: "should return commits if they are present",
logOrder: "topo-order",
@ -300,6 +324,9 @@ func TestGetCommits(t *testing.T) {
t.Run(scenario.testName, func(t *testing.T) {
common := common.NewDummyCommon()
common.UserConfig().Git.Log.Order = scenario.logOrder
if scenario.allRefsArgs != nil {
common.UserConfig().Git.Log.AllRefsArgs = scenario.allRefsArgs
}
cmd := oscommands.NewDummyCmdObjBuilder(scenario.runner)
builder := &CommitLoader{

View file

@ -420,8 +420,10 @@ type LogConfig struct {
//
// Can be toggled from within lazygit with `Log menu -> Show git graph` (`<ctrl+l>` in the commits window by default).
ShowGraph string `yaml:"showGraph" jsonschema:"enum=always,enum=never,enum=when-maximised"`
// displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)
// displays the whole git graph by default in the commits view (see `allRefsArgs` for which refs that includes)
ShowWholeGraph bool `yaml:"showWholeGraph"`
// The `git log` args used to select which refs are shown in the commits view when showing the whole graph. Defaults to `["--all"]`, which includes every ref; set it to something narrower such as `["--branches", "--remotes"]` to leave out refs that aren't branches, e.g. stashes or refs written by external tooling.
AllRefsArgs []string `yaml:"allRefsArgs"`
}
type CommitPrefixConfig struct {
@ -950,6 +952,7 @@ func GetDefaultConfigForPlatform(platform string) *UserConfig {
Order: "topo-order",
ShowGraph: "always",
ShowWholeGraph: false,
AllRefsArgs: []string{"--all"},
},
LocalBranchSortOrder: "date",
RemoteBranchSortOrder: "date",

View file

@ -3492,8 +3492,18 @@
},
"showWholeGraph": {
"type": "boolean",
"description": "displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)",
"description": "displays the whole git graph by default in the commits view (see `allRefsArgs` for which refs that includes)",
"default": false
},
"allRefsArgs": {
"items": {
"type": "string"
},
"type": "array",
"description": "The `git log` args used to select which refs are shown in the commits view when showing the whole graph. Defaults to `[\"--all\"]`, which includes every ref; set it to something narrower such as `[\"--branches\", \"--remotes\"]` to leave out refs that aren't branches, e.g. stashes or refs written by external tooling.",
"default": [
"--all"
]
}
},
"additionalProperties": false,