mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-03 13:21:56 +02:00
Merge pull request #1904 from jesseduffield/yank-author
This commit is contained in:
commit
f143d04d87
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-errors/errors"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,6 +81,27 @@ func (self *CommitCommands) GetCommitDiff(commitSha string) (string, error) {
|
|||||||
return diff, err
|
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) {
|
func (self *CommitCommands) GetCommitMessageFirstLine(sha string) (string, error) {
|
||||||
return self.GetCommitMessagesFirstLine([]string{sha})
|
return self.GetCommitMessagesFirstLine([]string{sha})
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ type Commit struct {
|
|||||||
Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
|
Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup"
|
||||||
Tags []string
|
Tags []string
|
||||||
ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2'
|
ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2'
|
||||||
Author string
|
Author string // something like 'Jesse Duffield <jessedduffield@gmail.com>'
|
||||||
UnixTimestamp int64
|
UnixTimestamp int64
|
||||||
|
|
||||||
// SHAs of parent commits (will be multiple if it's a merge commit)
|
// SHAs of parent commits (will be multiple if it's a merge commit)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
@ -126,6 +128,13 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e
|
|||||||
},
|
},
|
||||||
Key: 'm',
|
Key: 'm',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
DisplayString: self.c.Tr.LcCommitAuthor,
|
||||||
|
OnPress: func() error {
|
||||||
|
return self.copyAuthorToClipboard(commit)
|
||||||
|
},
|
||||||
|
Key: 'a',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -170,6 +179,23 @@ func (self *BasicCommitsController) copyCommitDiffToClipboard(commit *models.Com
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *BasicCommitsController) copyAuthorToClipboard(commit *models.Commit) error {
|
||||||
|
author, err := self.git.Commit.GetCommitAuthor(commit.Sha)
|
||||||
|
if err != nil {
|
||||||
|
return self.c.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
formattedAuthor := fmt.Sprintf("%s <%s>", author.Name, author.Email)
|
||||||
|
|
||||||
|
self.c.LogAction(self.c.Tr.Actions.CopyCommitAuthorToClipboard)
|
||||||
|
if err := self.os.CopyToClipboard(formattedAuthor); err != nil {
|
||||||
|
return self.c.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
self.c.Toast(self.c.Tr.CommitAuthorCopiedToClipboard)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (self *BasicCommitsController) copyCommitMessageToClipboard(commit *models.Commit) error {
|
func (self *BasicCommitsController) copyCommitMessageToClipboard(commit *models.Commit) error {
|
||||||
message, err := self.git.Commit.GetCommitMessage(commit.Sha)
|
message, err := self.git.Commit.GetCommitMessage(commit.Sha)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -379,6 +379,7 @@ type TranslationSet struct {
|
|||||||
LcCommitURL string
|
LcCommitURL string
|
||||||
LcCopyCommitMessageToClipboard string
|
LcCopyCommitMessageToClipboard string
|
||||||
LcCommitMessage string
|
LcCommitMessage string
|
||||||
|
LcCommitAuthor string
|
||||||
LcCopyCommitAttributeToClipboard string
|
LcCopyCommitAttributeToClipboard string
|
||||||
LcCopyBranchNameToClipboard string
|
LcCopyBranchNameToClipboard string
|
||||||
LcCopyFileNameToClipboard string
|
LcCopyFileNameToClipboard string
|
||||||
@ -435,6 +436,7 @@ type TranslationSet struct {
|
|||||||
CommitSHACopiedToClipboard string
|
CommitSHACopiedToClipboard string
|
||||||
CommitURLCopiedToClipboard string
|
CommitURLCopiedToClipboard string
|
||||||
CommitMessageCopiedToClipboard string
|
CommitMessageCopiedToClipboard string
|
||||||
|
CommitAuthorCopiedToClipboard string
|
||||||
LcCopiedToClipboard string
|
LcCopiedToClipboard string
|
||||||
ErrCannotEditDirectory string
|
ErrCannotEditDirectory string
|
||||||
ErrStageDirWithInlineMergeConflicts string
|
ErrStageDirWithInlineMergeConflicts string
|
||||||
@ -526,6 +528,7 @@ type Actions struct {
|
|||||||
CopyCommitDiffToClipboard string
|
CopyCommitDiffToClipboard string
|
||||||
CopyCommitSHAToClipboard string
|
CopyCommitSHAToClipboard string
|
||||||
CopyCommitURLToClipboard string
|
CopyCommitURLToClipboard string
|
||||||
|
CopyCommitAuthorToClipboard string
|
||||||
CopyCommitAttributeToClipboard string
|
CopyCommitAttributeToClipboard string
|
||||||
CustomCommand string
|
CustomCommand string
|
||||||
DiscardAllChangesInDirectory string
|
DiscardAllChangesInDirectory string
|
||||||
@ -980,6 +983,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
LcCommitURL: "commit URL",
|
LcCommitURL: "commit URL",
|
||||||
LcCopyCommitMessageToClipboard: "copy commit message to clipboard",
|
LcCopyCommitMessageToClipboard: "copy commit message to clipboard",
|
||||||
LcCommitMessage: "commit message",
|
LcCommitMessage: "commit message",
|
||||||
|
LcCommitAuthor: "commit author",
|
||||||
LcCopyCommitAttributeToClipboard: "copy commit attribute",
|
LcCopyCommitAttributeToClipboard: "copy commit attribute",
|
||||||
LcCopyBranchNameToClipboard: "copy branch name to clipboard",
|
LcCopyBranchNameToClipboard: "copy branch name to clipboard",
|
||||||
LcCopyFileNameToClipboard: "copy the file name to the clipboard",
|
LcCopyFileNameToClipboard: "copy the file name to the clipboard",
|
||||||
@ -1035,6 +1039,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
CommitSHACopiedToClipboard: "Commit SHA copied to clipboard",
|
CommitSHACopiedToClipboard: "Commit SHA copied to clipboard",
|
||||||
CommitURLCopiedToClipboard: "Commit URL copied to clipboard",
|
CommitURLCopiedToClipboard: "Commit URL copied to clipboard",
|
||||||
CommitMessageCopiedToClipboard: "Commit message copied to clipboard",
|
CommitMessageCopiedToClipboard: "Commit message copied to clipboard",
|
||||||
|
CommitAuthorCopiedToClipboard: "Commit author copied to clipboard",
|
||||||
LcCopiedToClipboard: "copied to clipboard",
|
LcCopiedToClipboard: "copied to clipboard",
|
||||||
ErrCannotEditDirectory: "Cannot edit directory: you can only edit individual files",
|
ErrCannotEditDirectory: "Cannot edit directory: you can only edit individual files",
|
||||||
ErrStageDirWithInlineMergeConflicts: "Cannot stage/unstage directory containing files with inline merge conflicts. Please fix up the merge conflicts first",
|
ErrStageDirWithInlineMergeConflicts: "Cannot stage/unstage directory containing files with inline merge conflicts. Please fix up the merge conflicts first",
|
||||||
@ -1107,6 +1112,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
CopyCommitDiffToClipboard: "Copy commit diff to clipboard",
|
CopyCommitDiffToClipboard: "Copy commit diff to clipboard",
|
||||||
CopyCommitSHAToClipboard: "Copy commit SHA to clipboard",
|
CopyCommitSHAToClipboard: "Copy commit SHA to clipboard",
|
||||||
CopyCommitURLToClipboard: "Copy commit URL to clipboard",
|
CopyCommitURLToClipboard: "Copy commit URL to clipboard",
|
||||||
|
CopyCommitAuthorToClipboard: "Copy commit author to clipboard",
|
||||||
CopyCommitAttributeToClipboard: "Copy to clipboard",
|
CopyCommitAttributeToClipboard: "Copy to clipboard",
|
||||||
MoveCommitUp: "Move commit up",
|
MoveCommitUp: "Move commit up",
|
||||||
MoveCommitDown: "Move commit down",
|
MoveCommitDown: "Move commit down",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user