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
5 changes: 5 additions & 0 deletions docs-master/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ gui:
# If true, show commit hashes alongside branch names in the branches view.
showBranchCommitHash: false

# If true, show GPG signature verification status for each commit in the
# commits view. This can slow down commit loading as it requires GPG
# verification.
showGpgSigningStatus: false

# Whether to show the divergence from the base branch in the branches view.
# One of: 'none' | 'onlyArrow' | 'arrowAndNumber'
showDivergenceFromBaseBranch: none
Expand Down
37 changes: 29 additions & 8 deletions pkg/commands/git_commands/commit_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,16 @@ func (self *CommitLoader) MergeRebasingCommits(hashPool *utils.StringPool, commi
// example input:
// 8ad01fe32fcc20f07bc6693f87aa4977c327f1e1|10 hours ago|Jesse Duffield| (HEAD -> master, tag: v0.15.2)|refresh commits when adding a tag
func (self *CommitLoader) extractCommitFromLine(hashPool *utils.StringPool, line string, showDivergence bool) *models.Commit {
split := strings.SplitN(line, "\x00", 8)
showGpg := self.UserConfig().Gui.ShowGpgSigningStatus
numFields := 8
if showGpg {
numFields = 9
}
split := strings.SplitN(line, "\x00", numFields)

// Ensure we have the minimum required fields (at least 7 for basic functionality)
if len(split) < 7 {
self.Log.Warnf("Malformed git log line: expected at least 7 fields, got %d. Line: %s", len(split), line)
minFields := 7
if len(split) < minFields {
self.Log.Warnf("Malformed git log line: expected at least %d fields, got %d. Line: %s", minFields, len(split), line)
return nil
}

Expand All @@ -209,10 +214,18 @@ func (self *CommitLoader) extractCommitFromLine(hashPool *utils.StringPool, line
}
extraInfo := strings.TrimSpace(split[6])

// message (and the \x00 before it) might not be present if extraInfo is extremely long
gpgStatus := ""
messageIdx := 7
if showGpg {
if len(split) > 7 {
gpgStatus = split[7]
}
messageIdx = 8
}

message := ""
if len(split) > 7 {
message = split[7]
if len(split) > messageIdx {
message = split[messageIdx]
}

var tags []string
Expand Down Expand Up @@ -248,6 +261,7 @@ func (self *CommitLoader) extractCommitFromLine(hashPool *utils.StringPool, line
AuthorEmail: authorEmail,
Parents: parents,
Divergence: divergence,
GpgStatus: gpgStatus,
})
}

Expand Down Expand Up @@ -586,12 +600,18 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) *oscommands.CmdObj {
refSpec += "..." + opts.RefToShowDivergenceFrom
}

showGpg := self.UserConfig().Gui.ShowGpgSigningStatus
format := prettyFormat
if showGpg {
format = prettyFormatWithGpg
}

cmdArgs := NewGitCmd("log").
Arg(refSpec).
ArgIf(gitLogOrder != "default", "--"+gitLogOrder).
ArgIf(opts.All, "--all").
Arg("--oneline").
Arg(prettyFormat).
Arg(format).
Arg("--abbrev=40").
ArgIf(opts.FilterAuthor != "", "--author="+opts.FilterAuthor).
ArgIf(opts.Limit, "-300").
Expand All @@ -606,3 +626,4 @@ func (self *CommitLoader) getLogCmd(opts GetCommitsOptions) *oscommands.CmdObj {
}

const prettyFormat = `--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%s`
const prettyFormatWithGpg = `--pretty=format:+%H%x00%at%x00%aN%x00%ae%x00%P%x00%m%x00%D%x00%G?%x00%s`
6 changes: 6 additions & 0 deletions pkg/commands/models/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ type Commit struct {
Action todo.TodoCommand
ActionFlag string // e.g. "-C" for fixup -C
Divergence Divergence // set to DivergenceNone unless we are showing the divergence view

// GPG signature status: "G" good, "B" bad, "U" unknown validity,
// "X" expired, "Y" expired key, "R" revoked, "E" missing key, "N" none
GpgStatus string
}

type NewCommitOpts struct {
Expand All @@ -77,6 +81,7 @@ type NewCommitOpts struct {
UnixTimestamp int64
Divergence Divergence
Parents []string
GpgStatus string
}

func NewCommit(hashPool *utils.StringPool, opts NewCommitOpts) *Commit {
Expand All @@ -93,6 +98,7 @@ func NewCommit(hashPool *utils.StringPool, opts NewCommitOpts) *Commit {
UnixTimestamp: opts.UnixTimestamp,
Divergence: opts.Divergence,
parents: lo.Map(opts.Parents, func(s string, _ int) *string { return hashPool.Add(s) }),
GpgStatus: opts.GpgStatus,
}
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ type GuiConfig struct {
CommitHashLength int `yaml:"commitHashLength" jsonschema:"minimum=0"`
// If true, show commit hashes alongside branch names in the branches view.
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
// If true, show GPG signature verification status for each commit in the commits view. This can slow down commit loading as it requires GPG verification.
ShowGpgSigningStatus bool `yaml:"showGpgSigningStatus"`
// Whether to show the divergence from the base branch in the branches view.
// One of: 'none' | 'onlyArrow' | 'arrowAndNumber'
ShowDivergenceFromBaseBranch string `yaml:"showDivergenceFromBaseBranch" jsonschema:"enum=none,enum=onlyArrow,enum=arrowAndNumber"`
Expand Down Expand Up @@ -804,6 +806,7 @@ func GetDefaultConfig() *UserConfig {
CommitAuthorLongLength: 17,
CommitHashLength: 8,
ShowBranchCommitHash: false,
ShowGpgSigningStatus: false,
ShowDivergenceFromBaseBranch: "none",
CommandLogSize: 8,
SplitDiff: "auto",
Expand Down
17 changes: 16 additions & 1 deletion pkg/gui/presentation/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,20 @@ func displayCommit(
actionString = actionColorMap(commit.Action, commit.Status).Sprint(actionStr)
}

gpgString := ""
if common.UserConfig().Gui.ShowGpgSigningStatus {
switch commit.GpgStatus {
case "G", "U":
gpgString = style.FgGreen.Sprint("✓")
case "B", "R", "X", "Y":
gpgString = style.FgRed.Sprint("✗")
case "E":
gpgString = style.FgYellow.Sprint("~")
default:
gpgString = style.FgBlue.Sprint("-")
}
}

tagString := ""
if fullDescription {
if commit.ExtraInfo != "" {
Expand Down Expand Up @@ -439,11 +453,12 @@ func displayCommit(
}
author := authors.AuthorWithLength(commit.AuthorName, authorLength)

cols := make([]string, 0, 7)
cols := make([]string, 0, 8)
cols = append(
cols,
divergenceString,
hashString,
gpgString,
bisectString,
descriptionString,
actionString,
Expand Down
5 changes: 5 additions & 0 deletions schema-master/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@
"description": "If true, show commit hashes alongside branch names in the branches view.",
"default": false
},
"showGpgSigningStatus": {
"type": "boolean",
"description": "If true, show GPG signature verification status for each commit in the commits view. This can slow down commit loading as it requires GPG verification.",
"default": false
},
"showDivergenceFromBaseBranch": {
"type": "string",
"enum": [
Expand Down
Loading