From 4dd09ee0d58a508e80e676e0f00e96f6a37f3689 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 1 May 2022 14:14:29 +1000 Subject: allow copying commit author to clipboard --- pkg/commands/git_commands/commit.go | 22 ++++++++++++++++++++++ pkg/commands/models/commit.go | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'pkg/commands') 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 ' UnixTimestamp int64 // SHAs of parent commits (will be multiple if it's a merge commit) -- cgit v1.2.3