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

Commit 48bf070

Browse files
Merge branch 'master' into autocompletebox
2 parents 5a6e48b + 285c8a5 commit 48bf070

20 files changed

+114
-50
lines changed

src/GitHub.App/Services/RepositoryCloneService.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public async Task CloneOrOpenRepository(
129129

130130
var repositoryUrl = url.ToRepositoryUrl();
131131
var isDotCom = HostAddress.IsGitHubDotComUri(repositoryUrl);
132-
if (DestinationDirectoryExists(repositoryPath))
132+
if (DestinationDirectoryExists(repositoryPath) && !DestinationDirectoryEmpty(repositoryPath))
133133
{
134134
if (!IsSolutionInRepository(repositoryPath))
135135
{
@@ -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
{
@@ -232,6 +235,9 @@ public async Task CloneRepository(
232235
/// <inheritdoc/>
233236
public bool DestinationDirectoryExists(string path) => operatingSystem.Directory.DirectoryExists(path);
234237

238+
/// <inheritdoc/>
239+
public bool DestinationDirectoryEmpty(string path) => operatingSystem.Directory.GetDirectory(path).IsEmpty;
240+
235241
/// <inheritdoc/>
236242
public bool DestinationFileExists(string path) => operatingSystem.File.Exists(path);
237243

src/GitHub.App/ViewModels/Dialog/Clone/RepositoryCloneViewModel.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ public RepositoryCloneViewModel(
6767

6868
var canClone = Observable.CombineLatest(
6969
repository, this.WhenAnyValue(x => x.Path),
70-
(repo, path) => repo != null && !service.DestinationFileExists(path) && !service.DestinationDirectoryExists(path));
70+
(repo, path) => repo != null && !service.DestinationFileExists(path) &&
71+
(!service.DestinationDirectoryExists(path)) || service.DestinationDirectoryEmpty(path));
7172

7273
var canOpen = Observable.CombineLatest(
7374
repository, this.WhenAnyValue(x => x.Path),
74-
(repo, path) => repo != null && !service.DestinationFileExists(path) && service.DestinationDirectoryExists(path));
75+
(repo, path) => repo != null && !service.DestinationFileExists(path) && service.DestinationDirectoryExists(path)
76+
&& !service.DestinationDirectoryEmpty(path));
7577

7678
Browse = ReactiveCommand.Create(() => BrowseForDirectory());
7779
Clone = ReactiveCommand.CreateFromObservable(
@@ -236,13 +238,13 @@ string ValidatePathWarning(RepositoryModel repositoryModel, string path)
236238
return Resources.DestinationAlreadyExists;
237239
}
238240

239-
if (service.DestinationDirectoryExists(path))
241+
if (service.DestinationDirectoryExists(path) && !service.DestinationDirectoryEmpty(path))
240242
{
241243
using (var repository = gitService.GetRepository(path))
242244
{
243245
if (repository == null)
244246
{
245-
return Resources.CantFindARepositoryAtLocalPath;
247+
return Resources.DirectoryAtDestinationNotEmpty;
246248
}
247249

248250
var localUrl = gitService.GetRemoteUri(repository)?.ToRepositoryUrl();
@@ -254,7 +256,8 @@ string ValidatePathWarning(RepositoryModel repositoryModel, string path)
254256
var targetUrl = repositoryModel.CloneUrl?.ToRepositoryUrl();
255257
if (localUrl != targetUrl)
256258
{
257-
return string.Format(CultureInfo.CurrentCulture, Resources.LocalRepositoryHasARemoteOf, localUrl);
259+
return string.Format(CultureInfo.CurrentCulture, Resources.LocalRepositoryHasARemoteOf,
260+
localUrl);
258261
}
259262

260263
return Resources.YouHaveAlreadyClonedToThisLocation;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ Task CloneOrOpenRepository(
5858
/// </returns>
5959
bool DestinationDirectoryExists(string path);
6060

61+
/// <summary>
62+
/// Checks whether the specified destination directory is empty.
63+
/// </summary>
64+
/// <param name="path">The destination path.</param>
65+
/// <returns>
66+
/// true if a directory is empty <paramref name="path"/>; otherwise false.
67+
/// </returns>
68+
bool DestinationDirectoryEmpty(string path);
69+
6170
/// <summary>
6271
/// Checks whether the specified destination file already exists.
6372
/// </summary>

src/GitHub.Resources/Resources.Designer.cs

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.Resources/Resources.cs-CZ.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>V aktuálním úložišti se nepodařilo najít cílovou adresu URL. Zkuste to znovu po načtení změn.</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>V tomto umístění je už adresář, ale neobsahuje úložiště.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>Úložiště už v tomto umístění existuje, ale nemá vzdálené úložiště s názvem origin.</value>

src/GitHub.Resources/Resources.de-DE.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>Die Ziel-URL wurde im aktuellen Repository nicht gefunden. Versuchen Sie es nach einem Abrufvorgang (fetch) noch einmal.</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>An diesem Speicherort liegt bereits ein Verzeichnis vor, aber es enthält kein Repository.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>An diesem Speicherort ist bereits ein Repository vorhanden, das aber kein Remoterepository namens "origin" aufweist.</value>

src/GitHub.Resources/Resources.es-ES.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>No se encontró la dirección URL de destino en el repositorio actual. Vuelva a intentarlo tras una recuperación de cambios.</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>Ya hay un directorio en esta ubicación, pero no contiene un repositorio.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>Ya existe un repositorio en esta ubicación, pero no tiene un repositorio remoto con el nombre "origen".</value>

src/GitHub.Resources/Resources.fr-FR.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>L'URL cible est introuvable dans le dépôt actuel. Réessayez après une récupération (fetch).</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>Un répertoire est déjà présent à cet emplacement, mais il ne contient pas de dépôt.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>Un dépôt existe déjà à cet emplacement, mais il n'a pas de dépôt distant nommé « origin ».</value>

src/GitHub.Resources/Resources.it-IT.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>Non è stato trovato alcun URL di destinazione nel repository corrente. Riprovare dopo aver eseguito il comando fetch.</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>In questo percorso esiste già una directory che però non contiene un repository.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>In questo percorso esiste già un repository che però non include un repository remoto denominato "origin".</value>

src/GitHub.Resources/Resources.ja-JP.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>現在のリポジトリにターゲット URL が見つかりませんでした。フェッチを実行した後、もう一度お試しください。</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>この場所に既にディレクトリがありますが、リポジトリが含まれていません。</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>この場所にリポジトリが既に存在しますが、そのリポジトリには "origin" という名前のリモートがありません。</value>

src/GitHub.Resources/Resources.ko-KR.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>현재 리포지토리에서 대상 URL을 찾을 수 없습니다. 페치를 수행한 후 다시 시도하세요.</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>이 위치에 이미 디렉터리가 있지만, 디렉터리에 리포지토리가 없습니다.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>리포지토리가 이 위치에 이미 있지만, "origin"이라는 원격 항목을 포함하지 않습니다.</value>

src/GitHub.Resources/Resources.pl-PL.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>Nie można odnaleźć docelowego adresu URL w bieżącym repozytorium. Spróbuj ponownie po zakończeniu pobierania.</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>W tej lokalizacji istnieje już katalog, ale nie zawiera on repozytorium.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>Repozytorium już istnieje w tej lokalizacji, ale nie ma zdalnego repozytorium o nazwie „origin”.</value>

src/GitHub.Resources/Resources.pt-BR.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>Não foi possível encontrar a URL de destino no repositório atual. Tente novamente depois de efetuar um fetch.</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>Já existe um diretório neste local, mas ele não contém um repositório.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>Já existe um repositório neste local, mas ele não tem um repositório remoto com o nome "origem".</value>

src/GitHub.Resources/Resources.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>Couldn't find target URL in current repository. Try again after doing a fetch.</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>There is already a directory at this location, but it doesn't contain a repository.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>A repository already exists at this location, but it doesn't have a remote named "origin".</value>
@@ -878,4 +878,4 @@ https://git-scm.com/download/win</value>
878878
<data name="RepositorySelectContributedRepositories" xml:space="preserve">
879879
<value>Contributed to repositories</value>
880880
</data>
881-
</root>
881+
</root>

src/GitHub.Resources/Resources.ru-RU.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>Не удалось найти целевой URL-адрес в текущем репозитории. Выполните принесение и повторите попытку.</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>В этом расположении уже существует каталог, но он не содержит репозиторий.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>В этом расположении уже существует репозиторий, но у него отсутствует удаленный репозиторий с именем "origin".</value>

src/GitHub.Resources/Resources.tr-TR.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>Hedef URL geçerli depoda bulunamadı. Getirme işlemi gerçekleştirdikten sonra yeniden deneyin.</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>Bu konumda zaten bir dizin var ancak bir depo içermiyor.</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>Bu konumda bir depo zaten var ancak bu deponun "origin" adlı bir uzak deposu yok.</value>

src/GitHub.Resources/Resources.zh-CN.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>当前存储库中找不到目标 URL。请执行提取后重试。</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>在此位置已存在一个目录,但它不包含存储库。</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>此位置已存在一个存储库,但该存储库不具有名为 "origin" 的远程库。</value>

src/GitHub.Resources/Resources.zh-TW.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ https://git-scm.com/download/win</value>
809809
<data name="NoResolveSameOwnerMessage" xml:space="preserve">
810810
<value>在目前存放庫中找不到目標 URL。請在執行擷取後再試一次。</value>
811811
</data>
812-
<data name="CantFindARepositoryAtLocalPath" xml:space="preserve">
813-
<value>此位置已經有一個目錄,但它並未包含存放庫。</value>
812+
<data name="DirectoryAtDestinationNotEmpty" xml:space="preserve">
813+
<value>The directory at the destination path is not empty.</value>
814814
</data>
815815
<data name="LocalRepositoryDoesntHaveARemoteOrigin" xml:space="preserve">
816816
<value>存放庫已存在於此位置,但其不具有名為 "origin" 的遠端存放庫。</value>

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ await usageTracker.Received(numberOfCalls).IncrementCounter(
121121
((MemberExpression)x.Body).Member.Name == counterName));
122122
}
123123

124-
[TestCase("https://github.com/failing/url", @"c:\dev\bar")]
125-
public async Task CleansDirectoryOnCloneFailed(string cloneUrl, string clonePath)
124+
[Test]
125+
public async Task CleansDirectoryOnCloneFailed()
126126
{
127+
var cloneUrl = "https://github.com/failing/url";
128+
var clonePath = @"c:\dev\bar";
127129
var operatingSystem = Substitute.For<IOperatingSystem>();
128130
var vsGitServices = Substitute.For<IVSGitServices>();
129131
vsGitServices.Clone(cloneUrl, clonePath, true).Returns(x => { throw new Exception(); });
@@ -136,6 +138,22 @@ public async Task CleansDirectoryOnCloneFailed(string cloneUrl, string clonePath
136138
await vsGitServices.Received().Clone(cloneUrl, clonePath, true);
137139
}
138140

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

0 commit comments

Comments
 (0)