diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 5d6b5e21934..93bf20220f4 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -117,6 +117,9 @@ func NewAppConfig( if appState.GitLogShowGraph == "" { appState.GitLogShowGraph = userConfig.Git.Log.ShowGraph } + if appState.GitLogShowTags == "" { + appState.GitLogShowTags = userConfig.Git.Log.ShowTags + } appConfig := &AppConfig{ name: name, @@ -691,6 +694,9 @@ type AppState struct { // This determines whether the git graph is rendered in the commits panel // One of 'always' | 'never' | 'when-maximised' GitLogShowGraph string + // This determines whether the commit tags are rendered in the commits panel + // One of 'always' | 'never' | 'when-maximised' + GitLogShowTags string } func getDefaultAppState() *AppState { @@ -705,6 +711,7 @@ func getDefaultAppState() *AppState { RemoteBranchSortOrder: "alphabetical", GitLogOrder: "", // should be "topo-order" eventually GitLogShowGraph: "", // should be "always" eventually + GitLogShowTags: "", // should be "always" eventually } } diff --git a/pkg/config/app_config_test.go b/pkg/config/app_config_test.go index 90c13ce6cd2..92e35d453ab 100644 --- a/pkg/config/app_config_test.go +++ b/pkg/config/app_config_test.go @@ -698,6 +698,10 @@ git: # displays the whole git graph by default in the commits view (equivalent to passing the --all argument to git log) showWholeGraph: false + # This determines whether tags are displayed in the commits view + # One of 'always' | 'never' | 'when-maximised' + showTags: always + # When copying commit hashes to the clipboard, truncate them to this # length. Set to 40 to disable truncation. truncateCopiedCommitHashesTo: 12 diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index af80dd9a41c..d2e7c8a7b05 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -337,6 +337,8 @@ type LogConfig struct { ShowGraph string `yaml:"showGraph" jsonschema:"deprecated,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`) ShowWholeGraph bool `yaml:"showWholeGraph"` + // This determines whether tags are displayed in the commits view + ShowTags string `yaml:"showTags" jsonschema:"enum=always,enum=never,enum=when-maximised"` } type CommitPrefixConfig struct { @@ -815,6 +817,7 @@ func GetDefaultConfig() *UserConfig { Order: "topo-order", ShowGraph: "always", ShowWholeGraph: false, + ShowTags: "always", }, SkipHookPrefix: "WIP", MainBranches: []string{"master", "main"}, diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index 6a2a20c8d74..af971365781 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -61,6 +61,7 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext { startIdx, endIdx, shouldShowGraph(c), + shouldDisplayForScreenMode(c, viewModel.showTags), c.Model().BisectInfo, ) } @@ -148,6 +149,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 show tags in the commit list. + showTags string } func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *ContextCommon) *LocalCommitsViewModel { @@ -155,6 +159,7 @@ func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *ContextCommon ListViewModel: NewListViewModel(getModel), limitCommits: true, showWholeGitGraph: c.UserConfig().Git.Log.ShowWholeGraph, + showTags: c.UserConfig().Git.Log.ShowTags, } return self @@ -238,6 +243,14 @@ func (self *LocalCommitsViewModel) SetShowWholeGitGraph(value bool) { self.showWholeGitGraph = value } +func (self *LocalCommitsContext) GetShowTags() string { + return self.showTags +} + +func (self *LocalCommitsViewModel) SetShowTags(value string) { + self.showTags = value +} + func (self *LocalCommitsViewModel) GetShowWholeGitGraph() bool { return self.showWholeGitGraph } @@ -247,12 +260,14 @@ func (self *LocalCommitsViewModel) GetCommits() []*models.Commit { } func shouldShowGraph(c *ContextCommon) bool { + return shouldDisplayForScreenMode(c, c.GetAppState().GitLogShowGraph) +} + +func shouldDisplayForScreenMode(c *ContextCommon, value string) bool { if c.Modes().Filtering.Active() { return false } - value := c.GetAppState().GitLogShowGraph - switch value { case "always": return true @@ -262,7 +277,7 @@ func shouldShowGraph(c *ContextCommon) bool { return c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL } - log.Fatalf("Unknown value for git.log.showGraph: %s. Expected one of: 'always', 'never', 'when-maximised'", value) + log.Fatalf("Unknown value: %s. Expected one of: 'always', 'never', 'when-maximised'", value) return false } diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index ac28aca2edd..936b37a00fe 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -76,6 +76,7 @@ func NewSubCommitsContext( startIdx, endIdx, shouldShowGraph(c), + shouldDisplayForScreenMode(c, viewModel.GetShowTags()), git_commands.NewNullBisectInfo(), ) } @@ -147,6 +148,7 @@ type SubCommitsViewModel struct { limitCommits bool showBranchHeads bool + showTags string } func (self *SubCommitsViewModel) SetRef(ref types.Ref) { @@ -173,6 +175,14 @@ func (self *SubCommitsViewModel) GetShowBranchHeads() bool { return self.showBranchHeads } +func (self *SubCommitsViewModel) SetShowTags(value string) { + self.showTags = value +} + +func (self *SubCommitsViewModel) GetShowTags() string { + return self.showTags +} + func (self *SubCommitsContext) CanRebase() bool { return false } diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index e9cd9cbc03f..fe3ce5f2033 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -1192,6 +1192,42 @@ func (self *LocalCommitsController) handleOpenLogMenu() error { }) }, }, + { + Label: self.c.Tr.ShowTags, + OpensMenu: true, + OnPress: func() error { + currentValue := self.context().GetShowTags() + onPress := func(value string) func() error { + return func() error { + self.context().SetShowTags(value) + self.c.SaveAppStateAndLogError() + self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits) + self.c.PostRefreshUpdate(self.c.Contexts().SubCommits) + return nil + } + } + return self.c.Menu(types.CreateMenuOptions{ + Title: self.c.Tr.LogMenuTitle, + Items: []*types.MenuItem{ + { + Label: "always", + OnPress: onPress("always"), + Widget: types.MakeMenuRadioButton(currentValue == "always"), + }, + { + Label: "never", + OnPress: onPress("never"), + Widget: types.MakeMenuRadioButton(currentValue == "never"), + }, + { + Label: "when maximised", + OnPress: onPress("when-maximised"), + Widget: types.MakeMenuRadioButton(currentValue == "when-maximised"), + }, + }, + }) + }, + }, { Label: self.c.Tr.SortCommits, OpensMenu: true, diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index 63c2b3c9b54..f3b4387eabf 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -2,6 +2,7 @@ package presentation import ( "fmt" + "regexp" "strings" "time" @@ -55,6 +56,7 @@ func GetCommitListDisplayStrings( startIdx int, endIdx int, showGraph bool, + showTags bool, bisectInfo *git_commands.BisectInfo, ) [][]string { mutex.Lock() @@ -203,6 +205,7 @@ func GetCommitListDisplayStrings( parseEmoji, getGraphLine(unfilteredIdx), fullDescription, + showTags, bisectStatus, bisectInfo, )) @@ -355,6 +358,7 @@ func displayCommit( parseEmoji bool, graphLine string, fullDescription bool, + showTags bool, bisectStatus BisectStatus, bisectInfo *git_commands.BisectInfo, ) []string { @@ -391,12 +395,17 @@ func displayCommit( } tagString := "" - if fullDescription { - if commit.ExtraInfo != "" { - tagString = style.FgMagenta.SetBold().Sprint(commit.ExtraInfo) + " " + if fullDescription && commit.ExtraInfo != "" { + extraInfo := commit.ExtraInfo + if !showTags { + extraInfo = regexp.MustCompile(`tag: [^,)\s]+,?\s*`).ReplaceAllString(commit.ExtraInfo, "") + extraInfo = strings.Replace(extraInfo, "()", "", 1) // if only tags were present in extraInfo + } + if extraInfo != "" { + tagString = style.FgMagenta.SetBold().Sprint(extraInfo) + " " } } else { - if len(commit.Tags) > 0 { + if showTags && len(commit.Tags) > 0 { tagString = theme.DiffTerminalColor.SetBold().Sprint(strings.Join(commit.Tags, " ")) + " " } diff --git a/pkg/gui/presentation/commits_test.go b/pkg/gui/presentation/commits_test.go index 1536d420a8c..593562ffab0 100644 --- a/pkg/gui/presentation/commits_test.go +++ b/pkg/gui/presentation/commits_test.go @@ -41,6 +41,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx int endIdx int showGraph bool + showTags bool bisectInfo *git_commands.BisectInfo expected string focus bool @@ -51,6 +52,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 1, showGraph: false, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -65,6 +67,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 2, showGraph: false, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -82,6 +85,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 2, showGraph: false, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -90,6 +94,43 @@ func TestGetCommitListDisplayStrings(t *testing.T) { hash2 commit2 `), }, + { + testName: "commit with tags, tags are hidden", + commitOpts: []models.NewCommitOpts{ + {Name: "commit1", Hash: "hash1", Tags: []string{"tag1", "tag2"}}, + {Name: "commit2", Hash: "hash2"}, + }, + startIdx: 0, + endIdx: 2, + showGraph: false, + showTags: false, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + expected: formatExpected(` + hash1 commit1 + hash2 commit2 + `), + }, + { + testName: "hidden commit tags with full description", + commitOpts: []models.NewCommitOpts{ + {Name: "commit1", Hash: "hash1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield", ExtraInfo: "(tag: v1.0)"}, + {Name: "commit2", Hash: "hash2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield", ExtraInfo: "(tag: v2.0, remote/branch, remote/branch2)"}, + }, + fullDescription: true, + startIdx: 0, + endIdx: 2, + showGraph: false, + showTags: false, + bisectInfo: git_commands.NewNullBisectInfo(), + cherryPickedCommitHashSet: set.New[string](), + now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), + expected: formatExpected(` + hash1 Jesse Duffield commit1 + hash2 Jesse Duffield (remote/branch, remote/branch2) commit2 + `), + }, { testName: "show local branch head, except the current branch, main branches, or merged branches", commitOpts: []models.NewCommitOpts{ @@ -109,6 +150,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 4, showGraph: false, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -134,6 +176,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 2, showGraph: false, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -157,6 +200,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 2, showGraph: false, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -178,6 +222,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 3, showGraph: false, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -199,6 +244,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 5, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -222,6 +268,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 5, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -245,6 +292,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 1, endIdx: 5, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -267,6 +315,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 3, endIdx: 5, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -287,6 +336,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 2, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -307,6 +357,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 4, endIdx: 5, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -326,6 +377,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 2, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -349,6 +401,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 8, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -378,6 +431,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 2, endIdx: 8, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -405,6 +459,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 5, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -431,6 +486,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 4, endIdx: 8, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -456,6 +512,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 2, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -476,6 +533,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 5, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -497,6 +555,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 3, showGraph: true, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), @@ -518,6 +577,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { startIdx: 0, endIdx: 2, showGraph: false, + showTags: true, bisectInfo: git_commands.NewNullBisectInfo(), cherryPickedCommitHashSet: set.New[string](), now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC), @@ -568,6 +628,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) { s.startIdx, s.endIdx, s.showGraph, + s.showTags, s.bisectInfo, ) diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 36a119c3657..f704115e651 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -779,6 +779,7 @@ type TranslationSet struct { LogMenuTitle string ToggleShowGitGraphAll string ShowGitGraph string + ShowTags string SortOrder string SortAlphabetical string SortByDate string @@ -1868,6 +1869,7 @@ func EnglishTranslationSet() *TranslationSet { LogMenuTitle: "Commit Log Options", ToggleShowGitGraphAll: "Toggle show whole git graph (pass the `--all` flag to `git log`)", ShowGitGraph: "Show git graph", + ShowTags: "Show tags", SortOrder: "Sort order", SortAlphabetical: "Alphabetical", SortByDate: "Date", diff --git a/schema/config.json b/schema/config.json index 9560c3ab49e..41a35a4d6f4 100644 --- a/schema/config.json +++ b/schema/config.json @@ -1502,6 +1502,16 @@ "type": "boolean", "description": "displays the whole git graph by default in the commits view (equivalent to passing the `--all` argument to `git log`)", "default": false + }, + "showTags": { + "type": "string", + "enum": [ + "always", + "never", + "when-maximised" + ], + "description": "Configure this with `Log menu -\u003e Show tags` (\u003cc-l\u003e in the commits window by default).", + "default": "always" } }, "additionalProperties": false,