summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pkg/gui/custom_patch_options_panel.go21
-rw-r--r--pkg/i18n/english.go4
-rw-r--r--pkg/integration/components/test_driver.go16
-rw-r--r--pkg/integration/components/views.go4
-rw-r--r--pkg/integration/tests/patch_building/copy_patch_to_clipboard.go53
-rw-r--r--pkg/integration/tests/tests.go2
6 files changed, 100 insertions, 0 deletions
diff --git a/pkg/gui/custom_patch_options_panel.go b/pkg/gui/custom_patch_options_panel.go
index a508c7b44..6d640157b 100644
--- a/pkg/gui/custom_patch_options_panel.go
+++ b/pkg/gui/custom_patch_options_panel.go
@@ -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
+}
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index c3a391795..22c7d5c43 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -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",
diff --git a/pkg/integration/components/test_driver.go b/pkg/integration/components/test_driver.go
index 5f2e15435..1128de3f5 100644
--- a/pkg/integration/components/test_driver.go
+++ b/pkg/integration/components/test_driver.go
@@ -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}
diff --git a/pkg/integration/components/views.go b/pkg/integration/components/views.go
index 906c17f4f..5641f1cd4 100644
--- a/pkg/integration/components/views.go
+++ b/pkg/integration/components/views.go
@@ -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")
}
diff --git a/pkg/integration/tests/patch_building/copy_patch_to_clipboard.go b/pkg/integration/tests/patch_building/copy_patch_to_clipboard.go
new file mode 100644
index 000000000..59b38388f
--- /dev/null
+++ b/pkg/integration/tests/patch_building/copy_patch_to_clipboard.go
@@ -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"))
+ },
+})
diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go
index 8d10b236f..59df0ef65 100644
--- a/pkg/integration/tests/tests.go
+++ b/pkg/integration/tests/tests.go
@@ -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 {