Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit f589bfa

Browse files
committed
Report progress using IProgress<string>
This should make it easier to display incremental progress.
1 parent f894e2a commit f589bfa

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,16 @@ public IObservable<Unit> Push(ILocalRepositoryModel repository)
187187
}
188188

189189
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2201", Justification = "Prototype")]
190-
public async Task SyncSubmodules(ILocalRepositoryModel repository)
190+
public async Task<bool> SyncSubmodules(ILocalRepositoryModel repository, IProgress<string> progress)
191191
{
192192
var exitCode = Where("git");
193193
if (exitCode != 0)
194194
{
195-
throw new ApplicationException(App.Resources.CouldntFindGitOnPath);
195+
progress.Report(App.Resources.CouldntFindGitOnPath);
196+
return false;
196197
}
197198

198-
var output = new StringWriter(CultureInfo.InvariantCulture);
199-
var progress = new Progress<string>(line => output.WriteLine(line));
200-
exitCode = await SyncSubmodules(repository.LocalPath, progress);
201-
if (exitCode != 0)
202-
{
203-
var message = output.ToString();
204-
throw new ApplicationException(message);
205-
}
199+
return await SyncSubmodules(repository.LocalPath, progress) == 0;
206200
}
207201

208202
// LibGit2Sharp has limited submodule support so shelling out Git.exe for submodule commands.

src/GitHub.App/ViewModels/GitHubPane/PullRequestDetailViewModel.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Reactive.Linq;
88
using System.Reactive.Threading.Tasks;
99
using System.Threading.Tasks;
10+
using System.Globalization;
1011
using GitHub.App;
1112
using GitHub.Extensions;
1213
using GitHub.Factories;
@@ -17,7 +18,6 @@
1718
using LibGit2Sharp;
1819
using ReactiveUI;
1920
using Serilog;
20-
using GitHub.Extensions.Reactive;
2121

2222
namespace GitHub.ViewModels.GitHubPane
2323
{
@@ -676,9 +676,24 @@ IObservable<Unit> DoPush(object unused)
676676
});
677677
}
678678

679-
Task DoSyncSubmodules(object unused)
679+
async Task DoSyncSubmodules(object unused)
680680
{
681-
return pullRequestsService.SyncSubmodules(LocalRepository).ContinueWith(_ => usageTracker.IncrementCounter(x => x.NumberOfSyncSubmodules).Forget());
681+
usageTracker.IncrementCounter(x => x.NumberOfSyncSubmodules).Forget();
682+
683+
var progress = new CaptureProgress();
684+
var complete = await pullRequestsService.SyncSubmodules(LocalRepository, progress);
685+
if (!complete)
686+
{
687+
throw new ApplicationException(progress.ToString());
688+
}
689+
}
690+
691+
sealed class CaptureProgress : IProgress<string>, IDisposable
692+
{
693+
StringWriter writer = new StringWriter(CultureInfo.CurrentCulture);
694+
public void Report(string value) => writer.WriteLine(value);
695+
public override string ToString() => writer.ToString();
696+
public void Dispose() => writer.Dispose();
682697
}
683698

684699
class CheckoutCommandState : IPullRequestCheckoutState

src/GitHub.Exports.Reactive/Services/IPullRequestService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ IObservable<IPullRequestModel> CreatePullRequest(IModelService modelService,
5656
/// Sync submodules on the current branch.
5757
/// </summary>
5858
/// <param name="repository">The repository.</param>
59-
Task SyncSubmodules(ILocalRepositoryModel repository);
59+
Task<bool> SyncSubmodules(ILocalRepositoryModel repository, IProgress<string> progress);
6060

6161
/// <summary>
6262
/// Calculates the name of a local branch for a pull request avoiding clashes with existing branches.

0 commit comments

Comments
 (0)