mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-17 22:32:58 +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})
|
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})
|
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
|
CommitURLCopiedToClipboard string
|
||||||
CommitMessageCopiedToClipboard string
|
CommitMessageCopiedToClipboard string
|
||||||
CommitAuthorCopiedToClipboard string
|
CommitAuthorCopiedToClipboard string
|
||||||
|
PatchCopiedToClipboard string
|
||||||
LcCopiedToClipboard string
|
LcCopiedToClipboard string
|
||||||
ErrCannotEditDirectory string
|
ErrCannotEditDirectory string
|
||||||
ErrStageDirWithInlineMergeConflicts string
|
ErrStageDirWithInlineMergeConflicts string
|
||||||
@ -566,6 +567,7 @@ type Actions struct {
|
|||||||
CopyCommitURLToClipboard string
|
CopyCommitURLToClipboard string
|
||||||
CopyCommitAuthorToClipboard string
|
CopyCommitAuthorToClipboard string
|
||||||
CopyCommitAttributeToClipboard string
|
CopyCommitAttributeToClipboard string
|
||||||
|
CopyPatchToClipboard string
|
||||||
CustomCommand string
|
CustomCommand string
|
||||||
DiscardAllChangesInDirectory string
|
DiscardAllChangesInDirectory string
|
||||||
DiscardUnstagedChangesInDirectory string
|
DiscardUnstagedChangesInDirectory string
|
||||||
@ -1111,6 +1113,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
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",
|
CommitAuthorCopiedToClipboard: "Commit author copied to clipboard",
|
||||||
|
PatchCopiedToClipboard: "Patch 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",
|
||||||
@ -1195,6 +1198,7 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
CopyCommitURLToClipboard: "Copy commit URL to clipboard",
|
CopyCommitURLToClipboard: "Copy commit URL to clipboard",
|
||||||
CopyCommitAuthorToClipboard: "Copy commit author to clipboard",
|
CopyCommitAuthorToClipboard: "Copy commit author to clipboard",
|
||||||
CopyCommitAttributeToClipboard: "Copy to clipboard",
|
CopyCommitAttributeToClipboard: "Copy to clipboard",
|
||||||
|
CopyPatchToClipboard: "Copy patch to clipboard",
|
||||||
MoveCommitUp: "Move commit up",
|
MoveCommitUp: "Move commit up",
|
||||||
MoveCommitDown: "Move commit down",
|
MoveCommitDown: "Move commit down",
|
||||||
CustomCommand: "Custom command",
|
CustomCommand: "Custom command",
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/atotto/clipboard"
|
||||||
"github.com/jesseduffield/lazygit/pkg/config"
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
|
||||||
@ -143,6 +144,21 @@ func (self *TestDriver) ExpectPopup() *Popup {
|
|||||||
return &Popup{t: self}
|
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
|
// for making assertions through git itself
|
||||||
func (self *TestDriver) Git() *Git {
|
func (self *TestDriver) Git() *Git {
|
||||||
return &Git{assertionHelper: self.assertionHelper, shell: self.shell}
|
return &Git{assertionHelper: self.assertionHelper, shell: self.shell}
|
||||||
|
@ -64,6 +64,10 @@ func (self *Views) Information() *ViewDriver {
|
|||||||
return self.byName("information")
|
return self.byName("information")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Views) AppStatus() *ViewDriver {
|
||||||
|
return self.byName("appStatus")
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Views) Branches() *ViewDriver {
|
func (self *Views) Branches() *ViewDriver {
|
||||||
return self.byName("localBranches")
|
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/filter_by_path"
|
||||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase"
|
"github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase"
|
||||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/misc"
|
"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/stash"
|
||||||
"github.com/jesseduffield/lazygit/pkg/integration/tests/sync"
|
"github.com/jesseduffield/lazygit/pkg/integration/tests/sync"
|
||||||
)
|
)
|
||||||
@ -72,6 +73,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
filter_by_path.CliArg,
|
filter_by_path.CliArg,
|
||||||
filter_by_path.SelectFile,
|
filter_by_path.SelectFile,
|
||||||
filter_by_path.TypeFile,
|
filter_by_path.TypeFile,
|
||||||
|
patch_building.BuildPatchAndCopyToClipboard,
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTests() []*components.IntegrationTest {
|
func GetTests() []*components.IntegrationTest {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user