summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-05-01 14:14:29 +1000
committerJesse Duffield <jessedduffield@gmail.com>2022-05-01 14:14:29 +1000
commit4dd09ee0d58a508e80e676e0f00e96f6a37f3689 (patch)
tree8d21f0a04cc2999353a7f1152b8f6118e8dd45f5 /pkg/commands
parentd85f4792af2a760fe07251e66e286e5a6929c26d (diff)
allow copying commit author to clipboard
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git_commands/commit.go22
-rw-r--r--pkg/commands/models/commit.go2
2 files changed, 23 insertions, 1 deletions
diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go
index 1e0a442f2..8d673ee2c 100644
--- a/pkg/commands/git_commands/commit.go
+++ b/pkg/commands/git_commands/commit.go
@@ -4,6 +4,7 @@ import (
"fmt"
"strings"
+ "github.com/go-errors/errors"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
)
@@ -80,6 +81,27 @@ func (self *CommitCommands) GetCommitDiff(commitSha string) (string, error) {
return diff, err
}
+type Author struct {
+ Name string
+ Email string
+}
+
+func (self *CommitCommands) GetCommitAuthor(commitSha string) (Author, error) {
+ cmdStr := "git show --no-patch --pretty=format:'%an|%ae' " + commitSha
+ output, err := self.cmd.New(cmdStr).DontLog().RunWithOutput()
+ if err != nil {
+ return Author{}, err
+ }
+
+ split := strings.Split(strings.TrimSpace(output), "|")
+ if len(split) < 2 {
+ return Author{}, errors.New("unexpected git output")
+ }
+
+ author := Author{Name: split[0], Email: split[1]}
+ return author, err
+}
+
func (self *CommitCommands) GetCommitMessageFirstLine(sha string) (string, error) {
return self.GetCommitMessagesFirstLine([]string{sha})
}
diff --git a/pkg/commands/models/commit.go b/pkg/commands/models/commit.go
index da992f65a..641cc4242 100644
--- a/pkg/commands/models/commit.go
+++ b/pkg/commands/models/commit.go
@@ -17,7 +17,7 @@ type Commit struct {
Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
Tags []string
ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2'
- Author string
+ Author string // something like 'Jesse Duffield <jessedduffield@gmail.com>'
UnixTimestamp int64
// SHAs of parent commits (will be multiple if it's a merge commit)