From 4ad7b58abe1c52726b3a5e211cb7a166513192a0 Mon Sep 17 00:00:00 2001 From: heartacker Date: Wed, 16 Jul 2025 13:37:57 +0800 Subject: [PATCH 1/2] 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. --- src/Commands/Discard.cs | 5 +++-- src/Resources/Locales/en_US.axaml | 1 + src/ViewModels/Discard.cs | 8 +++++++- src/ViewModels/Pull.cs | 2 +- src/Views/Discard.axaml | 6 +++++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Commands/Discard.cs b/src/Commands/Discard.cs index eaf5f844d..d358d6d86 100644 --- a/src/Commands/Discard.cs +++ b/src/Commands/Discard.cs @@ -12,15 +12,16 @@ public static class Discard /// /// /// + /// /// - public static async Task AllAsync(string repo, bool includeIgnored, Models.ICommandLog log) + public static async Task AllAsync(string repo, bool includeIgnored, bool includeUntracked, Models.ICommandLog log) { var changes = await new QueryLocalChanges(repo).GetResultAsync().ConfigureAwait(false); try { foreach (var c in changes) { - if (c.WorkTree == Models.ChangeState.Untracked || + if ((c.WorkTree == Models.ChangeState.Untracked && includeUntracked) || c.WorkTree == Models.ChangeState.Added || c.Index == Models.ChangeState.Added || c.Index == Models.ChangeState.Renamed) diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 6784923ce..028c76431 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -325,6 +325,7 @@ All local changes in working copy. Changes: Include ignored files + Include untracked files {0} changes will be discarded You can't undo this action!!! Bookmark: diff --git a/src/ViewModels/Discard.cs b/src/ViewModels/Discard.cs index 1fcda9049..41144d959 100644 --- a/src/ViewModels/Discard.cs +++ b/src/ViewModels/Discard.cs @@ -10,6 +10,12 @@ public bool IncludeIgnored get; set; } = false; + + public bool IncludeUntracked + { + get; + set; + } = false; } public class DiscardSingleFile @@ -65,7 +71,7 @@ public override async Task Sure() Use(log); if (Mode is DiscardAllMode all) - await Commands.Discard.AllAsync(_repo.FullPath, all.IncludeIgnored, log); + await Commands.Discard.AllAsync(_repo.FullPath, all.IncludeIgnored, all.IncludeUntracked, log); else await Commands.Discard.ChangesAsync(_repo.FullPath, _changes, log); diff --git a/src/ViewModels/Pull.cs b/src/ViewModels/Pull.cs index 9372f309f..c3156536a 100644 --- a/src/ViewModels/Pull.cs +++ b/src/ViewModels/Pull.cs @@ -125,7 +125,7 @@ public override async Task Sure() { if (DiscardLocalChanges) { - await Commands.Discard.AllAsync(_repo.FullPath, false, log); + await Commands.Discard.AllAsync(_repo.FullPath, false, false, log); } else { diff --git a/src/Views/Discard.axaml b/src/Views/Discard.axaml index 1699b0517..fa68bb984 100644 --- a/src/Views/Discard.axaml +++ b/src/Views/Discard.axaml @@ -24,7 +24,7 @@ - + + + From 0a799a4630be36665990c86c9590a2f555081ee7 Mon Sep 17 00:00:00 2001 From: heartacker Date: Wed, 16 Jul 2025 14:23:22 +0800 Subject: [PATCH 2/2] keep the old behavior while pulling --- src/ViewModels/Pull.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ViewModels/Pull.cs b/src/ViewModels/Pull.cs index c3156536a..54c936403 100644 --- a/src/ViewModels/Pull.cs +++ b/src/ViewModels/Pull.cs @@ -125,7 +125,7 @@ public override async Task Sure() { if (DiscardLocalChanges) { - await Commands.Discard.AllAsync(_repo.FullPath, false, false, log); + await Commands.Discard.AllAsync(_repo.FullPath, false, true, log); } else {