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

Commit 1618a86

Browse files
committed
Add tests for CloneService with empty directory.
1 parent b7cd425 commit 1618a86

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/GitHub.App/Services/RepositoryCloneService.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,12 @@ public async Task CloneRepository(
206206

207207
// Switch to a thread pool thread for IO then back to the main thread to call
208208
// vsGitServices.Clone() as this must be called on the main thread.
209-
await ThreadingHelper.SwitchToPoolThreadAsync();
210-
operatingSystem.Directory.CreateDirectory(repositoryPath);
211-
await ThreadingHelper.SwitchToMainThreadAsync();
209+
if (!DestinationDirectoryExists(repositoryPath))
210+
{
211+
await ThreadingHelper.SwitchToPoolThreadAsync();
212+
operatingSystem.Directory.CreateDirectory(repositoryPath);
213+
await ThreadingHelper.SwitchToMainThreadAsync();
214+
}
212215

213216
try
214217
{

test/GitHub.App.UnitTests/Services/RepositoryCloneServiceTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ public async Task CleansDirectoryOnCloneFailed(string cloneUrl, string clonePath
136136
await vsGitServices.Received().Clone(cloneUrl, clonePath, true);
137137
}
138138

139+
[TestCase("https://github.com/foo/bar", @"c:\empty\directory")]
140+
public async Task CloneIntoEmptyDirectory(string cloneUrl, string clonePath)
141+
{
142+
var operatingSystem = Substitute.For<IOperatingSystem>();
143+
operatingSystem.Directory.DirectoryExists(clonePath).Returns(true);
144+
operatingSystem.Directory.IsEmpty(clonePath).Returns(true);
145+
var vsGitServices = Substitute.For<IVSGitServices>();
146+
var cloneService = CreateRepositoryCloneService(operatingSystem: operatingSystem, vsGitServices: vsGitServices);
147+
await cloneService.CloneRepository(cloneUrl, clonePath);
148+
149+
operatingSystem.Directory.DidNotReceive().CreateDirectory(clonePath);
150+
await vsGitServices.Received().Clone(cloneUrl, clonePath, true);
151+
}
152+
139153
static RepositoryCloneService CreateRepositoryCloneService(IOperatingSystem operatingSystem = null,
140154
IVSGitServices vsGitServices = null, IUsageTracker usageTracker = null,
141155
ITeamExplorerServices teamExplorerServices = null, IGitHubServiceProvider serviceProvider = null)

0 commit comments

Comments
 (0)