diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-22 18:29:09 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-23 14:29:18 +1000 |
commit | 43d891b8d68c862da793429e0bdbca9dcabb44b0 (patch) | |
tree | 91ca072ea2d91eb156bd8c1958f8dbeb65c31c66 /pkg/gui/patch_building_panel.go | |
parent | 2eee079d3aafb7914947e85fe5decd528c34ab93 (diff) |
support creating patches from files in diff mode
Diffstat (limited to 'pkg/gui/patch_building_panel.go')
-rw-r--r-- | pkg/gui/patch_building_panel.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/pkg/gui/patch_building_panel.go b/pkg/gui/patch_building_panel.go index fc39a2e43..38a03859a 100644 --- a/pkg/gui/patch_building_panel.go +++ b/pkg/gui/patch_building_panel.go @@ -5,6 +5,19 @@ import ( "github.com/jesseduffield/lazygit/pkg/utils" ) +// getFromAndReverseArgsForDiff tells us the from and reverse args to be used in a diff command. If we're not in diff mode we'll end up with the equivalent of a `git show` i.e `git diff blah^..blah`. +func (gui *Gui) getFromAndReverseArgsForDiff(to string) (string, bool) { + from := to + "^" + reverse := false + + if gui.State.Modes.Diffing.Active() { + reverse = gui.State.Modes.Diffing.Reverse + from = gui.State.Modes.Diffing.Ref + } + + return from, reverse +} + func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error { if !gui.GitCommand.PatchManager.Active() { return gui.handleEscapePatchBuildingPanel() @@ -22,7 +35,9 @@ func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error { return nil } - diff, err := gui.GitCommand.ShowCommitFile(commitFile.Parent, commitFile.Name, true) + to := commitFile.Parent + from, reverse := gui.getFromAndReverseArgsForDiff(to) + diff, err := gui.GitCommand.ShowFileDiff(from, to, reverse, commitFile.Name, true) if err != nil { return err } |