Skip to content

Commit 82cedf8

Browse files
committed
feature: supports to exclude modifed/deleted files while discarding local changes (#2226)
Signed-off-by: leo <longshuang@msn.cn>
1 parent bd45b3b commit 82cedf8

File tree

8 files changed

+23
-9
lines changed

8 files changed

+23
-9
lines changed

src/Commands/Discard.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class Discard
1010
/// <summary>
1111
/// Discard all local changes (unstaged & staged)
1212
/// </summary>
13-
public static async Task AllAsync(string repo, bool includeUntracked, bool includeIgnored, Models.ICommandLog log)
13+
public static async Task AllAsync(string repo, bool includeModified, bool includeUntracked, bool includeIgnored, Models.ICommandLog log)
1414
{
1515
if (includeUntracked)
1616
{
@@ -37,7 +37,7 @@ public static async Task AllAsync(string repo, bool includeUntracked, bool inclu
3737
}
3838

3939
if (includeIgnored)
40-
await new Clean(repo, Models.CleanMode.All).Use(log).ExecAsync().ConfigureAwait(false);
40+
await new Clean(repo, Models.CleanMode.UntrackedAndIgnoredFiles).Use(log).ExecAsync().ConfigureAwait(false);
4141
else
4242
await new Clean(repo, Models.CleanMode.OnlyUntrackedFiles).Use(log).ExecAsync().ConfigureAwait(false);
4343
}
@@ -46,7 +46,8 @@ public static async Task AllAsync(string repo, bool includeUntracked, bool inclu
4646
await new Clean(repo, Models.CleanMode.OnlyIgnoredFiles).Use(log).ExecAsync().ConfigureAwait(false);
4747
}
4848

49-
await new Reset(repo, "", "--hard").Use(log).ExecAsync().ConfigureAwait(false);
49+
if (includeModified)
50+
await new Reset(repo, "", "--hard").Use(log).ExecAsync().ConfigureAwait(false);
5051
}
5152

5253
/// <summary>

src/Models/CleanMode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ public enum CleanMode
44
{
55
OnlyUntrackedFiles = 0,
66
OnlyIgnoredFiles,
7-
All,
7+
UntrackedAndIgnoredFiles,
88
}
99
}

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@
382382
<x:String x:Key="Text.Discard.All" xml:space="preserve">All local changes in working copy.</x:String>
383383
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">Changes:</x:String>
384384
<x:String x:Key="Text.Discard.IncludeIgnored" xml:space="preserve">Include ignored files</x:String>
385+
<x:String x:Key="Text.Discard.IncludeModified" xml:space="preserve">Include modified/deleted files</x:String>
385386
<x:String x:Key="Text.Discard.IncludeUntracked" xml:space="preserve">Include untracked files</x:String>
386387
<x:String x:Key="Text.Discard.Total" xml:space="preserve">{0} changes will be discarded</x:String>
387388
<x:String x:Key="Text.Discard.Warning" xml:space="preserve">You can't undo this action!!!</x:String>

src/Resources/Locales/zh_CN.axaml

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

src/Resources/Locales/zh_TW.axaml

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

src/ViewModels/Discard.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ namespace SourceGit.ViewModels
55
{
66
public class DiscardAllMode
77
{
8+
public bool IncludeModified
9+
{
10+
get;
11+
set;
12+
} = true;
13+
814
public bool IncludeUntracked
915
{
1016
get;
@@ -72,7 +78,7 @@ public override async Task<bool> Sure()
7278

7379
if (Mode is DiscardAllMode all)
7480
{
75-
await Commands.Discard.AllAsync(_repo.FullPath, all.IncludeUntracked, all.IncludeIgnored, log);
81+
await Commands.Discard.AllAsync(_repo.FullPath, all.IncludeModified, all.IncludeUntracked, all.IncludeIgnored, log);
7682
_repo.ClearCommitMessage();
7783
}
7884
else

src/ViewModels/Pull.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public override async Task<bool> Sure()
134134
}
135135
else
136136
{
137-
await Commands.Discard.AllAsync(_repo.FullPath, false, false, log);
137+
await Commands.Discard.AllAsync(_repo.FullPath, true, false, false, log);
138138
}
139139
}
140140

src/Views/Discard.axaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<ContentControl Margin="0,16,0,8" Content="{Binding Mode}">
2222
<ContentControl.DataTemplates>
2323
<DataTemplate DataType="vm:DiscardAllMode">
24-
<Grid RowDefinitions="32,32,32,Auto" ColumnDefinitions="120,*">
24+
<Grid RowDefinitions="32,32,32,32,Auto" ColumnDefinitions="120,*">
2525
<TextBlock Grid.Row="0" Grid.Column="0"
2626
Margin="0,0,8,0"
2727
HorizontalAlignment="Right"
@@ -30,14 +30,18 @@
3030
Text="{DynamicResource Text.Discard.All}"/>
3131

3232
<CheckBox Grid.Row="1" Grid.Column="1"
33+
Content="{DynamicResource Text.Discard.IncludeModified}"
34+
IsChecked="{Binding IncludeModified, Mode=TwoWay}"/>
35+
36+
<CheckBox Grid.Row="2" Grid.Column="1"
3337
Content="{DynamicResource Text.Discard.IncludeUntracked}"
3438
IsChecked="{Binding IncludeUntracked, Mode=TwoWay}"/>
3539

36-
<CheckBox Grid.Row="2" Grid.Column="1"
40+
<CheckBox Grid.Row="3" Grid.Column="1"
3741
Content="{DynamicResource Text.Discard.IncludeIgnored}"
3842
IsChecked="{Binding IncludeIgnored, Mode=TwoWay}"/>
3943

40-
<Grid Grid.Row="3" Grid.Column="1" ColumnDefinitions="Auto,*" Margin="0,6,0,0">
44+
<Grid Grid.Row="4" Grid.Column="1" ColumnDefinitions="Auto,*" Margin="0,6,0,0">
4145
<Path Grid.Column="0"
4246
Width="14" Height="14"
4347
Data="{StaticResource Icons.Error}"

0 commit comments

Comments
 (0)