зеркало из https://github.com/github/VisualStudio.git
Ensure the target clone directory exists
This commit is contained in:
Родитель
5601cf9484
Коммит
7700c1896d
|
@ -6,6 +6,7 @@ using System.Reactive;
|
|||
using System.Reactive.Linq;
|
||||
using Microsoft.TeamFoundation.Git.Controls.Extensibility;
|
||||
using Octokit;
|
||||
using Rothko;
|
||||
|
||||
namespace GitHub.Services
|
||||
{
|
||||
|
@ -18,11 +19,13 @@ namespace GitHub.Services
|
|||
public class RepositoryCloneService : IRepositoryCloneService
|
||||
{
|
||||
readonly Lazy<IServiceProvider> serviceProvider;
|
||||
readonly IOperatingSystem operatingSystem;
|
||||
|
||||
[ImportingConstructor]
|
||||
public RepositoryCloneService(Lazy<IServiceProvider> serviceProvider)
|
||||
public RepositoryCloneService(Lazy<IServiceProvider> serviceProvider, IOperatingSystem operatingSystem)
|
||||
{
|
||||
this.serviceProvider = serviceProvider;
|
||||
this.operatingSystem = operatingSystem;
|
||||
}
|
||||
|
||||
private IServiceProvider ServiceProvider
|
||||
|
@ -32,10 +35,16 @@ namespace GitHub.Services
|
|||
|
||||
public IObservable<Unit> CloneRepository(string cloneUrl, string repositoryName, string repositoryPath)
|
||||
{
|
||||
Guard.ArgumentNotEmptyString(cloneUrl, "cloneUrl");
|
||||
Guard.ArgumentNotEmptyString(repositoryName, "repositoryName");
|
||||
Guard.ArgumentNotEmptyString(repositoryPath, "repositoryPath");
|
||||
|
||||
return Observable.Start(() =>
|
||||
{
|
||||
string path = Path.Combine(repositoryPath, repositoryName);
|
||||
|
||||
operatingSystem.Directory.CreateDirectory(path);
|
||||
|
||||
var gitExt = ServiceProvider.GetService(typeof(IGitRepositoriesExt)) as IGitRepositoriesExt;
|
||||
Debug.Assert(gitExt != null, "Could not get an instance of IGitRepositoriesExt");
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using GitHub.Services;
|
||||
using Microsoft.TeamFoundation.Git.Controls.Extensibility;
|
||||
using NSubstitute;
|
||||
using Rothko;
|
||||
using Xunit;
|
||||
|
||||
public class RepositoryCloneServiceTests
|
||||
{
|
||||
public class TheCloneRepositoryMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task ClonesToRepositoryPath()
|
||||
{
|
||||
var gitClone = Substitute.For<IGitRepositoriesExt>();
|
||||
var operatingSystem = Substitute.For<IOperatingSystem>();
|
||||
var serviceProvider = Substitute.For<IServiceProvider>();
|
||||
serviceProvider.GetService(typeof(IGitRepositoriesExt)).Returns(gitClone);
|
||||
var cloneService = new RepositoryCloneService(
|
||||
new Lazy<IServiceProvider>(() => serviceProvider),
|
||||
operatingSystem);
|
||||
|
||||
await cloneService.CloneRepository("https://github.com/foo/bar", "bar", @"c:\dev");
|
||||
|
||||
operatingSystem.Directory.Received().CreateDirectory(@"c:\dev\bar");
|
||||
gitClone.Received().Clone("https://github.com/foo/bar", @"c:\dev\bar", CloneOptions.RecurseSubmodule);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,6 +32,10 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.TeamFoundation.Git.Controls, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\Microsoft.TeamFoundation.Git.Controls.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.ComponentModelHost, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
<Reference Include="Microsoft.VisualStudio.CoreUtility, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
<Reference Include="Microsoft.VisualStudio.Language.Intellisense, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
|
@ -96,6 +100,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Args.cs" />
|
||||
<Compile Include="GitHub.App\Controllers\UIControllerTests.cs" />
|
||||
<Compile Include="GitHub.App\Services\RepositoryCloneServiceTests.cs" />
|
||||
<Compile Include="GitHub.App\ViewModels\LoginToGitHubViewModelTests.cs" />
|
||||
<Compile Include="GitHub.App\ViewModels\RepositoryCreationViewModelTests.cs" />
|
||||
<Compile Include="GitHub.UI\TwoFactorInputTests.cs" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче