diff --git a/docs-master/Config.md b/docs-master/Config.md index 857a4e359..e5244983e 100644 --- a/docs-master/Config.md +++ b/docs-master/Config.md @@ -513,10 +513,18 @@ git: # (`` 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 diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index 381dd641e..d7d86657b 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -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"). diff --git a/pkg/commands/git_commands/commit_loader_test.go b/pkg/commands/git_commands/commit_loader_test.go index d26119720..0bcf23f05 100644 --- a/pkg/commands/git_commands/commit_loader_test.go +++ b/pkg/commands/git_commands/commit_loader_test.go @@ -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{ diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 9738186d9..332b7edff 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -420,8 +420,10 @@ type LogConfig struct { // // Can be toggled from within lazygit with `Log menu -> Show git graph` (`` 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", diff --git a/schema-master/config.json b/schema-master/config.json index 45a2b9efe..4c03ec386 100644 --- a/schema-master/config.json +++ b/schema-master/config.json @@ -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,