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>

0 commit comments

Comments
 (0)