Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
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
10 changes: 6 additions & 4 deletions src/GitHub.App/Services/RepositoryCloneService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public async Task<ViewerRepositoriesModel> ReadViewerRepositories(HostAddress ad
/// <inheritdoc/>
public async Task CloneOrOpenRepository(
CloneDialogResult cloneDialogResult,
object progress = null)
object progress = null,
CancellationToken? cancellationToken = null)
{
Guard.ArgumentNotNull(cloneDialogResult, nameof(cloneDialogResult));

Expand Down Expand Up @@ -147,7 +148,7 @@ public async Task CloneOrOpenRepository(
else
{
var cloneUrl = repositoryUrl.ToString();
await CloneRepository(cloneUrl, repositoryPath, progress).ConfigureAwait(true);
await CloneRepository(cloneUrl, repositoryPath, progress, cancellationToken).ConfigureAwait(true);

if (isDotCom)
{
Expand Down Expand Up @@ -197,7 +198,8 @@ bool IsSolutionInRepository(string repositoryPath)
public async Task CloneRepository(
string cloneUrl,
string repositoryPath,
object progress = null)
object progress = null,
CancellationToken? cancellationToken = null)
{
Guard.ArgumentNotEmptyString(cloneUrl, nameof(cloneUrl));
Guard.ArgumentNotEmptyString(repositoryPath, nameof(repositoryPath));
Expand All @@ -210,7 +212,7 @@ public async Task CloneRepository(

try
{
await vsGitServices.Clone(cloneUrl, repositoryPath, true, progress);
await vsGitServices.Clone(cloneUrl, repositoryPath, true, progress, cancellationToken);
await usageTracker.IncrementCounter(x => x.NumberOfClones);

if (repositoryPath.StartsWith(DefaultClonePath, StringComparison.OrdinalIgnoreCase))
Expand Down
10 changes: 6 additions & 4 deletions src/GitHub.Exports.Reactive/Services/IRepositoryCloneService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using GitHub.Models;
using GitHub.Primitives;
Expand Down Expand Up @@ -27,11 +26,13 @@ public interface IRepositoryCloneService
/// System.IProgress&lt;Microsoft.VisualStudio.Shell.ServiceProgressData&gt;, but
/// as that type is only available in VS2017+ it is typed as <see cref="object"/> here.
/// </param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns></returns>
Task CloneRepository(
string cloneUrl,
string repositoryPath,
object progress = null);
object progress = null,
CancellationToken? cancellationToken = null);

/// <summary>
/// Clones the specified repository into the specified directory or opens it if the directory already exists.
Expand All @@ -45,7 +46,8 @@ Task CloneRepository(
/// <returns></returns>
Task CloneOrOpenRepository(
CloneDialogResult cloneDialogResult,
object progress = null);
object progress = null,
CancellationToken? cancellationToken = null);

/// <summary>
/// Checks whether the specified destination directory already exists.
Expand Down
5 changes: 4 additions & 1 deletion src/GitHub.Exports/Services/IVSGitServices.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using GitHub.Models;

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

string GetActiveRepoPath();
LibGit2Sharp.IRepository GetActiveRepo();
Expand Down
7 changes: 4 additions & 3 deletions src/GitHub.StartPage/StartPagePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async Task<CodeContainer> RunAcquisition(IProgress<ServiceProgressData> download
try
{
var uiProvider = await Task.Run(() => Package.GetGlobalService(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider);
request = await ShowCloneDialog(uiProvider, downloadProgress, repository);
request = await ShowCloneDialog(uiProvider, downloadProgress, cancellationToken, repository);
}
catch (Exception e)
{
Expand All @@ -81,9 +81,10 @@ async Task<CodeContainer> RunAcquisition(IProgress<ServiceProgressData> download
lastAccessed: DateTimeOffset.UtcNow);
}

async Task<CloneDialogResult> ShowCloneDialog(
static async Task<CloneDialogResult> ShowCloneDialog(
IGitHubServiceProvider gitHubServiceProvider,
IProgress<ServiceProgressData> progress,
CancellationToken cancellationToken,
RepositoryModel repository = null)
{
var dialogService = gitHubServiceProvider.GetService<IDialogService>();
Expand All @@ -110,7 +111,7 @@ async Task<CloneDialogResult> ShowCloneDialog(
{
try
{
await cloneService.CloneOrOpenRepository(result, progress);
await cloneService.CloneOrOpenRepository(result, progress, cancellationToken);
usageTracker.IncrementCounter(x => x.NumberOfStartPageClones).Forget();
}
catch
Expand Down
12 changes: 7 additions & 5 deletions src/GitHub.TeamFoundation.14/Services/VSGitServices.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.ComponentModel.Composition;
Expand Down Expand Up @@ -74,7 +75,8 @@ public async Task Clone(
string cloneUrl,
string clonePath,
bool recurseSubmodules,
object progress = null)
object progress = null,
CancellationToken? cancellationToken = null)
{
var teamExplorer = serviceProvider.TryGetService<ITeamExplorer>();
Assumes.Present(teamExplorer);
Expand All @@ -84,13 +86,13 @@ public async Task Clone(
NavigateToHomePage(teamExplorer); // Show progress on Team Explorer - Home
await WaitForCloneOnHomePageAsync(teamExplorer);
#elif TEAMEXPLORER15 || TEAMEXPLORER16
// The ServiceProgressData type is in a Visual Studio 2019 assembly that we don't currently have access to.
// Using reflection to call the CloneAsync in order to avoid conflicts with the Visual Studio 2017 version.
// Progress won't be displayed on the status bar, but it appears prominently on the Team Explorer Home view.
// The progress parameter uses the ServiceProgressData type which is defined in
// Microsoft.VisualStudio.Shell.Framework. Referencing this assembly directly
// would cause type conflicts, so we're using reflection to call CloneAsync.
var gitExt = serviceProvider.GetService<IGitActionsExt>();
var cloneAsyncMethod = typeof(IGitActionsExt).GetMethod(nameof(IGitActionsExt.CloneAsync));
Assumes.NotNull(cloneAsyncMethod);
var cloneParameters = new object[] { cloneUrl, clonePath, recurseSubmodules, null, null };
var cloneParameters = new object[] { cloneUrl, clonePath, recurseSubmodules, cancellationToken, progress };
var cloneTask = (Task)cloneAsyncMethod.Invoke(gitExt, cloneParameters);

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