diff --git a/docs/keybindings/Keybindings_en.md b/docs/keybindings/Keybindings_en.md index 6f8c12966..65f217f73 100644 --- a/docs/keybindings/Keybindings_en.md +++ b/docs/keybindings/Keybindings_en.md @@ -155,7 +155,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct g: reset to this commit space: checkout commit T: tag commit - ctrl+y: copy commit message to clipboard + y: copy commit attribute o: open commit in browser enter: view selected item's files diff --git a/docs/keybindings/Keybindings_nl.md b/docs/keybindings/Keybindings_nl.md index c0accbd44..bec3e35ad 100644 --- a/docs/keybindings/Keybindings_nl.md +++ b/docs/keybindings/Keybindings_nl.md @@ -195,7 +195,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct g: reset naar deze commit space: checkout commit T: tag commit - ctrl+y: kopieer commit bericht naar klembord + y: copy commit attribute o: open commit in browser enter: bekijk gecommite bestanden diff --git a/docs/keybindings/Keybindings_pl.md b/docs/keybindings/Keybindings_pl.md index 9c619f6b6..3e9443b4e 100644 --- a/docs/keybindings/Keybindings_pl.md +++ b/docs/keybindings/Keybindings_pl.md @@ -68,7 +68,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct g: zresetuj do tego commita space: checkout commit T: tag commit - ctrl+y: copy commit message to clipboard + y: copy commit attribute o: open commit in browser enter: przeglądaj pliki commita diff --git a/docs/keybindings/Keybindings_zh.md b/docs/keybindings/Keybindings_zh.md index 408bfe90f..ba672a858 100644 --- a/docs/keybindings/Keybindings_zh.md +++ b/docs/keybindings/Keybindings_zh.md @@ -207,8 +207,8 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct g: 重置为此提交 space: 检出提交 T: 标签提交 - ctrl+y: 将提交消息复制到剪贴板 - o: 在浏览器中打开提交 + y: copy commit attribute + o: open commit in browser enter: 查看提交的文件 diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 75256878f..1e0a442f2 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -74,6 +74,12 @@ func (self *CommitCommands) GetCommitMessage(commitSha string) (string, error) { return strings.TrimSpace(message), err } +func (self *CommitCommands) GetCommitDiff(commitSha string) (string, error) { + cmdStr := "git show --no-color " + commitSha + diff, err := self.cmd.New(cmdStr).DontLog().RunWithOutput() + return diff, err +} + func (self *CommitCommands) GetCommitMessageFirstLine(sha string) (string, error) { return self.GetCommitMessagesFirstLine([]string{sha}) } diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 51f443243..988673f1e 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -229,28 +229,28 @@ type KeybindingBranchesConfig struct { } type KeybindingCommitsConfig struct { - SquashDown string `yaml:"squashDown"` - RenameCommit string `yaml:"renameCommit"` - RenameCommitWithEditor string `yaml:"renameCommitWithEditor"` - ViewResetOptions string `yaml:"viewResetOptions"` - MarkCommitAsFixup string `yaml:"markCommitAsFixup"` - CreateFixupCommit string `yaml:"createFixupCommit"` - SquashAboveCommits string `yaml:"squashAboveCommits"` - MoveDownCommit string `yaml:"moveDownCommit"` - MoveUpCommit string `yaml:"moveUpCommit"` - AmendToCommit string `yaml:"amendToCommit"` - PickCommit string `yaml:"pickCommit"` - RevertCommit string `yaml:"revertCommit"` - CherryPickCopy string `yaml:"cherryPickCopy"` - CherryPickCopyRange string `yaml:"cherryPickCopyRange"` - PasteCommits string `yaml:"pasteCommits"` - TagCommit string `yaml:"tagCommit"` - CheckoutCommit string `yaml:"checkoutCommit"` - ResetCherryPick string `yaml:"resetCherryPick"` - CopyCommitMessageToClipboard string `yaml:"copyCommitMessageToClipboard"` - OpenLogMenu string `yaml:"openLogMenu"` - OpenInBrowser string `yaml:"openInBrowser"` - ViewBisectOptions string `yaml:"viewBisectOptions"` + SquashDown string `yaml:"squashDown"` + RenameCommit string `yaml:"renameCommit"` + RenameCommitWithEditor string `yaml:"renameCommitWithEditor"` + ViewResetOptions string `yaml:"viewResetOptions"` + MarkCommitAsFixup string `yaml:"markCommitAsFixup"` + CreateFixupCommit string `yaml:"createFixupCommit"` + SquashAboveCommits string `yaml:"squashAboveCommits"` + MoveDownCommit string `yaml:"moveDownCommit"` + MoveUpCommit string `yaml:"moveUpCommit"` + AmendToCommit string `yaml:"amendToCommit"` + PickCommit string `yaml:"pickCommit"` + RevertCommit string `yaml:"revertCommit"` + CherryPickCopy string `yaml:"cherryPickCopy"` + CherryPickCopyRange string `yaml:"cherryPickCopyRange"` + PasteCommits string `yaml:"pasteCommits"` + TagCommit string `yaml:"tagCommit"` + CheckoutCommit string `yaml:"checkoutCommit"` + ResetCherryPick string `yaml:"resetCherryPick"` + CopyCommitAttributeToClipboard string `yaml:"copyCommitAttributeToClipboard"` + OpenLogMenu string `yaml:"openLogMenu"` + OpenInBrowser string `yaml:"openInBrowser"` + ViewBisectOptions string `yaml:"viewBisectOptions"` } type KeybindingStashConfig struct { @@ -496,28 +496,28 @@ func GetDefaultConfig() *UserConfig { FetchRemote: "f", }, Commits: KeybindingCommitsConfig{ - SquashDown: "s", - RenameCommit: "r", - RenameCommitWithEditor: "R", - ViewResetOptions: "g", - MarkCommitAsFixup: "f", - CreateFixupCommit: "F", - SquashAboveCommits: "S", - MoveDownCommit: "", - MoveUpCommit: "", - AmendToCommit: "A", - PickCommit: "p", - RevertCommit: "t", - CherryPickCopy: "c", - CherryPickCopyRange: "C", - PasteCommits: "v", - TagCommit: "T", - CheckoutCommit: "", - ResetCherryPick: "", - CopyCommitMessageToClipboard: "", - OpenLogMenu: "", - OpenInBrowser: "o", - ViewBisectOptions: "b", + SquashDown: "s", + RenameCommit: "r", + RenameCommitWithEditor: "R", + ViewResetOptions: "g", + MarkCommitAsFixup: "f", + CreateFixupCommit: "F", + SquashAboveCommits: "S", + MoveDownCommit: "", + MoveUpCommit: "", + AmendToCommit: "A", + PickCommit: "p", + RevertCommit: "t", + CherryPickCopy: "c", + CherryPickCopyRange: "C", + PasteCommits: "v", + TagCommit: "T", + CheckoutCommit: "", + ResetCherryPick: "", + CopyCommitAttributeToClipboard: "y", + OpenLogMenu: "", + OpenInBrowser: "o", + ViewBisectOptions: "b", }, Stash: KeybindingStashConfig{ PopStash: "g", diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 45c65e7ee..2c3618b82 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -165,9 +165,10 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [ Description: self.c.Tr.LcTagCommit, }, { - Key: opts.GetKey(opts.Config.Commits.CopyCommitMessageToClipboard), - Handler: self.checkSelected(self.copyCommitMessageToClipboard), - Description: self.c.Tr.LcCopyCommitMessageToClipboard, + Key: opts.GetKey(opts.Config.Commits.CopyCommitAttributeToClipboard), + Handler: self.checkSelected(self.copyCommitAttribute), + Description: self.c.Tr.LcCopyCommitAttributeToClipboard, + OpensMenu: true, }, { Key: opts.GetKey(opts.Config.Commits.OpenInBrowser), @@ -599,6 +600,78 @@ func (self *LocalCommitsController) gotoBottom() error { return nil } +func (self *LocalCommitsController) copyCommitAttribute(commit *models.Commit) error { + return self.c.Menu(types.CreateMenuOptions{ + Title: self.c.Tr.Actions.CopyCommitAttributeToClipboard, + Items: []*types.MenuItem{ + { + DisplayString: self.c.Tr.LcCommitSha, + OnPress: func() error { + return self.copyCommitSHAToClipboard(commit) + }, + }, + { + DisplayString: self.c.Tr.LcCommitURL, + OnPress: func() error { + return self.copyCommitURLToClipboard(commit) + }, + }, + { + DisplayString: self.c.Tr.LcCommitDiff, + OnPress: func() error { + return self.copyCommitDiffToClipboard(commit) + }, + }, + { + DisplayString: self.c.Tr.LcCommitMessage, + OnPress: func() error { + return self.copyCommitMessageToClipboard(commit) + }, + }, + }, + }) +} + +func (self *LocalCommitsController) copyCommitSHAToClipboard(commit *models.Commit) error { + self.c.LogAction(self.c.Tr.Actions.CopyCommitSHAToClipboard) + if err := self.os.CopyToClipboard(commit.Sha); err != nil { + return self.c.Error(err) + } + + self.c.Toast(self.c.Tr.CommitSHACopiedToClipboard) + return nil +} + +func (self *LocalCommitsController) copyCommitURLToClipboard(commit *models.Commit) error { + url, err := self.helpers.Host.GetCommitURL(commit.Sha) + if err != nil { + return err + } + + self.c.LogAction(self.c.Tr.Actions.CopyCommitURLToClipboard) + if err := self.os.CopyToClipboard(url); err != nil { + return self.c.Error(err) + } + + self.c.Toast(self.c.Tr.CommitURLCopiedToClipboard) + return nil +} + +func (self *LocalCommitsController) copyCommitDiffToClipboard(commit *models.Commit) error { + diff, err := self.git.Commit.GetCommitDiff(commit.Sha) + if err != nil { + return self.c.Error(err) + } + + self.c.LogAction(self.c.Tr.Actions.CopyCommitDiffToClipboard) + if err := self.os.CopyToClipboard(diff); err != nil { + return self.c.Error(err) + } + + self.c.Toast(self.c.Tr.CommitDiffCopiedToClipboard) + return nil +} + func (self *LocalCommitsController) copyCommitMessageToClipboard(commit *models.Commit) error { message, err := self.git.Commit.GetCommitMessage(commit.Sha) if err != nil { @@ -611,7 +684,6 @@ func (self *LocalCommitsController) copyCommitMessageToClipboard(commit *models. } self.c.Toast(self.c.Tr.CommitMessageCopiedToClipboard) - return nil } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 4724abcab..04e948380 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -362,8 +362,13 @@ type TranslationSet struct { LcOpenDiffingMenu string LcOpenExtrasMenu string LcShowingGitDiff string + LcCommitDiff string LcCopyCommitShaToClipboard string + LcCommitSha string + LcCommitURL string LcCopyCommitMessageToClipboard string + LcCommitMessage string + LcCopyCommitAttributeToClipboard string LcCopyBranchNameToClipboard string LcCopyFileNameToClipboard string LcCopyCommitFileNameToClipboard string @@ -415,6 +420,9 @@ type TranslationSet struct { ExtrasTitle string PushingTagStatus string PullRequestURLCopiedToClipboard string + CommitDiffCopiedToClipboard string + CommitSHACopiedToClipboard string + CommitURLCopiedToClipboard string CommitMessageCopiedToClipboard string LcCopiedToClipboard string ErrCannotEditDirectory string @@ -505,6 +513,10 @@ type Actions struct { MoveCommitUp string MoveCommitDown string CopyCommitMessageToClipboard string + CopyCommitDiffToClipboard string + CopyCommitSHAToClipboard string + CopyCommitURLToClipboard string + CopyCommitAttributeToClipboard string CustomCommand string DiscardAllChangesInDirectory string DiscardUnstagedChangesInDirectory string @@ -941,8 +953,13 @@ func EnglishTranslationSet() TranslationSet { // the actual view is the extras view which I intend to give more tabs in future but for now we'll only mention the command log part LcOpenExtrasMenu: "open command log menu", LcShowingGitDiff: "showing output for:", + LcCommitDiff: "commit diff", LcCopyCommitShaToClipboard: "copy commit SHA to clipboard", + LcCommitSha: "commit SHA", + LcCommitURL: "commit URL", LcCopyCommitMessageToClipboard: "copy commit message to clipboard", + LcCommitMessage: "commit message", + LcCopyCommitAttributeToClipboard: "copy commit attribute", LcCopyBranchNameToClipboard: "copy branch name to clipboard", LcCopyFileNameToClipboard: "copy the file name to the clipboard", LcCopyCommitFileNameToClipboard: "copy the committed file name to the clipboard", @@ -993,6 +1010,9 @@ func EnglishTranslationSet() TranslationSet { ExtrasTitle: "Extras", PushingTagStatus: "pushing tag", PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard", + CommitDiffCopiedToClipboard: "Commit diff copied to clipboard", + CommitSHACopiedToClipboard: "Commit SHA copied to clipboard", + CommitURLCopiedToClipboard: "Commit URL copied to clipboard", CommitMessageCopiedToClipboard: "Commit message copied to clipboard", LcCopiedToClipboard: "copied to clipboard", ErrCannotEditDirectory: "Cannot edit directory: you can only edit individual files", @@ -1064,6 +1084,10 @@ func EnglishTranslationSet() TranslationSet { CreateLightweightTag: "Create lightweight tag", CreateAnnotatedTag: "Create annotated tag", CopyCommitMessageToClipboard: "Copy commit message to clipboard", + CopyCommitDiffToClipboard: "Copy commit diff to clipboard", + CopyCommitSHAToClipboard: "Copy commit SHA to clipboard", + CopyCommitURLToClipboard: "Copy commit URL to clipboard", + CopyCommitAttributeToClipboard: "Copy to clipboard", MoveCommitUp: "Move commit up", MoveCommitDown: "Move commit down", CustomCommand: "Custom command",