Skip to content

Commit 0ae49c0

Browse files
committed
feature: supports to disable specific remote from auto-fetch (#2285)
Add `Enable Auto-Fetch` context menu entry to select remote. This menu item only visible when you have enable `Fetch remotes automatically` feature in `Preferences` dialog. Signed-off-by: leo <longshuang@msn.cn>
1 parent cace869 commit 0ae49c0

8 files changed

Lines changed: 52 additions & 16 deletions

File tree

src/Commands/QueryRemotes.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ public QueryRemotes(string repo)
2424
if (!rs.IsSuccess)
2525
return outs;
2626

27+
var config = await new Config(WorkingDirectory).ReadAllAsync().ConfigureAwait(false);
28+
var disableAutoFetchRemotes = new HashSet<string>();
29+
foreach (var (k, v) in config)
30+
{
31+
if (k.StartsWith("remote.", StringComparison.Ordinal) &&
32+
k.EndsWith(".disableautofetch", StringComparison.Ordinal) &&
33+
v.Equals("true", StringComparison.OrdinalIgnoreCase))
34+
{
35+
var remoteName = k.Substring(7, k.Length - 24).Trim('"');
36+
disableAutoFetchRemotes.Add(remoteName);
37+
}
38+
}
39+
2740
var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
2841
foreach (var line in lines)
2942
{
@@ -35,6 +48,7 @@ public QueryRemotes(string repo)
3548
{
3649
Name = match.Groups[1].Value,
3750
URL = match.Groups[2].Value,
51+
DisableAutoFetch = disableAutoFetchRemotes.Contains(match.Groups[1].Value)
3852
};
3953

4054
if (outs.Find(x => x.Name == remote.Name) != null)

src/Models/Remote.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public partial class Remote
3131

3232
public string Name { get; set; }
3333
public string URL { get; set; }
34+
public bool DisableAutoFetch { get; set; }
3435

3536
public static bool IsSSH(string url)
3637
{

src/Resources/Icons.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<StreamGeometry x:Key="Icons.Action">M41 512c0-128 46-241 138-333C271 87 384 41 512 41s241 46 333 138c92 92 138 205 138 333s-46 241-138 333c-92 92-205 138-333 138s-241-46-333-138C87 753 41 640 41 512zm87 0c0 108 36 195 113 271s164 113 271 113c108 0 195-36 271-113s113-164 113-271-36-195-113-271c-77-77-164-113-271-113-108 0-195 36-271 113C164 317 128 404 128 512zm256 148V292l195 113L768 512l-195 113-195 113v-77zm148-113-61 36V440l61 36 61 36-61 36z</StreamGeometry>
33
<StreamGeometry x:Key="Icons.AIAssist">M304 464a128 128 0 01128-128c71 0 128 57 128 128v224a32 32 0 01-64 0V592h-128v95a32 32 0 01-64 0v-224zm64 1v64h128v-64a64 64 0 00-64-64c-35 0-64 29-64 64zM688 337c18 0 32 14 32 32v319a32 32 0 01-32 32c-18 0-32-14-32-32v-319a32 32 0 0132-32zM84 911l60-143A446 446 0 0164 512C64 265 265 64 512 64s448 201 448 448-201 448-448 448c-54 0-105-9-153-27l-242 22a32 32 0 01-32-44zm133-150-53 126 203-18 13 5c41 15 85 23 131 23 212 0 384-172 384-384S724 128 512 128 128 300 128 512c0 82 26 157 69 220l20 29z</StreamGeometry>
44
<StreamGeometry x:Key="Icons.Archive">M366 146l293 0 0-73-293 0 0 73zm658 366 0 274q0 38-27 65t-65 27l-841 0q-38 0-65-27t-27-65l0-274 384 0 0 91q0 15 11 26t26 11l183 0q15 0 26-11t11-26l0-91 384 0zm-439 0 0 73-146 0 0-73 146 0zm439-274 0 219-1024 0 0-219q0-38 27-65t65-27l201 0 0-91q0-23 16-39t39-16l329 0q23 0 39 16t16 39l0 91 201 0q38 0 65 27t27 65z</StreamGeometry>
5+
<StreamGeometry x:Key="Icons.AutoFetch">M567 192C385 192 238 335 238 512H128l142 138 3 5L421 512H311c0-138 114-249 256-249s256 111 256 249c0 138-114 249-256 249a258 258 0 01-181-73l-52 51A332 332 0 00567 832C749 832 896 689 896 512S749 192 567 192zm-37 178v178l155 90 28-46-129-74v-148H530z</StreamGeometry>
56
<StreamGeometry x:Key="Icons.Bad">M851 755q0 23-16 39l-78 78q-16 16-39 16t-39-16l-168-168-168 168q-16 16-39 16t-39-16l-78-78q-16-16-16-39t16-39l168-168-168-168q-16-16-16-39t16-39l78-78q16-16 39-16t39 16l168 168 168-168q16-16 39-16t39 16l78 78q16 16 16 39t-16 39l-168 168 168 168q16 16 16 39z</StreamGeometry>
67
<StreamGeometry x:Key="Icons.Binary">M71 1024V0h661L953 219V1024H71zm808-731-220-219H145V951h735V293zM439 512h-220V219h220V512zm-74-219H292v146h74v-146zm0 512h74v73h-220v-73H292v-146H218V585h147v219zm294-366h74V512H512v-73h74v-146H512V219h147v219zm74 439H512V585h220v293zm-74-219h-74v146h74v-146z</StreamGeometry>
78
<StreamGeometry x:Key="Icons.Bisect">M128 384a43 43 0 0043-43V213a43 43 0 0143-43h128a43 43 0 000-85H213a128 128 0 00-128 128v128a43 43 0 0043 43zm213 469H213a43 43 0 01-43-43v-128a43 43 0 00-85 0v128a128 128 0 00128 128h128a43 43 0 000-85zm384-299a43 43 0 000-85h-49A171 171 0 00555 347V299a43 43 0 00-85 0v49A171 171 0 00347 469H299a43 43 0 000 85h49A171 171 0 00469 677V725a43 43 0 0085 0v-49A171 171 0 00677 555zm-213 43a85 85 0 1185-85 85 85 0 01-85 85zm384 43a43 43 0 00-43 43v128a43 43 0 01-43 43h-128a43 43 0 000 85h128a128 128 0 00128-128v-128a43 43 0 00-43-43zM811 85h-128a43 43 0 000 85h128a43 43 0 0143 43v128a43 43 0 0085 0V213a128 128 0 00-128-128z</StreamGeometry>

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@
736736
<x:String x:Key="Text.RemoteCM.CustomAction" xml:space="preserve">Custom Action</x:String>
737737
<x:String x:Key="Text.RemoteCM.Delete" xml:space="preserve">Delete...</x:String>
738738
<x:String x:Key="Text.RemoteCM.Edit" xml:space="preserve">Edit...</x:String>
739+
<x:String x:Key="Text.RemoteCM.EnableAutoFetch" xml:space="preserve">Enable Auto-Fetch</x:String>
739740
<x:String x:Key="Text.RemoteCM.Fetch" xml:space="preserve">Fetch</x:String>
740741
<x:String x:Key="Text.RemoteCM.OpenInBrowser" xml:space="preserve">Open In Browser</x:String>
741742
<x:String x:Key="Text.RemoteCM.Prune" xml:space="preserve">Prune</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@
740740
<x:String x:Key="Text.RemoteCM.CustomAction" xml:space="preserve">自定义操作</x:String>
741741
<x:String x:Key="Text.RemoteCM.Delete" xml:space="preserve">删除 ...</x:String>
742742
<x:String x:Key="Text.RemoteCM.Edit" xml:space="preserve">编辑 ...</x:String>
743+
<x:String x:Key="Text.RemoteCM.EnableAutoFetch" xml:space="preserve">启用自动拉取</x:String>
743744
<x:String x:Key="Text.RemoteCM.Fetch" xml:space="preserve">拉取(fetch)更新</x:String>
744745
<x:String x:Key="Text.RemoteCM.OpenInBrowser" xml:space="preserve">在浏览器中打开</x:String>
745746
<x:String x:Key="Text.RemoteCM.Prune" xml:space="preserve">清理远程已删除分支</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@
740740
<x:String x:Key="Text.RemoteCM.CustomAction" xml:space="preserve">自訂動作</x:String>
741741
<x:String x:Key="Text.RemoteCM.Delete" xml:space="preserve">刪除...</x:String>
742742
<x:String x:Key="Text.RemoteCM.Edit" xml:space="preserve">編輯...</x:String>
743+
<x:String x:Key="Text.RemoteCM.EnableAutoFetch" xml:space="preserve">啟用定時自動提取</x:String>
743744
<x:String x:Key="Text.RemoteCM.Fetch" xml:space="preserve">提取 (fetch) 更新</x:String>
744745
<x:String x:Key="Text.RemoteCM.OpenInBrowser" xml:space="preserve">在瀏覽器中存取網址</x:String>
745746
<x:String x:Key="Text.RemoteCM.Prune" xml:space="preserve">清理遠端已刪除分支</x:String>

src/ViewModels/Repository.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,14 @@ public void DeleteRemote(Models.Remote remote)
14711471
ShowPopup(new DeleteRemote(this, remote));
14721472
}
14731473

1474+
public async Task ToggleAutoFetchOnRemoteAsync(Models.Remote remote)
1475+
{
1476+
var val = remote.DisableAutoFetch ? "false" : "true";
1477+
var succ = await new Commands.Config(FullPath).SetAsync($"remote.{remote.Name.Quoted()}.disableautofetch", val);
1478+
if (succ)
1479+
remote.DisableAutoFetch = !remote.DisableAutoFetch;
1480+
}
1481+
14741482
public void AddSubmodule()
14751483
{
14761484
if (CanCreatePopup())
@@ -1881,27 +1889,19 @@ private async Task AutoFetchOnUIThread()
18811889

18821890
var remotes = new List<string>();
18831891
foreach (var r in _remotes)
1884-
remotes.Add(r.Name);
1892+
{
1893+
if (!r.DisableAutoFetch)
1894+
remotes.Add(r.Name);
1895+
}
18851896

18861897
if (remotes.Count == 0)
18871898
return;
18881899

18891900
IsAutoFetching = true;
18901901
log = CreateLog("Auto-Fetch");
18911902

1892-
if (_uiStates.FetchAllRemotes)
1893-
{
1894-
foreach (var remote in remotes)
1895-
await new Commands.Fetch(FullPath, remote).Use(log).RunAsync();
1896-
}
1897-
else
1898-
{
1899-
var remote = string.IsNullOrEmpty(_settings.DefaultRemote) ?
1900-
remotes.Find(x => x.Equals(_settings.DefaultRemote, StringComparison.Ordinal)) :
1901-
remotes[0];
1902-
1903+
foreach (var remote in remotes)
19031904
await new Commands.Fetch(FullPath, remote).Use(log).RunAsync();
1904-
}
19051905

19061906
_lastFetchTime = DateTime.Now;
19071907
IsAutoFetching = false;

src/Views/BranchTree.axaml.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,26 @@ private ContextMenu CreateContextMenuForRemote(ViewModels.Repository repo, Model
10591059
e.Handled = true;
10601060
};
10611061

1062+
menu.Items.Add(fetch);
1063+
menu.Items.Add(prune);
1064+
menu.Items.Add(new MenuItem() { Header = "-" });
1065+
1066+
if (ViewModels.Preferences.Instance.EnableAutoFetch)
1067+
{
1068+
var toggleAutoFetch = new MenuItem();
1069+
toggleAutoFetch.Header = App.Text("RemoteCM.EnableAutoFetch");
1070+
toggleAutoFetch.Icon = this.CreateMenuIcon("Icons.AutoFetch");
1071+
toggleAutoFetch.Tag = remote.DisableAutoFetch ? "OFF" : "ON";
1072+
toggleAutoFetch.Click += async (_, e) =>
1073+
{
1074+
await repo.ToggleAutoFetchOnRemoteAsync(remote);
1075+
e.Handled = true;
1076+
};
1077+
1078+
menu.Items.Add(toggleAutoFetch);
1079+
menu.Items.Add(new MenuItem() { Header = "-" });
1080+
}
1081+
10621082
var edit = new MenuItem();
10631083
edit.Header = App.Text("RemoteCM.Edit");
10641084
edit.Icon = this.CreateMenuIcon("Icons.Edit");
@@ -1088,9 +1108,6 @@ private ContextMenu CreateContextMenuForRemote(ViewModels.Repository repo, Model
10881108
e.Handled = true;
10891109
};
10901110

1091-
menu.Items.Add(fetch);
1092-
menu.Items.Add(prune);
1093-
menu.Items.Add(new MenuItem() { Header = "-" });
10941111
menu.Items.Add(edit);
10951112
menu.Items.Add(delete);
10961113
menu.Items.Add(new MenuItem() { Header = "-" });

0 commit comments

Comments
 (0)