From 3e907dc4c4c424d8ee67d775fee83952fe4e085e Mon Sep 17 00:00:00 2001 From: Yitzchak Ben-Ezra Date: Mon, 22 Dec 2025 08:59:23 +0200 Subject: [PATCH] feat: prune on demand - with respect to git config as default the project already have global setting that is fully synced with git config. but sometimes there is a need to prune on demand. in these scenarios there is no way to do it via SourceGit and I find myself everytime switch to terminal I also saw there was another PR suggesting a fix for that - but this PR respects the repo config and git config --- src/Commands/Fetch.cs | 4 +++- src/Resources/Locales/en_US.axaml | 1 + src/ViewModels/AddRemote.cs | 2 +- src/ViewModels/Fetch.cs | 16 ++++++++++++++-- src/Views/Fetch.axaml | 7 ++++++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Commands/Fetch.cs b/src/Commands/Fetch.cs index 914361257..2a0a4e72a 100644 --- a/src/Commands/Fetch.cs +++ b/src/Commands/Fetch.cs @@ -5,7 +5,7 @@ namespace SourceGit.Commands { public class Fetch : Command { - public Fetch(string repo, string remote, bool noTags, bool force) + public Fetch(string repo, string remote, bool noTags, bool force, bool prune) { _remote = remote; @@ -17,6 +17,8 @@ public Fetch(string repo, string remote, bool noTags, bool force) builder.Append(noTags ? "--no-tags " : "--tags "); if (force) builder.Append("--force "); + if (prune) + builder.Append("--prune "); builder.Append(remote); Args = builder.ToString(); diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index daa23e13d..8e027ed82 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -386,6 +386,7 @@ Fetch all remotes Force override local refs Fetch without tags + Prune deleted branches Remote: Fetch Remote Changes Assume unchanged diff --git a/src/ViewModels/AddRemote.cs b/src/ViewModels/AddRemote.cs index fb5f0264b..f48c1e2b5 100644 --- a/src/ViewModels/AddRemote.cs +++ b/src/ViewModels/AddRemote.cs @@ -105,7 +105,7 @@ public override async Task Sure() .Use(log) .SetAsync($"remote.{_name}.sshkey", _useSSH ? SSHKey : null); - await new Commands.Fetch(_repo.FullPath, _name, false, false) + await new Commands.Fetch(_repo.FullPath, _name, false, false, false) .Use(log) .RunAsync(); } diff --git a/src/ViewModels/Fetch.cs b/src/ViewModels/Fetch.cs index 43bc5a18a..b39b2d73c 100644 --- a/src/ViewModels/Fetch.cs +++ b/src/ViewModels/Fetch.cs @@ -43,6 +43,12 @@ public bool Force set => _repo.Settings.EnableForceOnFetch = value; } + public bool Prune + { + get => _prune; + set => SetProperty(ref _prune, value); + } + public Fetch(Repository repo, Models.Remote preferredRemote = null) { _repo = repo; @@ -62,6 +68,10 @@ public Fetch(Repository repo, Models.Remote preferredRemote = null) { SelectedRemote = _repo.Remotes[0]; } + + // Initialize prune from git config + var pruneConfig = new Commands.Config(_repo.FullPath).Get("fetch.prune"); + _prune = pruneConfig == "true"; } public override async Task Sure() @@ -71,19 +81,20 @@ public override async Task Sure() var navigateToUpstreamHEAD = _repo.SelectedView is Histories { AutoSelectedCommit: { IsCurrentHead: true } }; var notags = _repo.Settings.FetchWithoutTags; var force = _repo.Settings.EnableForceOnFetch; + var prune = Prune; var log = _repo.CreateLog("Fetch"); Use(log); if (FetchAllRemotes) { foreach (var remote in _repo.Remotes) - await new Commands.Fetch(_repo.FullPath, remote.Name, notags, force) + await new Commands.Fetch(_repo.FullPath, remote.Name, notags, force, prune) .Use(log) .RunAsync(); } else { - await new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force) + await new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, force, prune) .Use(log) .RunAsync(); } @@ -106,5 +117,6 @@ public override async Task Sure() private readonly Repository _repo = null; private bool _fetchAllRemotes = false; + private bool _prune = false; } } diff --git a/src/Views/Fetch.axaml b/src/Views/Fetch.axaml index 1a60f3eb7..0cace187f 100644 --- a/src/Views/Fetch.axaml +++ b/src/Views/Fetch.axaml @@ -18,7 +18,7 @@ Text="{DynamicResource Text.Fetch.Title}"/> - + + +