Skip to content

Commit b26fbfd

Browse files
committed
feat: add untracked opt in discard(fix #1586)
- Add support for including untracked files in discard operations by introducing a new parameter. - Add localization string for including untracked files in discard operation. - Add support for discarding untracked files in the discard functionality. - Add force flag parameter to discard command for local changes. - Add include untracked files checkbox to discard view. - Fix missing parameter in discard changes command call for non-left changes case.
1 parent 935d30d commit b26fbfd

File tree

6 files changed

+24
-9
lines changed

6 files changed

+24
-9
lines changed

src/Commands/Discard.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ 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+
25+
if ((c.WorkTree == Models.ChangeState.Untracked && includeUntracked) ||
2426
c.WorkTree == Models.ChangeState.Added ||
2527
c.Index == Models.ChangeState.Added ||
2628
c.Index == Models.ChangeState.Renamed)
@@ -49,16 +51,18 @@ public static async Task AllAsync(string repo, bool includeIgnored, Models.IComm
4951
/// </summary>
5052
/// <param name="repo"></param>
5153
/// <param name="changes"></param>
54+
/// <param name="includeUntracked"></param>
5255
/// <param name="log"></param>
53-
public static async Task ChangesAsync(string repo, List<Models.Change> changes, Models.ICommandLog log)
56+
public static async Task ChangesAsync(string repo, List<Models.Change> changes, bool includeUntracked, Models.ICommandLog log)
5457
{
5558
var restores = new List<string>();
5659

5760
try
5861
{
5962
foreach (var c in changes)
6063
{
61-
if (c.WorkTree == Models.ChangeState.Untracked || c.WorkTree == Models.ChangeState.Added)
64+
if ((c.WorkTree == Models.ChangeState.Untracked && includeUntracked) ||
65+
c.WorkTree == Models.ChangeState.Added)
6266
{
6367
var fullPath = Path.Combine(repo, c.Path);
6468
if (Directory.Exists(fullPath))

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: 8 additions & 2 deletions
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,9 +71,9 @@ 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
70-
await Commands.Discard.ChangesAsync(_repo.FullPath, _changes, log);
76+
await Commands.Discard.ChangesAsync(_repo.FullPath, _changes, false, log);
7177

7278
log.Complete();
7379
_repo.MarkWorkingCopyDirtyManually();

src/ViewModels/Pull.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public override async Task<bool> Sure()
125125
{
126126
if (DiscardLocalChanges)
127127
{
128-
await Commands.Discard.AllAsync(_repo.FullPath, false, log);
128+
await Commands.Discard.AllAsync(_repo.FullPath, false, false, log);
129129
}
130130
else
131131
{

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

src/Views/TextDiffView.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ private async void OnDiscardChunk(object _1, RoutedEventArgs _2)
19341934

19351935
if (!selection.HasLeftChanges)
19361936
{
1937-
await Commands.Discard.ChangesAsync(repo.FullPath, [change], null);
1937+
await Commands.Discard.ChangesAsync(repo.FullPath, [change], false, null);
19381938
}
19391939
else
19401940
{

0 commit comments

Comments
 (0)