From a68cd6af9c572a83cbaf511a72b8a89c1d534e0b Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 23 Feb 2023 22:51:49 +0100 Subject: [PATCH] Concatenate patches to apply them all at once This fixes the problem that patching would stop at the first file that has a conflict. We always want to patch all files. Also, it's faster for large patches, and the code is a little bit simpler too. --- pkg/commands/patch/patch_manager.go | 12 ++++-------- .../patch_building/apply_in_reverse_with_conflict.go | 3 ++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/pkg/commands/patch/patch_manager.go b/pkg/commands/patch/patch_manager.go index e3f6cd454..e50c0fd3a 100644 --- a/pkg/commands/patch/patch_manager.go +++ b/pkg/commands/patch/patch_manager.go @@ -245,6 +245,8 @@ func (p *PatchManager) GetFileIncLineIndices(filename string) ([]int, error) { } func (p *PatchManager) ApplyPatches(reverse bool) error { + patch := "" + applyFlags := []string{"index", "3way"} if reverse { applyFlags = append(applyFlags, "reverse") @@ -255,16 +257,10 @@ func (p *PatchManager) ApplyPatches(reverse bool) error { continue } - patch := p.RenderPatchForFile(filename, true, reverse) - if patch != "" { - err := p.applyPatch(patch, applyFlags...) - if err != nil { - return err - } - } + patch += p.RenderPatchForFile(filename, true, reverse) } - return nil + return p.applyPatch(patch, applyFlags...) } // clears the patch diff --git a/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go b/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go index 8c3e61a86..04d160a01 100644 --- a/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go +++ b/pkg/integration/tests/patch_building/apply_in_reverse_with_conflict.go @@ -52,7 +52,7 @@ var ApplyInReverseWithConflict = NewIntegrationTest(NewIntegrationTestArgs{ t.ExpectPopup().Alert(). Title(Equals("Error")). Content(Contains("Applied patch to 'file1' with conflicts."). - DoesNotContain("Applied patch to 'file2' cleanly.")). + Contains("Applied patch to 'file2' cleanly.")). Confirm() t.Views().Files(). @@ -79,6 +79,7 @@ var ApplyInReverseWithConflict = NewIntegrationTest(NewIntegrationTestArgs{ Focus(). Lines( Contains("M").Contains("file1").IsSelected(), + Contains("M").Contains("file2"), ) t.Views().Main().