Skip to content

Commit 71e34ec

Browse files
feature: allow enabling 3-way merge when applying a patch (#2200)
1 parent 16a66d4 commit 71e34ec

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

src/Commands/Apply.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace SourceGit.Commands
44
{
55
public class Apply : Command
66
{
7-
public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode, string extra)
7+
public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode, bool threeWayMerge, string extra)
88
{
99
WorkingDirectory = repo;
1010
Context = repo;
@@ -17,6 +17,9 @@ public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceM
1717
else
1818
builder.Append("--whitespace=").Append(whitespaceMode).Append(' ');
1919

20+
if (threeWayMerge)
21+
builder.Append("--3way ");
22+
2023
if (!string.IsNullOrEmpty(extra))
2124
builder.Append(extra).Append(' ');
2225

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<x:String x:Key="Text.Apply.File" xml:space="preserve">Patch File:</x:String>
2828
<x:String x:Key="Text.Apply.File.Placeholder" xml:space="preserve">Select .patch file to apply</x:String>
2929
<x:String x:Key="Text.Apply.IgnoreWS" xml:space="preserve">Ignore whitespace changes</x:String>
30+
<x:String x:Key="Text.Apply.3Way" xml:space="preserve">3-Way Merge</x:String>
3031
<x:String x:Key="Text.Apply.Title" xml:space="preserve">Apply Patch</x:String>
3132
<x:String x:Key="Text.Apply.WS" xml:space="preserve">Whitespace:</x:String>
3233
<x:String x:Key="Text.ApplyStash" xml:space="preserve">Apply Stash</x:String>

src/ViewModels/Apply.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public Models.ApplyWhiteSpaceMode SelectedWhiteSpaceMode
2626
set;
2727
}
2828

29+
public bool ThreeWayMerge
30+
{
31+
get => _threeWayMerge;
32+
set => SetProperty(ref _threeWayMerge, value);
33+
}
34+
2935
public Apply(Repository repo)
3036
{
3137
_repo = repo;
@@ -49,7 +55,7 @@ public override async Task<bool> Sure()
4955
var log = _repo.CreateLog("Apply Patch");
5056
Use(log);
5157

52-
var succ = await new Commands.Apply(_repo.FullPath, _patchFile, _ignoreWhiteSpace, SelectedWhiteSpaceMode.Arg, null)
58+
var succ = await new Commands.Apply(_repo.FullPath, _patchFile, _ignoreWhiteSpace, SelectedWhiteSpaceMode.Arg, _threeWayMerge, null)
5359
.Use(log)
5460
.ExecAsync();
5561

@@ -60,5 +66,6 @@ public override async Task<bool> Sure()
6066
private readonly Repository _repo = null;
6167
private string _patchFile = string.Empty;
6268
private bool _ignoreWhiteSpace = true;
69+
private bool _threeWayMerge = false;
6370
}
6471
}

src/ViewModels/StashesPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public async Task ApplySelectedChanges(List<Models.Change> changes)
253253
return;
254254

255255
var log = _repo.CreateLog($"Apply changes from '{_selectedStash.Name}'");
256-
await new Commands.Apply(_repo.FullPath, saveTo, true, string.Empty, string.Empty)
256+
await new Commands.Apply(_repo.FullPath, saveTo, true, string.Empty, false, string.Empty)
257257
.Use(log)
258258
.ExecAsync();
259259

src/Views/Apply.axaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Text="{DynamicResource Text.Apply.Title}"/>
1919
</StackPanel>
2020

21-
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32" ColumnDefinitions="120,*">
21+
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,32" ColumnDefinitions="120,*">
2222
<TextBlock Grid.Column="0"
2323
HorizontalAlignment="Right" VerticalAlignment="Center"
2424
Margin="0,0,8,0"
@@ -77,6 +77,11 @@
7777
Content="{DynamicResource Text.Apply.IgnoreWS}"
7878
IsChecked="{Binding IgnoreWhiteSpace, Mode=TwoWay}"
7979
ToolTip.Tip="--ignore-whitespace"/>
80+
81+
<CheckBox Grid.Row="3" Grid.Column="1"
82+
Content="{DynamicResource Text.Apply.3Way}"
83+
IsChecked="{Binding ThreeWayMerge, Mode=TwoWay}"
84+
ToolTip.Tip="--3way"/>
8085
</Grid>
8186
</StackPanel>
8287
</UserControl>

src/Views/TextDiffView.axaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ private async void OnStageChunk(object _1, RoutedEventArgs _2)
15081508
diff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, false, chunk.IsOldSide, tmpFile);
15091509
}
15101510

1511-
await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", "--cache --index").ExecAsync();
1511+
await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", false, "--cache --index").ExecAsync();
15121512
File.Delete(tmpFile);
15131513

15141514
vm.BlockNavigation.UpdateByChunk(chunk);
@@ -1539,7 +1539,7 @@ private async void OnUnstageChunk(object _1, RoutedEventArgs _2)
15391539
else
15401540
diff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, true, chunk.IsOldSide, tmpFile);
15411541

1542-
await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", "--cache --index --reverse").ExecAsync();
1542+
await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", false, "--cache --index --reverse").ExecAsync();
15431543
File.Delete(tmpFile);
15441544

15451545
vm.BlockNavigation.UpdateByChunk(chunk);
@@ -1577,7 +1577,7 @@ private async void OnDiscardChunk(object _1, RoutedEventArgs _2)
15771577
diff.GeneratePatchFromSelectionSingleSide(change, treeGuid, selection, true, chunk.IsOldSide, tmpFile);
15781578
}
15791579

1580-
await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", "--reverse").ExecAsync();
1580+
await new Commands.Apply(repo.FullPath, tmpFile, true, "nowarn", false, "--reverse").ExecAsync();
15811581
File.Delete(tmpFile);
15821582

15831583
vm.BlockNavigation.UpdateByChunk(chunk);

0 commit comments

Comments
 (0)