From 71e34ecb4dcf25e1453a49c8183f9e51f37fb9be Mon Sep 17 00:00:00 2001 From: CrabNickolson Date: Wed, 18 Mar 2026 03:18:32 +0100 Subject: [PATCH] feature: allow enabling 3-way merge when applying a patch (#2200) --- src/Commands/Apply.cs | 5 ++++- src/Resources/Locales/en_US.axaml | 1 + src/ViewModels/Apply.cs | 9 ++++++++- src/ViewModels/StashesPage.cs | 2 +- src/Views/Apply.axaml | 7 ++++++- src/Views/TextDiffView.axaml.cs | 6 +++--- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Commands/Apply.cs b/src/Commands/Apply.cs index ca6ffe8d..544cf4d9 100644 --- a/src/Commands/Apply.cs +++ b/src/Commands/Apply.cs @@ -4,7 +4,7 @@ namespace SourceGit.Commands { public class Apply : Command { - public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode, string extra) + public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode, bool threeWayMerge, string extra) { WorkingDirectory = repo; Context = repo; @@ -17,6 +17,9 @@ namespace SourceGit.Commands else builder.Append("--whitespace=").Append(whitespaceMode).Append(' '); + if (threeWayMerge) + builder.Append("--3way "); + if (!string.IsNullOrEmpty(extra)) builder.Append(extra).Append(' '); diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 994a8804..f71f46f1 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -27,6 +27,7 @@ Patch File: Select .patch file to apply Ignore whitespace changes + 3-Way Merge Apply Patch Whitespace: Apply Stash diff --git a/src/ViewModels/Apply.cs b/src/ViewModels/Apply.cs index 3eab5ef7..817d5621 100644 --- a/src/ViewModels/Apply.cs +++ b/src/ViewModels/Apply.cs @@ -26,6 +26,12 @@ namespace SourceGit.ViewModels set; } + public bool ThreeWayMerge + { + get => _threeWayMerge; + set => SetProperty(ref _threeWayMerge, value); + } + public Apply(Repository repo) { _repo = repo; @@ -49,7 +55,7 @@ namespace SourceGit.ViewModels var log = _repo.CreateLog("Apply Patch"); Use(log); - var succ = await new Commands.Apply(_repo.FullPath, _patchFile, _ignoreWhiteSpace, SelectedWhiteSpaceMode.Arg, null) + var succ = await new Commands.Apply(_repo.FullPath, _patchFile, _ignoreWhiteSpace, SelectedWhiteSpaceMode.Arg, _threeWayMerge, null) .Use(log) .ExecAsync(); @@ -60,5 +66,6 @@ namespace SourceGit.ViewModels private readonly Repository _repo = null; private string _patchFile = string.Empty; private bool _ignoreWhiteSpace = true; + private bool _threeWayMerge = false; } } diff --git a/src/ViewModels/StashesPage.cs b/src/ViewModels/StashesPage.cs index a484b022..d1834d63 100644 --- a/src/ViewModels/StashesPage.cs +++ b/src/ViewModels/StashesPage.cs @@ -253,7 +253,7 @@ namespace SourceGit.ViewModels return; var log = _repo.CreateLog($"Apply changes from '{_selectedStash.Name}'"); - await new Commands.Apply(_repo.FullPath, saveTo, true, string.Empty, string.Empty) + await new Commands.Apply(_repo.FullPath, saveTo, true, string.Empty, false, string.Empty) .Use(log) .ExecAsync(); diff --git a/src/Views/Apply.axaml b/src/Views/Apply.axaml index d1265a5a..d64972de 100644 --- a/src/Views/Apply.axaml +++ b/src/Views/Apply.axaml @@ -18,7 +18,7 @@ Text="{DynamicResource Text.Apply.Title}"/> - + + + diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 2f844b68..81322c72 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -1508,7 +1508,7 @@ namespace SourceGit.Views diff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, false, chunk.IsOldSide, tmpFile); } - await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", "--cache --index").ExecAsync(); + await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", false, "--cache --index").ExecAsync(); File.Delete(tmpFile); vm.BlockNavigation.UpdateByChunk(chunk); @@ -1539,7 +1539,7 @@ namespace SourceGit.Views else diff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, true, chunk.IsOldSide, tmpFile); - await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", "--cache --index --reverse").ExecAsync(); + await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", false, "--cache --index --reverse").ExecAsync(); File.Delete(tmpFile); vm.BlockNavigation.UpdateByChunk(chunk); @@ -1577,7 +1577,7 @@ namespace SourceGit.Views diff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, true, chunk.IsOldSide, tmpFile); } - await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", "--reverse").ExecAsync(); + await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", false, "--reverse").ExecAsync(); File.Delete(tmpFile); vm.BlockNavigation.UpdateByChunk(chunk);