feature: supports to exclude modifed/deleted files while discarding local changes (#2226)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-03-30 11:26:00 +08:00
parent bd45b3b4e6
commit 82cedf858e
8 changed files with 23 additions and 9 deletions

View File

@@ -10,7 +10,7 @@ namespace SourceGit.Commands
/// <summary>
/// Discard all local changes (unstaged & staged)
/// </summary>
public static async Task AllAsync(string repo, bool includeUntracked, bool includeIgnored, Models.ICommandLog log)
public static async Task AllAsync(string repo, bool includeModified, bool includeUntracked, bool includeIgnored, Models.ICommandLog log)
{
if (includeUntracked)
{
@@ -37,7 +37,7 @@ namespace SourceGit.Commands
}
if (includeIgnored)
await new Clean(repo, Models.CleanMode.All).Use(log).ExecAsync().ConfigureAwait(false);
await new Clean(repo, Models.CleanMode.UntrackedAndIgnoredFiles).Use(log).ExecAsync().ConfigureAwait(false);
else
await new Clean(repo, Models.CleanMode.OnlyUntrackedFiles).Use(log).ExecAsync().ConfigureAwait(false);
}
@@ -46,7 +46,8 @@ namespace SourceGit.Commands
await new Clean(repo, Models.CleanMode.OnlyIgnoredFiles).Use(log).ExecAsync().ConfigureAwait(false);
}
await new Reset(repo, "", "--hard").Use(log).ExecAsync().ConfigureAwait(false);
if (includeModified)
await new Reset(repo, "", "--hard").Use(log).ExecAsync().ConfigureAwait(false);
}
/// <summary>

View File

@@ -4,6 +4,6 @@
{
OnlyUntrackedFiles = 0,
OnlyIgnoredFiles,
All,
UntrackedAndIgnoredFiles,
}
}

View File

@@ -382,6 +382,7 @@
<x:String x:Key="Text.Discard.All" xml:space="preserve">All local changes in working copy.</x:String>
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">Changes:</x:String>
<x:String x:Key="Text.Discard.IncludeIgnored" xml:space="preserve">Include ignored files</x:String>
<x:String x:Key="Text.Discard.IncludeModified" xml:space="preserve">Include modified/deleted files</x:String>
<x:String x:Key="Text.Discard.IncludeUntracked" xml:space="preserve">Include untracked files</x:String>
<x:String x:Key="Text.Discard.Total" xml:space="preserve">{0} changes will be discarded</x:String>
<x:String x:Key="Text.Discard.Warning" xml:space="preserve">You can't undo this action!!!</x:String>

View File

@@ -386,6 +386,7 @@
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本仓库未提交的修改。</x:String>
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">变更 </x:String>
<x:String x:Key="Text.Discard.IncludeIgnored" xml:space="preserve">包括所有已忽略的文件</x:String>
<x:String x:Key="Text.Discard.IncludeModified" xml:space="preserve">包括已修改或删除的文件</x:String>
<x:String x:Key="Text.Discard.IncludeUntracked" xml:space="preserve">包括未跟踪的文件</x:String>
<x:String x:Key="Text.Discard.Total" xml:space="preserve">总计{0}项选中更改</x:String>
<x:String x:Key="Text.Discard.Warning" xml:space="preserve">本操作不支持回退,请确认后继续!!!</x:String>

View File

@@ -386,6 +386,7 @@
<x:String x:Key="Text.Discard.All" xml:space="preserve">所有本機未提交的變更。</x:String>
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">變更:</x:String>
<x:String x:Key="Text.Discard.IncludeIgnored" xml:space="preserve">包括所有已忽略的檔案</x:String>
<x:String x:Key="Text.Discard.IncludeModified" xml:space="preserve">包括已變更或刪除的檔案</x:String>
<x:String x:Key="Text.Discard.IncludeUntracked" xml:space="preserve">包含未追蹤檔案</x:String>
<x:String x:Key="Text.Discard.Total" xml:space="preserve">將捨棄總計 {0} 項已選取的變更</x:String>
<x:String x:Key="Text.Discard.Warning" xml:space="preserve">您無法復原此操作,請確認後再繼續!</x:String>

View File

@@ -5,6 +5,12 @@ namespace SourceGit.ViewModels
{
public class DiscardAllMode
{
public bool IncludeModified
{
get;
set;
} = true;
public bool IncludeUntracked
{
get;
@@ -72,7 +78,7 @@ namespace SourceGit.ViewModels
if (Mode is DiscardAllMode all)
{
await Commands.Discard.AllAsync(_repo.FullPath, all.IncludeUntracked, all.IncludeIgnored, log);
await Commands.Discard.AllAsync(_repo.FullPath, all.IncludeModified, all.IncludeUntracked, all.IncludeIgnored, log);
_repo.ClearCommitMessage();
}
else

View File

@@ -134,7 +134,7 @@ namespace SourceGit.ViewModels
}
else
{
await Commands.Discard.AllAsync(_repo.FullPath, false, false, log);
await Commands.Discard.AllAsync(_repo.FullPath, true, false, false, log);
}
}

View File

@@ -21,7 +21,7 @@
<ContentControl Margin="0,16,0,8" Content="{Binding Mode}">
<ContentControl.DataTemplates>
<DataTemplate DataType="vm:DiscardAllMode">
<Grid RowDefinitions="32,32,32,Auto" ColumnDefinitions="120,*">
<Grid RowDefinitions="32,32,32,32,Auto" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
HorizontalAlignment="Right"
@@ -30,14 +30,18 @@
Text="{DynamicResource Text.Discard.All}"/>
<CheckBox Grid.Row="1" Grid.Column="1"
Content="{DynamicResource Text.Discard.IncludeModified}"
IsChecked="{Binding IncludeModified, Mode=TwoWay}"/>
<CheckBox Grid.Row="2" Grid.Column="1"
Content="{DynamicResource Text.Discard.IncludeUntracked}"
IsChecked="{Binding IncludeUntracked, Mode=TwoWay}"/>
<CheckBox Grid.Row="2" Grid.Column="1"
<CheckBox Grid.Row="3" Grid.Column="1"
Content="{DynamicResource Text.Discard.IncludeIgnored}"
IsChecked="{Binding IncludeIgnored, Mode=TwoWay}"/>
<Grid Grid.Row="3" Grid.Column="1" ColumnDefinitions="Auto,*" Margin="0,6,0,0">
<Grid Grid.Row="4" Grid.Column="1" ColumnDefinitions="Auto,*" Margin="0,6,0,0">
<Path Grid.Column="0"
Width="14" Height="14"
Data="{StaticResource Icons.Error}"