Skip to content

Commit 3cbffa6

Browse files
committed
feature: add an option in repository configuration to enable --prune on fetch (#590)
Signed-off-by: leo <[email protected]>
1 parent a4befd0 commit 3cbffa6

File tree

12 files changed

+50
-11
lines changed

12 files changed

+50
-11
lines changed

src/Commands/Fetch.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace SourceGit.Commands
44
{
55
public class Fetch : Command
66
{
7-
public Fetch(string repo, string remote, bool noTags, Action<string> outputHandler)
7+
public Fetch(string repo, string remote, bool noTags, bool prune, Action<string> outputHandler)
88
{
99
_outputHandler = outputHandler;
1010
WorkingDirectory = repo;
@@ -18,6 +18,9 @@ public Fetch(string repo, string remote, bool noTags, Action<string> outputHandl
1818
else
1919
Args += "--force ";
2020

21+
if (prune)
22+
Args += "--prune ";
23+
2124
Args += remote;
2225
}
2326

src/Commands/Pull.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace SourceGit.Commands
44
{
55
public class Pull : Command
66
{
7-
public Pull(string repo, string remote, string branch, bool useRebase, bool noTags, Action<string> outputHandler)
7+
public Pull(string repo, string remote, string branch, bool useRebase, bool noTags, bool prune, Action<string> outputHandler)
88
{
99
_outputHandler = outputHandler;
1010
WorkingDirectory = repo;
@@ -17,6 +17,8 @@ public Pull(string repo, string remote, string branch, bool useRebase, bool noTa
1717
Args += "--rebase ";
1818
if (noTags)
1919
Args += "--no-tags ";
20+
if (prune)
21+
Args += "--prune ";
2022

2123
Args += $"{remote} {branch}";
2224
}

src/Models/RepositorySettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public DealWithLocalChanges DealWithLocalChangesOnCheckoutBranch
1616
set;
1717
} = DealWithLocalChanges.DoNothing;
1818

19+
public bool EnablePruneOnFetch
20+
{
21+
get;
22+
set;
23+
} = false;
24+
1925
public bool FetchWithoutTags
2026
{
2127
get;

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
<x:String x:Key="Text.Configure.Git.AutoFetch" xml:space="preserve">Fetch remotes automatically</x:String>
146146
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">Minute(s)</x:String>
147147
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">Default Remote</x:String>
148+
<x:String x:Key="Text.Configure.Git.EnablePruneOnFetch" xml:space="preserve">Enable --prune on fetch</x:String>
148149
<x:String x:Key="Text.Configure.Git.EnableSignOff" xml:space="preserve">Enable --signoff for commit</x:String>
149150
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">ISSUE TRACKER</x:String>
150151
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">Add Sample Github Rule</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">分钟</x:String>
150150
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">默认远程</x:String>
151151
<x:String x:Key="Text.Configure.Git.EnableSignOff" xml:space="preserve">提交信息追加署名 (--signoff)</x:String>
152+
<x:String x:Key="Text.Configure.Git.EnablePruneOnFetch" xml:space="preserve">拉取更新时启用修剪(--prune)</x:String>
152153
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">ISSUE追踪</x:String>
153154
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">新增匹配Github Issue规则</x:String>
154155
<x:String x:Key="Text.Configure.IssueTracker.AddSampleJira" xml:space="preserve">新增匹配Jira规则</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
<x:String x:Key="Text.Configure.Git.AutoFetchIntervalSuffix" xml:space="preserve">分鐘</x:String>
150150
<x:String x:Key="Text.Configure.Git.DefaultRemote" xml:space="preserve">預設遠端存放庫</x:String>
151151
<x:String x:Key="Text.Configure.Git.EnableSignOff" xml:space="preserve">提交訊息追加署名 (--signoff)</x:String>
152+
<x:String x:Key="Text.Configure.Git.EnablePruneOnFetch" xml:space="preserve">提取變更时啟用修剪(--prune)</x:String>
152153
<x:String x:Key="Text.Configure.IssueTracker" xml:space="preserve">Issue 追蹤</x:String>
153154
<x:String x:Key="Text.Configure.IssueTracker.AddSampleGithub" xml:space="preserve">新增符合 GitHub Issue 規則</x:String>
154155
<x:String x:Key="Text.Configure.IssueTracker.AddSampleJira" xml:space="preserve">新增符合 Jira 規則</x:String>

src/ViewModels/AddRemote.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public override Task<bool> Sure()
100100
{
101101
SetProgressDescription("Fetching from added remote ...");
102102
new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
103-
new Commands.Fetch(_repo.FullPath, _name, false, SetProgressDescription).Exec();
103+
new Commands.Fetch(_repo.FullPath, _name, false, false, SetProgressDescription).Exec();
104104
}
105105
CallUIThread(() =>
106106
{

src/ViewModels/Fetch.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,22 @@ public override Task<bool> Sure()
4040
{
4141
_repo.SetWatcherEnabled(false);
4242

43+
var notags = _repo.Settings.FetchWithoutTags;
44+
var prune = _repo.Settings.EnablePruneOnFetch;
4345
return Task.Run(() =>
4446
{
4547
if (FetchAllRemotes)
4648
{
4749
foreach (var remote in _repo.Remotes)
4850
{
4951
SetProgressDescription($"Fetching remote: {remote.Name}");
50-
new Commands.Fetch(_repo.FullPath, remote.Name, NoTags, SetProgressDescription).Exec();
52+
new Commands.Fetch(_repo.FullPath, remote.Name, notags, prune, SetProgressDescription).Exec();
5153
}
5254
}
5355
else
5456
{
5557
SetProgressDescription($"Fetching remote: {SelectedRemote.Name}");
56-
new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, NoTags, SetProgressDescription).Exec();
58+
new Commands.Fetch(_repo.FullPath, SelectedRemote.Name, notags, prune, SetProgressDescription).Exec();
5759
}
5860

5961
CallUIThread(() =>

src/ViewModels/Pull.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,13 @@ public override Task<bool> Sure()
147147
if (FetchAllBranches)
148148
{
149149
SetProgressDescription($"Fetching remote: {_selectedRemote.Name}...");
150-
rs = new Commands.Fetch(_repo.FullPath, _selectedRemote.Name, NoTags, SetProgressDescription).Exec();
150+
rs = new Commands.Fetch(
151+
_repo.FullPath,
152+
_selectedRemote.Name,
153+
NoTags,
154+
_repo.Settings.EnablePruneOnFetch,
155+
SetProgressDescription).Exec();
156+
151157
if (!rs)
152158
{
153159
CallUIThread(() => _repo.SetWatcherEnabled(true));
@@ -171,7 +177,14 @@ public override Task<bool> Sure()
171177
else
172178
{
173179
SetProgressDescription($"Pull {_selectedRemote.Name}/{_selectedBranch.Name}...");
174-
rs = new Commands.Pull(_repo.FullPath, _selectedRemote.Name, _selectedBranch.Name, UseRebase, NoTags, SetProgressDescription).Exec();
180+
rs = new Commands.Pull(
181+
_repo.FullPath,
182+
_selectedRemote.Name,
183+
_selectedBranch.Name,
184+
UseRebase,
185+
NoTags,
186+
_repo.Settings.EnablePruneOnFetch,
187+
SetProgressDescription).Exec();
175188
}
176189

177190
if (rs && needPopStash)

src/ViewModels/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ private void AutoFetchImpl(object sender)
21372137

21382138
IsAutoFetching = true;
21392139
Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching)));
2140-
new Commands.Fetch(_fullpath, "--all", false, null) { RaiseError = false }.Exec();
2140+
new Commands.Fetch(_fullpath, "--all", false, _settings.EnablePruneOnFetch, null) { RaiseError = false }.Exec();
21412141
_lastFetchTime = DateTime.Now;
21422142
IsAutoFetching = false;
21432143
Dispatcher.UIThread.Invoke(() => OnPropertyChanged(nameof(IsAutoFetching)));

0 commit comments

Comments
 (0)