diff --git a/docs-master/keybindings/Keybindings_en.md b/docs-master/keybindings/Keybindings_en.md index bbbd3e2e8b7..ae8fce873d7 100644 --- a/docs-master/keybindings/Keybindings_en.md +++ b/docs-master/keybindings/Keybindings_en.md @@ -106,6 +106,7 @@ _Legend: `` means ctrl+b, `` means alt+b, `B` means shift+b_ | `` t `` | Revert | Create a revert commit for the selected commit, which applies the selected commit's changes in reverse. | | `` T `` | Tag commit | Create a new tag pointing at the selected commit. You'll be prompted to enter a tag name and optional description. | | `` `` | View log options | View options for commit log e.g. changing sort order, hiding the git graph, showing the whole git graph. | +| `` z `` | Toggle first-parent only (flat view) | Show only first-parent commits, hiding all commits from merged branches. This gives a flat view of the main branch history. | | `` `` | Checkout | Checkout the selected commit as a detached HEAD. | | `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). | | `` o `` | Open commit in browser | | diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index da4bcb7ff5e..716883d3bdd 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -64,6 +64,8 @@ type GetCommitsOptions struct { RefForPushedStatus models.Ref // the ref to use for determining pushed/unpushed status // determines if we show the whole git graph i.e. pass the '--all' flag All bool + // determines if we show only first-parent commits (flat view) + FirstParentOnly bool // If non-empty, show divergence from this ref (left-right log) RefToShowDivergenceFrom string MainBranches *MainBranches @@ -588,6 +590,7 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) *oscommands.CmdObj { Arg(refSpec). ArgIf(gitLogOrder != "default", "--"+gitLogOrder). ArgIf(opts.All, "--all"). + ArgIf(opts.FirstParentOnly, "--first-parent"). Arg("--oneline"). Arg(prettyFormat). Arg("--abbrev=40"). diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index e873663c30d..af2ad4013eb 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -148,6 +148,9 @@ type LocalCommitsViewModel struct { // If this is true we'll use git log --all when fetching the commits. showWholeGitGraph bool + + // If this is true we'll use git log --first-parent for a flat view. + showFirstParentOnly bool } func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *ContextCommon) *LocalCommitsViewModel { @@ -242,6 +245,14 @@ func (self *LocalCommitsViewModel) GetShowWholeGitGraph() bool { return self.showWholeGitGraph } +func (self *LocalCommitsViewModel) SetShowFirstParentOnly(value bool) { + self.showFirstParentOnly = value +} + +func (self *LocalCommitsViewModel) GetShowFirstParentOnly() bool { + return self.showFirstParentOnly +} + func (self *LocalCommitsViewModel) GetCommits() []*models.Commit { return self.getModel() } diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 8ebc76d161d..3a305871a3d 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -328,6 +328,7 @@ func (self *RefreshHelper) refreshCommitsWithLimit() error { RefName: self.refForLog(), RefForPushedStatus: checkedOutRef, All: self.c.Contexts().LocalCommits.GetShowWholeGitGraph(), + FirstParentOnly: self.c.Contexts().LocalCommits.GetShowFirstParentOnly(), MainBranches: self.c.Model().MainBranches, HashPool: self.c.Model().HashPool, }, diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 1091b91782f..4ff296b524e 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -244,6 +244,12 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [ Tooltip: self.c.Tr.OpenLogMenuTooltip, OpensMenu: true, }, + { + Key: 'z', + Handler: self.toggleFirstParentOnly, + Description: self.c.Tr.ToggleFirstParentOnly, + Tooltip: self.c.Tr.ToggleFirstParentOnlyTooltip, + }, } return bindings @@ -1485,3 +1491,9 @@ func (self *LocalCommitsController) pickEnabled(selectedCommits []*models.Commit return self.midRebaseCommandEnabled(selectedCommits, startIdx, endIdx) } + +func (self *LocalCommitsController) toggleFirstParentOnly() error { + self.context().SetShowFirstParentOnly(!self.context().GetShowFirstParentOnly()) + self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}}) + return nil +} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 75391a2c1f2..a69298f9599 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -778,6 +778,8 @@ type TranslationSet struct { OpenLogMenu string OpenLogMenuTooltip string LogMenuTitle string + ToggleFirstParentOnly string + ToggleFirstParentOnlyTooltip string ToggleShowGitGraphAll string ShowGitGraph string ShowGitGraphTooltip string @@ -1876,6 +1878,8 @@ func EnglishTranslationSet() *TranslationSet { OpenLogMenu: "View log options", OpenLogMenuTooltip: "View options for commit log e.g. changing sort order, hiding the git graph, showing the whole git graph.", LogMenuTitle: "Commit Log Options", + ToggleFirstParentOnly: "Toggle first-parent only (flat view)", + ToggleFirstParentOnlyTooltip: "Show only first-parent commits, hiding all commits from merged branches. This gives a flat view of the main branch history.", ToggleShowGitGraphAll: "Toggle show whole git graph (pass the `--all` flag to `git log`)", ShowGitGraph: "Show git graph", ShowGitGraphTooltip: "Show or hide the git graph in the commit log.\n\nThe default can be changed in the config file with the key 'git.log.showGraph'.",