Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs-master/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,15 @@ git:
# passing the `--all` argument to `git log`)
showWholeGraph: false

# Custom format for the commit list side panel.
# Supports placeholders like:
# %h short hash %s subject
# %an author name %as short author
# %g graph line %d decorations (tags/branches/markers)
# %a action %cd date
# Default: "%h %a %as %g %d %s".
customPaneLogFormat: '%h %a %as %g %d %s'

# 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
Expand Down
16 changes: 13 additions & 3 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ type LogConfig struct {
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`)
ShowWholeGraph bool `yaml:"showWholeGraph"`

// Custom format for the commit list side panel.
// Supports placeholders like:
// %h short hash %s subject
// %an author name %as short author
// %g graph line %d decorations (tags/branches/markers)
// %a action %cd date
// Default: "%h %a %as %g %d %s".
CustomPaneLogFormat string `yaml:"customPaneLogFormat"`
}

type CommitPrefixConfig struct {
Expand Down Expand Up @@ -831,9 +840,10 @@ func GetDefaultConfig() *UserConfig {
SquashMergeMessage: "Squash merge {{selectedRef}} into {{currentBranch}}",
},
Log: LogConfig{
Order: "topo-order",
ShowGraph: "always",
ShowWholeGraph: false,
Order: "topo-order",
ShowGraph: "always",
ShowWholeGraph: false,
CustomPaneLogFormat: "%h %a %as %g %d %s",
},
LocalBranchSortOrder: "date",
RemoteBranchSortOrder: "date",
Expand Down
78 changes: 78 additions & 0 deletions pkg/gui/presentation/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,32 @@ func displayCommit(
}
author := authors.AuthorWithLength(commit.AuthorName, authorLength)

// if custom config
if common.UserConfig().Git.Log.CustomPaneLogFormat != "%h %a %as %g %d %s" {
lastCol := customPaneLogFormat(
common.UserConfig().Git.Log.CustomPaneLogFormat,
commit,
hashString,
author,
now,
timeFormat,
shortTimeFormat,
parseEmoji,
graphLine,
mark,
tagString,
actionString,
)

cols := []string{
divergenceString,
bisectString,
lastCol,
}

return cols
}

cols := make([]string, 0, 7)
cols = append(
cols,
Expand All @@ -449,6 +475,58 @@ func displayCommit(
return cols
}

func customPaneLogFormat(
format string,
commit *models.Commit,
shortHashColored string,
authorShort string,
now time.Time,
timeFormat string,
shortTimeFormat string,
parseEmoji bool,
graphLine string,
mark string,
tagString string,
actionString string,
) string {
out := format

out = strings.ReplaceAll(out, "%h", shortHashColored)
out = strings.ReplaceAll(out, "%H", commit.Hash())

out = strings.ReplaceAll(out, "%an", commit.AuthorName)
out = strings.ReplaceAll(out, "%ae", commit.AuthorEmail)
out = strings.ReplaceAll(out, "%as", authorShort)

dateStr := utils.UnixToDateSmart(
now,
commit.UnixTimestamp,
timeFormat,
shortTimeFormat,
)
out = strings.ReplaceAll(out, "%cd", style.FgBlue.Sprint(dateStr))

out = strings.ReplaceAll(out, "%g", graphLine)

out = strings.ReplaceAll(out, "%d", mark+tagString)

out = strings.ReplaceAll(out, "%a", actionString)

subject := commit.Name
if commit.Action == todo.UpdateRef {
subject = strings.TrimPrefix(subject, "refs/heads/")
}
if parseEmoji {
subject = emoji.Sprint(subject)
}
subject = theme.DefaultTextColor.Sprint(subject)
out = strings.ReplaceAll(out, "%s", subject)

out = strings.Join(strings.Fields(out), " ")

return out
}

func getBisectStatusColor(status BisectStatus) style.TextStyle {
switch status {
case BisectStatusNone:
Expand Down
55 changes: 53 additions & 2 deletions pkg/gui/presentation/commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
bisectInfo *git_commands.BisectInfo
expected string
focus bool
setupConfig func(c *common.Common)
}{
{
testName: "no commits",
Expand Down Expand Up @@ -73,6 +74,26 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
hash2 commit2
`),
},
{
testName: "some commits formatted with email",
commitOpts: []models.NewCommitOpts{
{Name: "commit1", Hash: "hash1", AuthorEmail: "[email protected]"},
{Name: "commit2", Hash: "hash2", AuthorEmail: "[email protected]"},
},
startIdx: 0,
endIdx: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
setupConfig: func(c *common.Common) {
c.UserConfig().Git.Log.CustomPaneLogFormat = "%ae %s"
},
expected: formatExpected(`
[email protected] commit1
[email protected] commit2
`),
},
{
testName: "commit with tags",
commitOpts: []models.NewCommitOpts{
Expand Down Expand Up @@ -210,6 +231,32 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
hash5 ◯ commit5
`),
},
{
testName: "showing graph with custom formatting",
commitOpts: []models.NewCommitOpts{
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2", "hash3"}},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
{Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}},
{Name: "commit5", Hash: "hash5", Parents: []string{"hash7"}},
},
startIdx: 0,
endIdx: 5,
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
setupConfig: func(c *common.Common) {
c.UserConfig().Git.Log.CustomPaneLogFormat = "%h %g"
},
expected: formatExpected(`
hash1 ⏣─╮
hash2 ◯ │
hash3 ◯─╯
hash4 ◯
hash5 ◯
`),
},
{
testName: "showing graph, including rebase commits",
commitOpts: []models.NewCommitOpts{
Expand Down Expand Up @@ -540,16 +587,20 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
}
}

common := common.NewDummyCommon()

for _, s := range scenarios {
if !focusing || s.focus {
t.Run(s.testName, func(t *testing.T) {
common := common.NewDummyCommon()

hashPool := &utils.StringPool{}

commits := lo.Map(s.commitOpts,
func(opts models.NewCommitOpts, _ int) *models.Commit { return models.NewCommit(hashPool, opts) })

if s.setupConfig != nil {
s.setupConfig(common)
}

result := GetCommitListDisplayStrings(
common,
commits,
Expand Down
5 changes: 5 additions & 0 deletions schema-master/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,11 @@
"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
},
"customPaneLogFormat": {
"type": "string",
"description": "Custom format for the commit list side panel.\nSupports placeholders like:\n %h short hash %s subject\n %an author name %as short author\n %g graph line %d decorations (tags/branches/markers)\n %a action %cd date\nDefault: \"%h %a %as %g %d %s\".",
"default": "%h %a %as %g %d %s"
}
},
"additionalProperties": false,
Expand Down