mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-03 13:21:56 +02:00
Use WillBeAppliedReverse (and git apply --reverse) in the staging panel too
It's simpler to have only one way of reversing a patch.
This commit is contained in:
parent
bf6e9a1bd3
commit
e4659145e8
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user