feature: allow enabling 3-way merge when applying a patch (#2200)

This commit is contained in:
CrabNickolson
2026-03-18 03:18:32 +01:00
committed by GitHub
parent 16a66d4dff
commit 71e34ecb4d
6 changed files with 23 additions and 7 deletions

View File

@@ -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(' ');

View File

@@ -27,6 +27,7 @@
<x:String x:Key="Text.Apply.File" xml:space="preserve">Patch File:</x:String>
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">Select .patch file to apply</x:String>
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">Ignore whitespace changes</x:String>
<x:String x:Key="Text.Apply.3Way" xml:space="preserve">3-Way Merge</x:String>
<x:String x:Key="Text.Apply.Title" xml:space="preserve">Apply Patch</x:String>
<x:String x:Key="Text.Apply.WS" xml:space="preserve">Whitespace:</x:String>
<x:String x:Key="Text.ApplyStash" xml:space="preserve">Apply Stash</x:String>

View File

@@ -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;
}
}

View File

@@ -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();

View File

@@ -18,7 +18,7 @@
Text="{DynamicResource Text.Apply.Title}"/>
</StackPanel>
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32" ColumnDefinitions="120,*">
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32" ColumnDefinitions="120,*">
<TextBlock Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
@@ -77,6 +77,11 @@
Content="{DynamicResource Text.Apply.IgnoreWS}"
IsChecked="{Binding IgnoreWhiteSpace, Mode=TwoWay}"
ToolTip.Tip="--ignore-whitespace"/>
<CheckBox Grid.Row="3" Grid.Column="1"
Content="{DynamicResource Text.Apply.3Way}"
IsChecked="{Binding ThreeWayMerge, Mode=TwoWay}"
ToolTip.Tip="--3way"/>
</Grid>
</StackPanel>
</UserControl>

View File

@@ -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);