Add option --ignore-whitespace supports for git apply command

This commit is contained in:
leo 2020-07-08 11:37:29 +08:00
parent 95030c334f
commit 5df377e48e
3 changed files with 23 additions and 6 deletions

View file

@ -502,11 +502,16 @@ namespace SourceGit.Git {
/// Apply patch. /// Apply patch.
/// </summary> /// </summary>
/// <param name="patch"></param> /// <param name="patch"></param>
/// <param name="ignoreSpaceChanges"></param>
/// <param name="whitespaceMode"></param> /// <param name="whitespaceMode"></param>
public void Apply(string patch, string whitespaceMode) { public void Apply(string patch, bool ignoreSpaceChanges, string whitespaceMode) {
isWatcherDisabled = true; isWatcherDisabled = true;
var errs = RunCommand($"apply --whitespace={whitespaceMode} \"{patch}\"", null); var args = "apply ";
if (ignoreSpaceChanges) args += "--ignore-whitespace ";
else args += $"--whitespace={whitespaceMode} ";
var errs = RunCommand($"{args} \"{patch}\"", null);
if (errs != null) { if (errs != null) {
App.RaiseError(errs); App.RaiseError(errs);
} else { } else {

View file

@ -5,14 +5,16 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="clr-namespace:SourceGit.Helpers" xmlns:helpers="clr-namespace:SourceGit.Helpers"
xmlns:converters="clr-namespace:SourceGit.Converters"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="192" d:DesignWidth="500" Height="160" Width="500"> Height="192" Width="500">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="16"/> <RowDefinition Height="16"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="16"/> <RowDefinition Height="16"/>
<RowDefinition Height="32"/> <RowDefinition Height="32"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
@ -22,6 +24,10 @@
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.Resources>
<converters:InverseBool x:Key="InverseBool"/>
</Grid.Resources>
<Label Grid.Row="0" Grid.ColumnSpan="2" FontWeight="DemiBold" FontSize="18" Content="Apply Patch"/> <Label Grid.Row="0" Grid.ColumnSpan="2" FontWeight="DemiBold" FontSize="18" Content="Apply Patch"/>
<Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Content="Patch File :"/> <Label Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Content="Patch File :"/>
@ -51,7 +57,7 @@
</Grid> </Grid>
<Label Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" Content="Whitespace :"/> <Label Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" Content="Whitespace :"/>
<ComboBox x:Name="combWhitespaceOptions" Grid.Row="3" Grid.Column="1" VerticalAlignment="Center"> <ComboBox x:Name="combWhitespaceOptions" Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" IsEnabled="{Binding ElementName=chkIgnoreWhitespace, Path=IsChecked, Converter={StaticResource InverseBool}}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Horizontal" Height="20"> <StackPanel Orientation="Horizontal" Height="20">
@ -62,7 +68,12 @@
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>
</ComboBox> </ComboBox>
<Grid Grid.Row="5" Grid.ColumnSpan="2"> <CheckBox Grid.Row="4" Grid.Column="1"
x:Name="chkIgnoreWhitespace"
IsChecked="True"
Content="Ignore whitespace changes"/>
<Grid Grid.Row="6" Grid.ColumnSpan="2">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
<ColumnDefinition Width="80"/> <ColumnDefinition Width="80"/>

View file

@ -85,7 +85,8 @@ namespace SourceGit.UI {
PopupManager.Lock(); PopupManager.Lock();
var mode = combWhitespaceOptions.SelectedItem as WhitespaceOption; var mode = combWhitespaceOptions.SelectedItem as WhitespaceOption;
await Task.Run(() => repo.Apply(PatchFile, mode.Arg)); var ignoreSpaceChanges = chkIgnoreWhitespace.IsChecked == true;
await Task.Run(() => repo.Apply(PatchFile, ignoreSpaceChanges, mode.Arg));
PopupManager.Close(true); PopupManager.Close(true);
} }