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 @@ -1065,6 +1065,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 @@ -1069,6 +1069,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 @@ -1066,6 +1066,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
57 changes: 57 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 @@ -122,6 +124,61 @@ public void CloseAll()
_ignoreIndexChange = false;
}

public async Task FetchAllRepositoriesAsync()
{
// avoid collection was modified while enumerating.
var pages = new List<LauncherPage>();
pages.AddRange(Pages);

var total = 0;
var succeeded = 0;
var noRemoteNames = new List<string>();
var skippedNames = new List<string>();
var failedNames = new List<string>();

foreach (var page in pages)
{
if (page.Data is not Repository repo)
continue;

if (repo.Remotes.Count == 0)
{
noRemoteNames.Add(page.Node.Name);
continue;
}

total++;
var result = await repo.FetchAllRemotesAsync();
switch (result.Status)
{
case Repository.FetchAllStatus.Succeeded:
succeeded++;
break;
case Repository.FetchAllStatus.Skipped:
skippedNames.Add(page.Node.Name);
total--;
break;
case Repository.FetchAllStatus.Failed:
var remotesInfo = string.Join(", ", result.FailedRemotes);
failedNames.Add($"{page.Node.Name} (remote: {remotesInfo})");
break;
}
}

var message = $"Fetched {succeeded}/{total} repositories";

if (noRemoteNames.Count > 0)
message += $"\n{noRemoteNames.Count} repositories skipped (no remote):\n {string.Join("\n ", noRemoteNames)}";

if (skippedNames.Count > 0)
message += $"\n{skippedNames.Count} repositories skipped:\n {string.Join("\n ", skippedNames)}";

if (failedNames.Count > 0)
message += $"\n{failedNames.Count} repositories failed:\n {string.Join("\n ", failedNames)}";

Models.Notification.Send(null, message, succeeded < total);
}

public void SwitchWorkspace(Workspace to)
{
if (to == null || to.IsActive)
Expand Down
52 changes: 52 additions & 0 deletions src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,58 @@ public async Task FetchAsync(bool autoStart)
ShowPopup(new Fetch(this));
}

public enum FetchAllStatus
{
Succeeded,
Failed,
Skipped,
}

public class FetchAllRemotesResult
{
public FetchAllStatus Status { get; set; } = FetchAllStatus.Succeeded;
public List<string> FailedRemotes { get; } = new List<string>();
}

public async Task<FetchAllRemotesResult> FetchAllRemotesAsync()
{
var result = new FetchAllRemotesResult();

if (IsAutoFetching)
{
result.Status = FetchAllStatus.Skipped;
return result;
}

CommandLog log = null;

try
{
IsAutoFetching = true;
log = CreateLog("Fetch");

foreach (var remote in _remotes)
{
var succ = await new Commands.Fetch(FullPath, remote).Use(log).ExecAsync();
if (!succ)
result.FailedRemotes.Add(remote.Name);
}

_lastFetchTime = DateTime.Now;
}
catch
{
// Ignore all exceptions.
result.FailedRemotes.Add("*");
}

IsAutoFetching = false;
log?.Complete();

result.Status = result.FailedRemotes.Count == 0 ? FetchAllStatus.Succeeded : FetchAllStatus.Failed;
return result;
}

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 @@ -405,6 +406,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
Loading