Fix mistaken errors when cloning FCP-Tools and Add more Logging

This commit is contained in:
Canon
2026-03-12 06:00:00 +08:00
parent e4e3e67d81
commit 683c5a8575
3 changed files with 22 additions and 9 deletions
+17 -4
View File
@@ -129,7 +129,7 @@ public partial class GitService : IGitService
return exitCode == 0;
}
public async Task<bool> CloneAsync(string url, string targetPath, IProgress<string>? progress = null,
public async Task<(bool Success, string? Error)> CloneAsync(string url, string targetPath, IProgress<string>? progress = null,
IProgress<double>? percentProgress = null, CancellationToken ct = default)
{
progress?.Report($"Cloning {url}...");
@@ -144,10 +144,23 @@ public partial class GitService : IGitService
ct,
timeoutMs: 300000); // 5 minute timeout for clone
if (exitCode != 0)
progress?.Report($"Clone failed: {error}");
// Exit code 141 = SIGPIPE (128+13), harmless when git's progress pipe closes early
if (exitCode != 0 && exitCode != 141)
{
var errorMessage = $"Clone failed (exit code {exitCode}): url={url}, target={targetPath}, git output: {error}";
progress?.Report(errorMessage);
return (Success: false, Error: errorMessage);
}
return exitCode == 0;
// Verify the clone actually produced a valid git repo
if (!Directory.Exists(targetPath) || !await IsGitRepositoryAsync(targetPath, ct))
{
var errorMessage = $"Clone appeared to finish but target is not a valid git repo: url={url}, target={targetPath}, git output: {error}";
progress?.Report(errorMessage);
return (Success: false, Error: errorMessage);
}
return (Success: true, Error: null);
}
public async Task<IReadOnlyList<string>> GetRemoteBranchesAsync(string path, CancellationToken ct = default)
+1 -1
View File
@@ -12,7 +12,7 @@ public interface IGitService
Task<IReadOnlyList<GitCommitInfo>> GetIncomingCommitsAsync(string path, int limit = 10, CancellationToken ct = default);
Task<bool> FetchAsync(string path, IProgress<string>? progress = null, CancellationToken ct = default);
Task<bool> PullAsync(string path, IProgress<string>? progress = null, CancellationToken ct = default);
Task<bool> CloneAsync(string url, string targetPath, IProgress<string>? progress = null, IProgress<double>? percentProgress = null, CancellationToken ct = default);
Task<(bool Success, string? Error)> CloneAsync(string url, string targetPath, IProgress<string>? progress = null, IProgress<double>? percentProgress = null, CancellationToken ct = default);
Task<IReadOnlyList<string>> GetRemoteBranchesAsync(string path, CancellationToken ct = default);
Task<bool> CheckoutAsync(string path, string branchOrCommit, CancellationToken ct = default);
Task<bool> ResetToCommitAsync(string path, string commitHash, CancellationToken ct = default);
+4 -4
View File
@@ -221,9 +221,9 @@ public class InteractiveMenu
{
var targetPath = Path.Combine(_modsDirectory, repo.Name);
var cloneOk = await _gitService.CloneAsync(repo.CloneUrl, targetPath, percentProgress: progress, ct: ct);
var result = await _gitService.CloneAsync(repo.CloneUrl, targetPath, percentProgress: progress, ct: ct);
return (Success: cloneOk, Error: cloneOk ? null : "Clone failed");
return (Success: result.Success, Error: result.Error);
});
ModTableRenderer.RenderUpdateSummary(results);
@@ -353,9 +353,9 @@ public class InteractiveMenu
Directory.Delete(mod.Path, recursive: true);
// Clone fresh with progress
var cloneOk = await _gitService.CloneAsync(repo.CloneUrl, mod.Path, percentProgress: progress, ct: ct);
var result = await _gitService.CloneAsync(repo.CloneUrl, mod.Path, percentProgress: progress, ct: ct);
return (Success: cloneOk, Error: cloneOk ? null : "Clone failed");
return (result.Success, result.Error);
}
catch (Exception ex)
{