diff --git a/src/Commands/Fetch.cs b/src/Commands/Fetch.cs index 25c499fd..08d2d1c6 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, Action outputHandler) + public Fetch(string repo, string remote, bool noTags, bool prune, Action outputHandler) { _outputHandler = outputHandler; WorkingDirectory = repo; @@ -18,6 +18,9 @@ namespace SourceGit.Commands else Args += "--force "; + if (prune) + Args += "--prune "; + Args += remote; } diff --git a/src/Commands/Pull.cs b/src/Commands/Pull.cs index a4efa4b6..732530f5 100644 --- a/src/Commands/Pull.cs +++ b/src/Commands/Pull.cs @@ -4,7 +4,7 @@ namespace SourceGit.Commands { public class Pull : Command { - public Pull(string repo, string remote, string branch, bool useRebase, bool noTags, Action outputHandler) + public Pull(string repo, string remote, string branch, bool useRebase, bool noTags, bool prune, Action outputHandler) { _outputHandler = outputHandler; WorkingDirectory = repo; @@ -17,6 +17,8 @@ namespace SourceGit.Commands Args += "--rebase "; if (noTags) Args += "--no-tags "; + if (prune) + Args += "--prune "; Args += $"{remote} {branch}"; } diff --git a/src/Models/RepositorySettings.cs b/src/Models/RepositorySettings.cs index ce4119f5..a8cc5770 100644 --- a/src/Models/RepositorySettings.cs +++ b/src/Models/RepositorySettings.cs @@ -16,6 +16,12 @@ namespace SourceGit.Models set; } = DealWithLocalChanges.DoNothing; + public bool EnablePruneOnFetch + { + get; + set; + } = false; + public bool FetchWithoutTags { get; diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index b2e0ef8d..c6f88ed1 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -145,6 +145,7 @@ Fetch remotes automatically Minute(s) Default Remote + Enable --prune on fetch Enable --signoff for commit ISSUE TRACKER Add Sample Github Rule diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 333dbd06..a274c06c 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -149,6 +149,7 @@ 分钟 默认远程 提交信息追加署名 (--signoff) + 拉取更新时启用修剪(--prune) ISSUE追踪 新增匹配Github Issue规则 新增匹配Jira规则 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 06f9bba4..ce62c299 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -149,6 +149,7 @@ 分鐘 預設遠端存放庫 提交訊息追加署名 (--signoff) + 提取變更时啟用修剪(--prune) Issue 追蹤 新增符合 GitHub Issue 規則 新增符合 Jira 規則 diff --git a/src/ViewModels/AddRemote.cs b/src/ViewModels/AddRemote.cs index d2a7729a..d6424572 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, SetProgressDescription).Exec(); + new Commands.Fetch(_repo.FullPath, _name, false, false, SetProgressDescription).Exec(); } CallUIThread(() => { diff --git a/src/ViewModels/Fetch.cs b/src/ViewModels/Fetch.cs index 3fe92a5f..7f54680d 100644 --- a/src/ViewModels/Fetch.cs +++ b/src/ViewModels/Fetch.cs @@ -40,6 +40,8 @@ namespace SourceGit.ViewModels { _repo.SetWatcherEnabled(false); + var notags = _repo.Settings.FetchWithoutTags; + var prune = _repo.Settings.EnablePruneOnFetch; return Task.Run(() => { if (FetchAllRemotes) @@ -47,13 +49,13 @@ namespace SourceGit.ViewModels foreach (var remote in _repo.Remotes) { SetProgressDescription($"Fetching remote: {remote.Name}"); - new Commands.Fetch(_repo.FullPath, remote.Name, NoTags, SetProgressDescription).Exec(); + new Commands.Fetch(_repo.FullPath, remote.Name, notags, prune, SetProgressDescription).Exec(); } } else { SetProgressDescription($"Fetching remote: {SelectedRemote.Name}"); - new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, NoTags, SetProgressDescription).Exec(); + new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, prune, SetProgressDescription).Exec(); } CallUIThread(() => diff --git a/src/ViewModels/Pull.cs b/src/ViewModels/Pull.cs index b5c038ae..6c493449 100644 --- a/src/ViewModels/Pull.cs +++ b/src/ViewModels/Pull.cs @@ -147,7 +147,13 @@ namespace SourceGit.ViewModels if (FetchAllBranches) { SetProgressDescription($"Fetching remote: {_selectedRemote.Name}..."); - rs = new Commands.Fetch(_repo.FullPath, _selectedRemote.Name, NoTags, SetProgressDescription).Exec(); + rs = new Commands.Fetch( + _repo.FullPath, + _selectedRemote.Name, + NoTags, + _repo.Settings.EnablePruneOnFetch, + SetProgressDescription).Exec(); + if (!rs) { CallUIThread(() => _repo.SetWatcherEnabled(true)); @@ -171,7 +177,14 @@ namespace SourceGit.ViewModels else { SetProgressDescription($"Pull {_selectedRemote.Name}/{_selectedBranch.Name}..."); - rs = new Commands.Pull(_repo.FullPath, _selectedRemote.Name, _selectedBranch.Name, UseRebase, NoTags, SetProgressDescription).Exec(); + rs = new Commands.Pull( + _repo.FullPath, + _selectedRemote.Name, + _selectedBranch.Name, + UseRebase, + NoTags, + _repo.Settings.EnablePruneOnFetch, + SetProgressDescription).Exec(); } if (rs && needPopStash) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 917833db..c64967d1 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -2137,7 +2137,7 @@ namespace SourceGit.ViewModels IsAutoFetching = true; Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching))); - new Commands.Fetch(_fullpath, "--all", false, null) { RaiseError = false }.Exec(); + new Commands.Fetch(_fullpath, "--all", false, _settings.EnablePruneOnFetch, null) { RaiseError = false }.Exec(); _lastFetchTime = DateTime.Now; IsAutoFetching = false; Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching))); diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index d7eaa1cb..94efc09d 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -67,6 +67,12 @@ namespace SourceGit.ViewModels set => _repo.Settings.EnableSignOffForCommit = value; } + public bool EnablePruneOnFetch + { + get => _repo.Settings.EnablePruneOnFetch; + set => _repo.Settings.EnablePruneOnFetch = value; + } + public bool EnableAutoFetch { get => _repo.Settings.EnableAutoFetch; @@ -134,7 +140,7 @@ namespace SourceGit.ViewModels AvailableOpenAIServices.Add(service.Name); if (AvailableOpenAIServices.IndexOf(PreferedOpenAIService) == -1) - PreferedOpenAIService = "---"; + PreferedOpenAIService = "---"; _cached = new Commands.Config(repo.FullPath).ListAll(); if (_cached.TryGetValue("user.name", out var name)) diff --git a/src/Views/RepositoryConfigure.axaml b/src/Views/RepositoryConfigure.axaml index ced0dab6..535a016c 100644 --- a/src/Views/RepositoryConfigure.axaml +++ b/src/Views/RepositoryConfigure.axaml @@ -51,7 +51,7 @@ - + - + + +