diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-02-23 22:51:49 +0100 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2023-03-07 09:49:34 +0100 |
commit | a68cd6af9c572a83cbaf511a72b8a89c1d534e0b (patch) | |
tree | b8d3feb25fc4a3498298dfd79645e8c6ccb34ae6 | |
parent | 4ca012dbfbe0c6be33da36f442a4d7d10019fafd (diff) |
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.
-rw-r--r-- | pkg/commands/patch/patch_manager.go | 12 | ||||
-rw-r--r-- | pkg/integration/tests/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(). |