diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 96399d52ef..2871a50ba4 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -1051,6 +1051,7 @@ Template: ${0}$ WORKSPACE: Configure Workspaces... + Fetch All Repositories WORKTREE BRANCH Copy Path diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 71d41fa744..0068729ef7 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -1055,6 +1055,7 @@ 模板:${0}$ 工作区: 配置工作区... + 拉取工作区所有仓库 本地工作树 連結分支 复制工作树路径 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 20343afaee..7982a279b0 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -1039,6 +1039,7 @@ 範本: ${0}$ 工作區: 設定工作區... + 提取工作區所有存放庫 本機工作樹 分支 複製工作樹路徑 diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 1cf00a848c..595c72f480 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.IO; using System.Text; +using System.Threading.Tasks; using Avalonia.Collections; using Avalonia.Threading; @@ -122,6 +124,26 @@ public void CloseAll() _ignoreIndexChange = false; } + public async Task FetchAllRepositoriesAsync() + { + // avoid collection was modified while enumerating. + var pages = new List(); + pages.AddRange(Pages); + + var count = 0; + foreach (var page in pages) + { + if (page.Data is Repository repo) + { + if (await repo.FetchAllRemotesAsync()) + count++; + } + } + + if (count > 0) + Models.Notification.Send(null, $"Fetched {count} repositories"); + } + public void SwitchWorkspace(Workspace to) { if (to == null || to.IsActive) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 450bdb41c6..6ce58c66f2 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -697,6 +697,40 @@ public async Task FetchAsync(bool autoStart) ShowPopup(new Fetch(this)); } + public async Task FetchAllRemotesAsync() + { + if (IsAutoFetching) + return false; + + CommandLog log = null; + + try + { + var lockFile = Path.Combine(GitDir, "index.lock"); + if (File.Exists(lockFile)) + return false; + + if (_remotes.Count == 0) + return false; + + IsAutoFetching = true; + log = CreateLog("Fetch"); + + foreach (var remote in _remotes) + await new Commands.Fetch(FullPath, remote.Name).Use(log).RunAsync(); + + _lastFetchTime = DateTime.Now; + } + catch + { + // Ignore all exceptions. + } + + IsAutoFetching = false; + log?.Complete(); + return true; + } + public async Task PullAsync(bool autoStart) { if (IsBare || !CanCreatePopup()) diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index 0aedfbc721..e67eda1e3e 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Avalonia; using Avalonia.Controls; @@ -409,6 +410,19 @@ private void OnOpenWorkspaceMenu(object sender, RoutedEventArgs e) menu.Items.Add(new MenuItem() { Header = "-" }); + var hasRepos = launcher.Pages.Any(p => p.Data is ViewModels.Repository); + + var fetchAll = new MenuItem(); + fetchAll.Header = App.Text("Workspace.FetchAllRepositories"); + fetchAll.Icon = this.CreateMenuIcon("Icons.Fetch"); + fetchAll.IsEnabled = hasRepos; + fetchAll.Click += async (_, ev) => + { + await launcher.FetchAllRepositoriesAsync(); + ev.Handled = true; + }; + menu.Items.Add(fetchAll); + var configure = new MenuItem(); configure.Header = App.Text("Workspace.Configure"); configure.Click += async (_, ev) =>