Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@
<x:String x:Key="Text.WorkingCopy.UseCommitTemplate" xml:space="preserve">Template: ${0}$</x:String>
<x:String x:Key="Text.Workspace" xml:space="preserve">WORKSPACE: </x:String>
<x:String x:Key="Text.Workspace.Configure" xml:space="preserve">Configure Workspaces...</x:String>
<x:String x:Key="Text.Workspace.FetchAllRepositories" xml:space="preserve">Fetch All Repositories</x:String>
<x:String x:Key="Text.Worktree" xml:space="preserve">WORKTREE</x:String>
<x:String x:Key="Text.Worktree.Branch" xml:space="preserve">BRANCH</x:String>
<x:String x:Key="Text.Worktree.CopyPath" xml:space="preserve">Copy Path</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@
<x:String x:Key="Text.WorkingCopy.UseCommitTemplate" xml:space="preserve">模板:${0}$</x:String>
<x:String x:Key="Text.Workspace" xml:space="preserve">工作区:</x:String>
<x:String x:Key="Text.Workspace.Configure" xml:space="preserve">配置工作区...</x:String>
<x:String x:Key="Text.Workspace.FetchAllRepositories" xml:space="preserve">拉取工作区所有仓库</x:String>
<x:String x:Key="Text.Worktree" xml:space="preserve">本地工作树</x:String>
<x:String x:Key="Text.Worktree.Branch" xml:space="preserve">連結分支</x:String>
<x:String x:Key="Text.Worktree.CopyPath" xml:space="preserve">复制工作树路径</x:String>
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Locales/zh_TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@
<x:String x:Key="Text.WorkingCopy.UseCommitTemplate" xml:space="preserve">範本: ${0}$</x:String>
<x:String x:Key="Text.Workspace" xml:space="preserve">工作區: </x:String>
<x:String x:Key="Text.Workspace.Configure" xml:space="preserve">設定工作區...</x:String>
<x:String x:Key="Text.Workspace.FetchAllRepositories" xml:space="preserve">提取工作區所有存放庫</x:String>
<x:String x:Key="Text.Worktree" xml:space="preserve">本機工作區</x:String>
<x:String x:Key="Text.Worktree.Branch" xml:space="preserve">分支</x:String>
<x:String x:Key="Text.Worktree.CopyPath" xml:space="preserve">複製工作區路徑</x:String>
Expand Down
22 changes: 22 additions & 0 deletions src/ViewModels/Launcher.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -116,6 +118,26 @@ public void CloseAll()
_ignoreIndexChange = false;
}

public async Task FetchAllRepositoriesAsync()
{
// avoid collection was modified while enumerating.
var pages = new List<LauncherPage>();
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)
Expand Down
34 changes: 34 additions & 0 deletions src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,40 @@ public async Task FetchAsync(bool autoStart)
ShowPopup(new Fetch(this));
}

public async Task<bool> 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())
Expand Down
14 changes: 14 additions & 0 deletions src/Views/Launcher.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;

using Avalonia;
using Avalonia.Controls;
Expand Down Expand Up @@ -395,6 +396,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) =>
Expand Down