mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-03 13:21:56 +02:00
Merge pull request #2373 from phanithinks/clipboard_patch_option_2357
This commit is contained in:
commit
368d6437b8
@ -69,6 +69,14 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
|
||||
}
|
||||
}
|
||||
|
||||
menuItems = append(menuItems, []*types.MenuItem{
|
||||
{
|
||||
Label: "copy patch to clipboard",
|
||||
OnPress: func() error { return gui.copyPatchToClipboard() },
|
||||
Key: 'y',
|
||||
},
|
||||
}...)
|
||||
|
||||
return gui.c.Menu(types.CreateMenuOptions{Title: gui.c.Tr.PatchOptionsTitle, Items: menuItems})
|
||||
}
|
||||
|
||||
@ -192,3 +200,16 @@ func (gui *Gui) handleApplyPatch(reverse bool) error {
|
||||
}
|
||||
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
|
||||
}
|
||||
|
||||
func (gui *Gui) copyPatchToClipboard() error {
|
||||
patch := gui.git.Patch.PatchManager.RenderAggregatedPatchColored(true)
|
||||
|
||||
gui.c.LogAction(gui.c.Tr.Actions.CopyPatchToClipboard)
|
||||
if err := gui.os.CopyToClipboard(patch); err != nil {
|
||||
return gui.c.Error(err)
|
||||
}
|
||||
|
||||
gui.c.Toast(gui.c.Tr.PatchCopiedToClipboard)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -463,6 +463,7 @@ type TranslationSet struct {
|
||||
CommitURLCopiedToClipboard string
|
||||
CommitMessageCopiedToClipboard string
|
||||
CommitAuthorCopiedToClipboard string
|
||||
PatchCopiedToClipboard string
|
||||
LcCopiedToClipboard string
|
||||
ErrCannotEditDirectory string
|
||||
ErrStageDirWithInlineMergeConflicts string
|
||||
@ -566,6 +567,7 @@ type Actions struct {
|
||||
CopyCommitURLToClipboard string
|
||||
CopyCommitAuthorToClipboard string
|
||||
CopyCommitAttributeToClipboard string
|
||||
CopyPatchToClipboard string
|
||||
CustomCommand string
|
||||
DiscardAllChangesInDirectory string
|
||||
DiscardUnstagedChangesInDirectory string
|
||||
@ -1111,6 +1113,7 @@ func EnglishTranslationSet() TranslationSet {
|
||||
CommitURLCopiedToClipboard: "Commit URL copied to clipboard",
|
||||
CommitMessageCopiedToClipboard: "Commit message copied to clipboard",
|
||||
CommitAuthorCopiedToClipboard: "Commit author copied to clipboard",
|
||||
PatchCopiedToClipboard: "Patch copied to clipboard",
|
||||
LcCopiedToClipboard: "copied to clipboard",
|
||||
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",
|
||||
@ -1195,6 +1198,7 @@ func EnglishTranslationSet() TranslationSet {
|
||||
CopyCommitURLToClipboard: "Copy commit URL to clipboard",
|
||||
CopyCommitAuthorToClipboard: "Copy commit author to clipboard",
|
||||
CopyCommitAttributeToClipboard: "Copy to clipboard",
|
||||
CopyPatchToClipboard: "Copy patch to clipboard",
|
||||
MoveCommitUp: "Move commit up",
|
||||
MoveCommitDown: "Move commit down",
|
||||
CustomCommand: "Custom command",
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/atotto/clipboard"
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
||||
@ -143,6 +144,21 @@ func (self *TestDriver) ExpectPopup() *Popup {
|
||||
return &Popup{t: self}
|
||||
}
|
||||
|
||||
func (self *TestDriver) ExpectToast(matcher *matcher) {
|
||||
self.Views().AppStatus().Content(matcher)
|
||||
}
|
||||
|
||||
func (self *TestDriver) ExpectClipboard(matcher *matcher) {
|
||||
self.assertWithRetries(func() (bool, string) {
|
||||
text, err := clipboard.ReadAll()
|
||||
if err != nil {
|
||||
return false, "Error occured when reading from clipboard: " + err.Error()
|
||||
}
|
||||
ok, _ := matcher.test(text)
|
||||
return ok, fmt.Sprintf("Expected clipboard to match %s, but got %s", matcher.name(), text)
|
||||
})
|
||||
}
|
||||
|
||||
// for making assertions through git itself
|
||||
func (self *TestDriver) Git() *Git {
|
||||
return &Git{assertionHelper: self.assertionHelper, shell: self.shell}
|
||||
|
@ -64,6 +64,10 @@ func (self *Views) Information() *ViewDriver {
|
||||
return self.byName("information")
|
||||
}
|
||||
|
||||
func (self *Views) AppStatus() *ViewDriver {
|
||||
return self.byName("appStatus")
|
||||
}
|
||||
|
||||
func (self *Views) Branches() *ViewDriver {
|
||||
return self.byName("localBranches")
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package patch_building
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var BuildPatchAndCopyToClipboard = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Create a patch from the commits and copy the patch to clipbaord.",
|
||||
ExtraCmdArgs: "",
|
||||
Skip: true,
|
||||
SetupConfig: func(config *config.AppConfig) {},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.NewBranch("branch-a")
|
||||
shell.CreateFileAndAdd("file1", "first line\n")
|
||||
shell.Commit("first commit")
|
||||
|
||||
shell.NewBranch("branch-b")
|
||||
shell.UpdateFileAndAdd("file1", "first line\nsecond line\n")
|
||||
shell.Commit("update")
|
||||
|
||||
shell.Checkout("branch-a")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Branches().
|
||||
Focus().
|
||||
Lines(
|
||||
Contains("branch-a").IsSelected(),
|
||||
Contains("branch-b"),
|
||||
).
|
||||
Press(keys.Universal.NextItem).
|
||||
PressEnter().
|
||||
PressEnter()
|
||||
t.Views().
|
||||
CommitFiles().
|
||||
Lines(
|
||||
Contains("M file1").IsSelected(),
|
||||
).
|
||||
PressPrimaryAction()
|
||||
|
||||
t.Views().Information().Content(Contains("building patch"))
|
||||
|
||||
t.Views().
|
||||
CommitFiles().
|
||||
Press(keys.Universal.CreatePatchOptionsMenu)
|
||||
|
||||
t.ExpectPopup().Menu().Title(Equals("Patch Options")).Select(Contains("copy patch to clipboard")).Confirm()
|
||||
|
||||
t.ExpectToast(Contains("Patch copied to clipboard"))
|
||||
|
||||
t.ExpectClipboard(Contains("diff --git a/file1 b/file1"))
|
||||
},
|
||||
})
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/filter_by_path"
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase"
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/misc"
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/patch_building"
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/stash"
|
||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/sync"
|
||||
)
|
||||
@ -72,6 +73,7 @@ var tests = []*components.IntegrationTest{
|
||||
filter_by_path.CliArg,
|
||||
filter_by_path.SelectFile,
|
||||
filter_by_path.TypeFile,
|
||||
patch_building.BuildPatchAndCopyToClipboard,
|
||||
}
|
||||
|
||||
func GetTests() []*components.IntegrationTest {
|
||||
|
Loading…
x
Reference in New Issue
Block a user