From 1fd0f31682a1b55f22508309e6a16a3e56ac0206 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 21 Aug 2020 20:40:20 +1000 Subject: [PATCH] only show rebasey commands on a local commit when patch building --- pkg/gui/patch_building_panel.go | 10 ++++++++++ pkg/gui/patch_options_panel.go | 29 +++++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/pkg/gui/patch_building_panel.go b/pkg/gui/patch_building_panel.go index c39568cdf..6e2bcf8af 100644 --- a/pkg/gui/patch_building_panel.go +++ b/pkg/gui/patch_building_panel.go @@ -1,6 +1,8 @@ package gui import ( + "strings" + "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -119,3 +121,11 @@ func (gui *Gui) secondaryPatchPanelUpdateOpts() *viewUpdateOpts { return nil } + +func (gui *Gui) handleCopyPatchToClipboard() error { + // TODO: test that this works + + return gui.OSCommand.CopyToClipboard( + strings.Join(gui.GitCommand.PatchManager.RenderEachFilePatch(true), "\n"), + ) +} diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index 844ecbd36..2b6ec0c2a 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -13,16 +13,8 @@ func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error menuItems := []*menuItem{ { - displayString: fmt.Sprintf("remove patch from original commit (%s)", gui.GitCommand.PatchManager.Parent), - onPress: gui.handleDeletePatchFromCommit, - }, - { - displayString: "pull patch out into index", - onPress: gui.handlePullPatchIntoWorkingTree, - }, - { - displayString: "pull patch into new commit", - onPress: gui.handlePullPatchIntoNewCommit, + displayString: "copy patch", + onPress: gui.handleCopyPatchToClipboard, }, { displayString: "apply patch", @@ -38,6 +30,23 @@ func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error }, } + if gui.GitCommand.PatchManager.CanRebase { + menuItems = append(menuItems, []*menuItem{ + { + displayString: fmt.Sprintf("remove patch from original commit (%s)", gui.GitCommand.PatchManager.Parent), + onPress: gui.handleDeletePatchFromCommit, + }, + { + displayString: "pull patch out into index", + onPress: gui.handlePullPatchIntoWorkingTree, + }, + { + displayString: "pull patch into new commit", + onPress: gui.handlePullPatchIntoNewCommit, + }, + }...) + } + selectedCommit := gui.getSelectedCommit() if selectedCommit != nil && gui.GitCommand.PatchManager.Parent != selectedCommit.Sha { // adding this option to index 1