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

Commit fced2fe

Browse files
authored
Merge pull request #2198 from github/fixes/2196-clone-progress
Ensure that clone from Start Page shows progress status bar
2 parents b4404e2 + 073a2d2 commit fced2fe

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

src/GitHub.App/Services/RepositoryCloneService.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public async Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress ad
114114
/// <inheritdoc/>
115115
public async Task CloneOrOpenRepository(
116116
CloneDialogResult cloneDialogResult,
117-
object progress = null)
117+
object progress = null,
118+
CancellationToken? cancellationToken = null)
118119
{
119120
Guard.ArgumentNotNull(cloneDialogResult, nameof(cloneDialogResult));
120121

@@ -147,7 +148,7 @@ public async Task CloneOrOpenRepository(
147148
else
148149
{
149150
var cloneUrl = repositoryUrl.ToString();
150-
await CloneRepository(cloneUrl, repositoryPath, progress).ConfigureAwait(true);
151+
await CloneRepository(cloneUrl, repositoryPath, progress, cancellationToken).ConfigureAwait(true);
151152

152153
if (isDotCom)
153154
{
@@ -197,7 +198,8 @@ bool IsSolutionInRepository(string repositoryPath)
197198
public async Task CloneRepository(
198199
string cloneUrl,
199200
string repositoryPath,
200-
object progress = null)
201+
object progress = null,
202+
CancellationToken? cancellationToken = null)
201203
{
202204
Guard.ArgumentNotEmptyString(cloneUrl, nameof(cloneUrl));
203205
Guard.ArgumentNotEmptyString(repositoryPath, nameof(repositoryPath));
@@ -210,7 +212,7 @@ public async Task CloneRepository(
210212

211213
try
212214
{
213-
await vsGitServices.Clone(cloneUrl, repositoryPath, true, progress);
215+
await vsGitServices.Clone(cloneUrl, repositoryPath, true, progress, cancellationToken);
214216
await usageTracker.IncrementCounter(x => x.NumberOfClones);
215217

216218
if (repositoryPath.StartsWith(DefaultClonePath, StringComparison.OrdinalIgnoreCase))

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Threading;
32
using System.Threading.Tasks;
43
using GitHub.Models;
54
using GitHub.Primitives;
@@ -27,11 +26,13 @@ public interface IRepositoryCloneService
2726
/// System.IProgress&lt;Microsoft.VisualStudio.Shell.ServiceProgressData&gt;, but
2827
/// as that type is only available in VS2017+ it is typed as <see cref="object"/> here.
2928
/// </param>
29+
/// <param name="cancellationToken">A cancellation token.</param>
3030
/// <returns></returns>
3131
Task CloneRepository(
3232
string cloneUrl,
3333
string repositoryPath,
34-
object progress = null);
34+
object progress = null,
35+
CancellationToken? cancellationToken = null);
3536

3637
/// <summary>
3738
/// Clones the specified repository into the specified directory or opens it if the directory already exists.
@@ -45,7 +46,8 @@ Task CloneRepository(
4546
/// <returns></returns>
4647
Task CloneOrOpenRepository(
4748
CloneDialogResult cloneDialogResult,
48-
object progress = null);
49+
object progress = null,
50+
CancellationToken? cancellationToken = null);
4951

5052
/// <summary>
5153
/// Checks whether the specified destination directory already exists.

src/GitHub.Exports/Services/IVSGitServices.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Threading;
34
using System.Threading.Tasks;
45
using GitHub.Models;
56

@@ -20,13 +21,15 @@ public interface IVSGitServices
2021
/// System.IProgress&lt;Microsoft.VisualStudio.Shell.ServiceProgressData&gt;, but
2122
/// as that type is only available in VS2017+ it is typed as <see cref="object"/> here.
2223
/// </param>
24+
/// <param name="cancellationToken">A cancellation token.</param>
2325
/// <seealso cref="System.IProgress{T}"/>
2426
/// <seealso cref="Microsoft.VisualStudio.Shell.ServiceProgressData"/>
2527
Task Clone(
2628
string cloneUrl,
2729
string clonePath,
2830
bool recurseSubmodules,
29-
object progress = null);
31+
object progress = null,
32+
CancellationToken? cancellationToken = null);
3033

3134
string GetActiveRepoPath();
3235
LibGit2Sharp.IRepository GetActiveRepo();

src/GitHub.StartPage/StartPagePackage.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async Task<CodeContainer> RunAcquisition(IProgress<ServiceProgressData> download
5757
try
5858
{
5959
var uiProvider = await Task.Run(() => Package.GetGlobalService(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider);
60-
request = await ShowCloneDialog(uiProvider, downloadProgress, repository);
60+
request = await ShowCloneDialog(uiProvider, downloadProgress, cancellationToken, repository);
6161
}
6262
catch (Exception e)
6363
{
@@ -81,9 +81,10 @@ async Task<CodeContainer> RunAcquisition(IProgress<ServiceProgressData> download
8181
lastAccessed: DateTimeOffset.UtcNow);
8282
}
8383

84-
async Task<CloneDialogResult> ShowCloneDialog(
84+
static async Task<CloneDialogResult> ShowCloneDialog(
8585
IGitHubServiceProvider gitHubServiceProvider,
8686
IProgress<ServiceProgressData> progress,
87+
CancellationToken cancellationToken,
8788
RepositoryModel repository = null)
8889
{
8990
var dialogService = gitHubServiceProvider.GetService<IDialogService>();
@@ -110,7 +111,7 @@ async Task<CloneDialogResult> ShowCloneDialog(
110111
{
111112
try
112113
{
113-
await cloneService.CloneOrOpenRepository(result, progress);
114+
await cloneService.CloneOrOpenRepository(result, progress, cancellationToken);
114115
usageTracker.IncrementCounter(x => x.NumberOfStartPageClones).Forget();
115116
}
116117
catch

src/GitHub.TeamFoundation.14/Services/VSGitServices.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading;
23
using System.Collections.Generic;
34
using System.Diagnostics.CodeAnalysis;
45
using System.ComponentModel.Composition;
@@ -74,7 +75,8 @@ public async Task Clone(
7475
string cloneUrl,
7576
string clonePath,
7677
bool recurseSubmodules,
77-
object progress = null)
78+
object progress = null,
79+
CancellationToken? cancellationToken = null)
7880
{
7981
var teamExplorer = serviceProvider.TryGetService<ITeamExplorer>();
8082
Assumes.Present(teamExplorer);
@@ -84,13 +86,13 @@ public async Task Clone(
8486
NavigateToHomePage(teamExplorer); // Show progress on Team Explorer - Home
8587
await WaitForCloneOnHomePageAsync(teamExplorer);
8688
#elif TEAMEXPLORER15 || TEAMEXPLORER16
87-
// The ServiceProgressData type is in a Visual Studio 2019 assembly that we don't currently have access to.
88-
// Using reflection to call the CloneAsync in order to avoid conflicts with the Visual Studio 2017 version.
89-
// Progress won't be displayed on the status bar, but it appears prominently on the Team Explorer Home view.
89+
// The progress parameter uses the ServiceProgressData type which is defined in
90+
// Microsoft.VisualStudio.Shell.Framework. Referencing this assembly directly
91+
// would cause type conflicts, so we're using reflection to call CloneAsync.
9092
var gitExt = serviceProvider.GetService<IGitActionsExt>();
9193
var cloneAsyncMethod = typeof(IGitActionsExt).GetMethod(nameof(IGitActionsExt.CloneAsync));
9294
Assumes.NotNull(cloneAsyncMethod);
93-
var cloneParameters = new object[] { cloneUrl, clonePath, recurseSubmodules, null, null };
95+
var cloneParameters = new object[] { cloneUrl, clonePath, recurseSubmodules, cancellationToken, progress };
9496
var cloneTask = (Task)cloneAsyncMethod.Invoke(gitExt, cloneParameters);
9597

9698
NavigateToHomePage(teamExplorer); // Show progress on Team Explorer - Home

0 commit comments

Comments
 (0)