Skip to content

Commit e2e76ba

Browse files
committed
feat: add include untracked opt on discard (fix #1586)
- Add support for optionally including untracked files when discarding all changes in the repository. - Add option to include untracked files in discard operation. - Add option to include untracked files when discarding all changes. - Add include untracked files checkbox to discard view.
1 parent 935d30d commit e2e76ba

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/Commands/Discard.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ public static class Discard
1212
/// </summary>
1313
/// <param name="repo"></param>
1414
/// <param name="includeIgnored"></param>
15+
/// <param name="includeUntracked"></param>
1516
/// <param name="log"></param>
16-
public static async Task AllAsync(string repo, bool includeIgnored, Models.ICommandLog log)
17+
public static async Task AllAsync(string repo, bool includeIgnored, bool includeUntracked, Models.ICommandLog log)
1718
{
1819
var changes = await new QueryLocalChanges(repo).GetResultAsync().ConfigureAwait(false);
1920
try
2021
{
2122
foreach (var c in changes)
2223
{
23-
if (c.WorkTree == Models.ChangeState.Untracked ||
24+
if ((c.WorkTree == Models.ChangeState.Untracked && includeUntracked) ||
2425
c.WorkTree == Models.ChangeState.Added ||
2526
c.Index == Models.ChangeState.Added ||
2627
c.Index == Models.ChangeState.Renamed)

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@
325325
<x:String x:Key="Text.Discard.All" xml:space="preserve">All local changes in working copy.</x:String>
326326
<x:String x:Key="Text.Discard.Changes" xml:space="preserve">Changes:</x:String>
327327
<x:String x:Key="Text.Discard.IncludeIgnored" xml:space="preserve">Include ignored files</x:String>
328+
<x:String x:Key="Text.Discard.IncludeUntracked" xml:space="preserve">Include untracked files</x:String>
328329
<x:String x:Key="Text.Discard.Total" xml:space="preserve">{0} changes will be discarded</x:String>
329330
<x:String x:Key="Text.Discard.Warning" xml:space="preserve">You can't undo this action!!!</x:String>
330331
<x:String x:Key="Text.EditRepositoryNode.Bookmark" xml:space="preserve">Bookmark:</x:String>

src/ViewModels/Discard.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public bool IncludeIgnored
1010
get;
1111
set;
1212
} = false;
13+
14+
public bool IncludeUntracked
15+
{
16+
get;
17+
set;
18+
} = false;
1319
}
1420

1521
public class DiscardSingleFile
@@ -65,7 +71,7 @@ public override async Task<bool> Sure()
6571
Use(log);
6672

6773
if (Mode is DiscardAllMode all)
68-
await Commands.Discard.AllAsync(_repo.FullPath, all.IncludeIgnored, log);
74+
await Commands.Discard.AllAsync(_repo.FullPath, all.IncludeIgnored, all.IncludeUntracked, log);
6975
else
7076
await Commands.Discard.ChangesAsync(_repo.FullPath, _changes, log);
7177

src/Views/Discard.axaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<ContentControl Margin="0,16,0,8" Content="{Binding Mode}">
2525
<ContentControl.DataTemplates>
2626
<DataTemplate DataType="vm:DiscardAllMode">
27-
<Grid RowDefinitions="32,32" ColumnDefinitions="120,*">
27+
<Grid RowDefinitions="32,32,32" ColumnDefinitions="120,*">
2828
<TextBlock Grid.Row="0" Grid.Column="0"
2929
Margin="0,0,8,0"
3030
HorizontalAlignment="Right"
@@ -35,6 +35,10 @@
3535
<CheckBox Grid.Row="1" Grid.Column="1"
3636
Content="{DynamicResource Text.Discard.IncludeIgnored}"
3737
IsChecked="{Binding IncludeIgnored, Mode=TwoWay}"/>
38+
39+
<CheckBox Grid.Row="2" Grid.Column="1"
40+
Content="{DynamicResource Text.Discard.IncludeUntracked}"
41+
IsChecked="{Binding IncludeUntracked, Mode=TwoWay}"/>
3842
</Grid>
3943
</DataTemplate>
4044

0 commit comments

Comments
 (0)