mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
committed by
Stefan Haller
parent
68edfa20b4
commit
d146d834c2
@ -238,6 +238,13 @@ func (self *CommitsHelper) OpenCommitMenu(suggestionFunc func(string) []*types.S
|
||||
},
|
||||
Key: 'c',
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.PasteCommitMessageFromClipboard,
|
||||
OnPress: func() error {
|
||||
return self.pasteCommitMessageFromClipboard()
|
||||
},
|
||||
Key: 'p',
|
||||
},
|
||||
}
|
||||
return self.c.Menu(types.CreateMenuOptions{
|
||||
Title: self.c.Tr.CommitMenuTitle,
|
||||
@ -257,3 +264,28 @@ func (self *CommitsHelper) addCoAuthor(suggestionFunc func(string) []*types.Sugg
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (self *CommitsHelper) pasteCommitMessageFromClipboard() error {
|
||||
message, err := self.c.OS().PasteFromClipboard()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if message == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if currentMessage := self.JoinCommitMessageAndUnwrappedDescription(); currentMessage == "" {
|
||||
self.SetMessageAndDescriptionInView(message)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Confirm before overwriting the commit message
|
||||
return self.c.Confirm(types.ConfirmOpts{
|
||||
Title: self.c.Tr.PasteCommitMessageFromClipboard,
|
||||
Prompt: self.c.Tr.SurePasteCommitMessage,
|
||||
HandleConfirm: func() error {
|
||||
self.SetMessageAndDescriptionInView(message)
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -582,6 +582,8 @@ type TranslationSet struct {
|
||||
CommitHash string
|
||||
CommitURL string
|
||||
CopyCommitMessageToClipboard string
|
||||
PasteCommitMessageFromClipboard string
|
||||
SurePasteCommitMessage string
|
||||
CommitMessage string
|
||||
CommitSubject string
|
||||
CommitAuthor string
|
||||
@ -1553,6 +1555,8 @@ func EnglishTranslationSet() *TranslationSet {
|
||||
CommitHash: "Commit hash",
|
||||
CommitURL: "Commit URL",
|
||||
CopyCommitMessageToClipboard: "Copy commit message to clipboard",
|
||||
PasteCommitMessageFromClipboard: "Paste commit message from clipboard",
|
||||
SurePasteCommitMessage: "Pasting will overwrite the current commit message, continue?",
|
||||
CommitMessage: "Commit message",
|
||||
CommitSubject: "Commit subject",
|
||||
CommitAuthor: "Commit author",
|
||||
|
49
pkg/integration/tests/commit/paste_commit_message.go
Normal file
49
pkg/integration/tests/commit/paste_commit_message.go
Normal file
@ -0,0 +1,49 @@
|
||||
package commit
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var PasteCommitMessage = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Paste a commit message into the commit message panel",
|
||||
ExtraCmdArgs: []string{},
|
||||
Skip: false,
|
||||
SetupConfig: func(config *config.AppConfig) {
|
||||
config.UserConfig.OS.CopyToClipboardCmd = "echo {{text}} > ../clipboard"
|
||||
config.UserConfig.OS.ReadFromClipboardCmd = "cat ../clipboard"
|
||||
},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.EmptyCommit("subject\n\nbody 1st line\nbody 2nd line")
|
||||
shell.CreateFileAndAdd("file", "file content")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Commits().
|
||||
Focus().
|
||||
ContainsLines(
|
||||
Contains("subject").IsSelected(),
|
||||
).
|
||||
Press(keys.Commits.CopyCommitAttributeToClipboard)
|
||||
|
||||
t.ExpectPopup().Menu().Title(Equals("Copy to clipboard")).
|
||||
Select(Contains("Commit message")).Confirm()
|
||||
|
||||
t.ExpectToast(Equals("Commit message copied to clipboard"))
|
||||
|
||||
t.Views().Files().
|
||||
Focus().
|
||||
Press(keys.Files.CommitChanges)
|
||||
|
||||
t.ExpectPopup().CommitMessagePanel().
|
||||
OpenCommitMenu()
|
||||
|
||||
t.ExpectPopup().Menu().Title(Equals("Commit Menu")).
|
||||
Select(Contains("Paste commit message from clipboard")).
|
||||
Confirm()
|
||||
|
||||
t.ExpectPopup().CommitMessagePanel().
|
||||
Content(Equals("subject")).
|
||||
SwitchToDescription().
|
||||
Content(Equals("body 1st line\nbody 2nd line"))
|
||||
},
|
||||
})
|
@ -0,0 +1,54 @@
|
||||
package commit
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var PasteCommitMessageOverExisting = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Paste a commit message into the commit message panel when there is already text in the panel, causing a confirmation",
|
||||
ExtraCmdArgs: []string{},
|
||||
Skip: false,
|
||||
SetupConfig: func(config *config.AppConfig) {
|
||||
config.UserConfig.OS.CopyToClipboardCmd = "echo {{text}} > ../clipboard"
|
||||
config.UserConfig.OS.ReadFromClipboardCmd = "cat ../clipboard"
|
||||
},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.EmptyCommit("subject\n\nbody 1st line\nbody 2nd line")
|
||||
shell.CreateFileAndAdd("file", "file content")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Commits().
|
||||
Focus().
|
||||
ContainsLines(
|
||||
Contains("subject").IsSelected(),
|
||||
).
|
||||
Press(keys.Commits.CopyCommitAttributeToClipboard)
|
||||
|
||||
t.ExpectPopup().Menu().Title(Equals("Copy to clipboard")).
|
||||
Select(Contains("Commit message")).Confirm()
|
||||
|
||||
t.ExpectToast(Equals("Commit message copied to clipboard"))
|
||||
|
||||
t.Views().Files().
|
||||
Focus().
|
||||
Press(keys.Files.CommitChanges)
|
||||
|
||||
t.ExpectPopup().CommitMessagePanel().
|
||||
Type("existing message").
|
||||
OpenCommitMenu()
|
||||
|
||||
t.ExpectPopup().Menu().Title(Equals("Commit Menu")).
|
||||
Select(Contains("Paste commit message from clipboard")).
|
||||
Confirm()
|
||||
|
||||
t.ExpectPopup().Alert().Title(Equals("Paste commit message from clipboard")).
|
||||
Content(Equals("Pasting will overwrite the current commit message, continue?")).
|
||||
Confirm()
|
||||
|
||||
t.ExpectPopup().CommitMessagePanel().
|
||||
Content(Equals("subject")).
|
||||
SwitchToDescription().
|
||||
Content(Equals("body 1st line\nbody 2nd line"))
|
||||
},
|
||||
})
|
@ -89,6 +89,8 @@ var tests = []*components.IntegrationTest{
|
||||
commit.History,
|
||||
commit.HistoryComplex,
|
||||
commit.NewBranch,
|
||||
commit.PasteCommitMessage,
|
||||
commit.PasteCommitMessageOverExisting,
|
||||
commit.PreserveCommitMessage,
|
||||
commit.ResetAuthor,
|
||||
commit.ResetAuthorRange,
|
||||
|
Reference in New Issue
Block a user