allow copying commit author to clipboard

This commit is contained in:
Jesse Duffield 2022-05-01 14:14:29 +10:00
parent d85f4792af
commit 4dd09ee0d5
4 changed files with 55 additions and 1 deletions

View file

@ -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})
}