diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-03-07 08:55:48 +0100 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2023-03-07 13:38:19 +0100 |
commit | e4659145e89f8b84e4c12078eca5361ce0715611 (patch) | |
tree | e4732605298ab7d0fd10af3605f2b3a498a0b947 /pkg/gui | |
parent | bf6e9a1bd3f7a3084644b3658264631b156d725c (diff) |
Use WillBeAppliedReverse (and git apply --reverse) in the staging panel too
It's simpler to have only one way of reversing a patch.
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/controllers/staging_controller.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/pkg/gui/controllers/staging_controller.go b/pkg/gui/controllers/staging_controller.go index 840c18a18..b29361aca 100644 --- a/pkg/gui/controllers/staging_controller.go +++ b/pkg/gui/controllers/staging_controller.go @@ -182,7 +182,7 @@ func (self *StagingController) applySelection(reverse bool) error { firstLineIdx, lastLineIdx := state.SelectedRange() patch := patch.ModifiedPatchForRange(self.c.Log, path, state.GetDiff(), firstLineIdx, lastLineIdx, - patch.PatchOptions{Reverse: reverse, KeepOriginalHeader: false}) + patch.PatchOptions{Reverse: false, WillBeAppliedReverse: reverse, KeepOriginalHeader: false}) if patch == "" { return nil @@ -191,6 +191,9 @@ func (self *StagingController) applySelection(reverse bool) error { // apply the patch then refresh this panel // create a new temp file with the patch, then call git apply with that patch applyFlags := []string{} + if reverse { + applyFlags = append(applyFlags, "reverse") + } if !reverse || self.staged { applyFlags = append(applyFlags, "cached") } @@ -229,7 +232,7 @@ func (self *StagingController) editHunk() error { hunk := state.CurrentHunk() patchText := patch.ModifiedPatchForRange( self.c.Log, path, state.GetDiff(), hunk.FirstLineIdx, hunk.LastLineIdx(), - patch.PatchOptions{Reverse: self.staged, KeepOriginalHeader: false}, + patch.PatchOptions{Reverse: false, WillBeAppliedReverse: self.staged, KeepOriginalHeader: false}, ) patchFilepath, err := self.git.WorkingTree.SaveTemporaryPatch(patchText) if err != nil { @@ -254,7 +257,12 @@ func (self *StagingController) editHunk() error { self.c.Log, path, editedPatchText, 0, lineCount, patch.PatchOptions{Reverse: false, KeepOriginalHeader: false}, ) - if err := self.git.WorkingTree.ApplyPatch(newPatchText, "cached"); err != nil { + + applyFlags := []string{"cached"} + if self.staged { + applyFlags = append(applyFlags, "reverse") + } + if err := self.git.WorkingTree.ApplyPatch(newPatchText, applyFlags...); err != nil { return self.c.Error(err) } |