From 3c595223e65ccc6fa5a4ef93e1b9c56eca12797f Mon Sep 17 00:00:00 2001 From: Oleg Kosmakov <1533952+kosmakoff@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:06:02 +0100 Subject: [PATCH] feat: Added option to prune during fetch --- src/Commands/Fetch.cs | 5 ++++- src/Resources/Locales/en_US.axaml | 1 + src/ViewModels/AddRemote.cs | 2 +- src/ViewModels/Fetch.cs | 15 +++++++++++---- src/ViewModels/Pull.cs | 1 + src/ViewModels/Repository.cs | 2 +- src/Views/Fetch.axaml | 7 ++++++- 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Commands/Fetch.cs b/src/Commands/Fetch.cs index 06ae8cb6..1835c58e 100644 --- a/src/Commands/Fetch.cs +++ b/src/Commands/Fetch.cs @@ -4,7 +4,7 @@ namespace SourceGit.Commands { public class Fetch : Command { - public Fetch(string repo, string remote, bool noTags, bool force, Action outputHandler) + public Fetch(string repo, string remote, bool noTags, bool force, bool prune, Action outputHandler) { _outputHandler = outputHandler; WorkingDirectory = repo; @@ -21,6 +21,9 @@ namespace SourceGit.Commands if (force) Args += "--force "; + if (prune) + Args += "--prune "; + Args += remote; } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 0da8b5ed..e528e2ad 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -287,6 +287,7 @@ Fetch all remotes Force override local refs Fetch without tags + Prune outdated remote refs Remote: Fetch Remote Changes Assume unchanged diff --git a/src/ViewModels/AddRemote.cs b/src/ViewModels/AddRemote.cs index d6424572..2ca7449f 100644 --- a/src/ViewModels/AddRemote.cs +++ b/src/ViewModels/AddRemote.cs @@ -100,7 +100,7 @@ namespace SourceGit.ViewModels { SetProgressDescription("Fetching from added remote ..."); new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", _useSSH ? SSHKey : null); - new Commands.Fetch(_repo.FullPath, _name, false, false, SetProgressDescription).Exec(); + new Commands.Fetch(_repo.FullPath, _name, false, false, false, SetProgressDescription).Exec(); } CallUIThread(() => { diff --git a/src/ViewModels/Fetch.cs b/src/ViewModels/Fetch.cs index d816d0b8..559562ea 100644 --- a/src/ViewModels/Fetch.cs +++ b/src/ViewModels/Fetch.cs @@ -28,6 +28,12 @@ namespace SourceGit.ViewModels set => _repo.Settings.FetchWithoutTags = value; } + public bool Prune + { + get; + set; + } + public bool Force { get => _repo.Settings.EnableForceOnFetch; @@ -46,8 +52,9 @@ namespace SourceGit.ViewModels { _repo.SetWatcherEnabled(false); - var notags = _repo.Settings.FetchWithoutTags; - var force = _repo.Settings.EnableForceOnFetch; + var notags = NoTags; + var force = Force; + var prune = Prune; return Task.Run(() => { if (FetchAllRemotes) @@ -55,13 +62,13 @@ namespace SourceGit.ViewModels foreach (var remote in _repo.Remotes) { SetProgressDescription($"Fetching remote: {remote.Name}"); - new Commands.Fetch(_repo.FullPath, remote.Name, notags, force, SetProgressDescription).Exec(); + new Commands.Fetch(_repo.FullPath, remote.Name, notags, force, prune, SetProgressDescription).Exec(); } } else { SetProgressDescription($"Fetching remote: {SelectedRemote.Name}"); - new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force, SetProgressDescription).Exec(); + new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force, prune, SetProgressDescription).Exec(); } CallUIThread(() => diff --git a/src/ViewModels/Pull.cs b/src/ViewModels/Pull.cs index 52f98d87..17c4d2ba 100644 --- a/src/ViewModels/Pull.cs +++ b/src/ViewModels/Pull.cs @@ -151,6 +151,7 @@ namespace SourceGit.ViewModels _repo.FullPath, _selectedRemote.Name, NoTags, + false, false, SetProgressDescription).Exec(); diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 6e8a5290..c3df5ad5 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -2433,7 +2433,7 @@ namespace SourceGit.ViewModels Dispatcher.UIThread.Invoke(() => IsAutoFetching = true); foreach (var remote in remotes) - new Commands.Fetch(_fullpath, remote, false, false, null) { RaiseError = false }.Exec(); + new Commands.Fetch(_fullpath, remote, false, false, false, null) { RaiseError = false }.Exec(); _lastFetchTime = DateTime.Now; Dispatcher.UIThread.Invoke(() => IsAutoFetching = false); } diff --git a/src/Views/Fetch.axaml b/src/Views/Fetch.axaml index 67669380..eb550b84 100644 --- a/src/Views/Fetch.axaml +++ b/src/Views/Fetch.axaml @@ -11,7 +11,7 @@ - + + +