8000 Allow cloning of repositories into empty directories by YuPeiHenry · Pull Request #2316 · github/VisualStudio · GitHub
[go: up one dir, main page]

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

Allow cloning of repositories into empty directories #2316

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion src/GitHub.App/Services/RepositoryCloneService.cs
< 8000 tr data-hunk="4809085d1973a3dd3a7c52d3eae215f258e87601b60dc495aee16ce3992339ff" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public async Task CloneOrOpenRepository(

var repositoryUrl = url.ToRepositoryUrl();
var isDotCom = HostAddress.IsGitHubDotComUri(repositoryUrl);
if (DestinationDirectoryExists(repositoryPath))
if (DestinationDirectoryExists(repositoryPath) && !DestinationDirectoryEmpty(repositoryPath))
{
if (!IsSolutionInRepository(repositoryPath))
{
Expand Down Expand Up @@ -232,6 +232,9 @@ public async Task CloneRepository(
/// <inheritdoc/>
public bool DestinationDirectoryExists(string path) => operatingSystem.Directory.DirectoryExists(path);

/// <inheritdoc/>
public bool DestinationDirectoryEmpty(string path) => !DestinationDirectoryExists(path) || operatingSystem.Directory.GetDirectory(path).IsEmpty;

/// <inheritdoc/>
public bool DestinationFileExists(string path) => operatingSystem.File.Exists(path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ public RepositoryCloneViewModel(

var canClone = Observable.CombineLatest(
repository, this.WhenAnyValue(x => x.Path),
(repo, path) => repo != null && !service.DestinationFileExists(path) && !service.DestinationDirectoryExists(path));
(repo, path) => repo != null && !service.DestinationFileExists(path) &&
(!service.DestinationDirectoryExists(path)) || service.DestinationDirectoryEmpty(path));

var canOpen = Observable.CombineLatest(
repository, this.WhenAnyValue(x => x.Path),
(repo, path) => repo != null && !service.DestinationFileExists(path) && service.DestinationDirectoryExists(path));
(repo, path) => repo != null && !service.DestinationFileExists(path) && service.DestinationDirectoryExists(path)
&& !service.DestinationDirectoryEmpty(path));

Browse = ReactiveCommand.Create(() => BrowseForDirectory());
Clone = ReactiveCommand.CreateFromObservable(
Expand Down Expand Up @@ -240,6 +242,11 @@ string ValidatePathWarning(RepositoryModel repositoryModel, string path)
{
using (var repository = gitService.GetRepository(path))
{
if (service.DestinationDirectoryEmpty(path))
{
return null;
}

if (repository == null)
{
return Resources.CantFindARepositoryAtLocalPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ Task CloneOrOpenRepository(
/// </returns>
bool DestinationDirectoryExists(string path);

/// <summary>
/// Checks whether the specified destination directory is empty.
/// </summary>
/// <param name="path">The destination path.</param>
/// <returns>
/// true if a directory is empty <paramref name="path"/>; otherwise false.
/// </returns>
bool DestinationDirectoryEmpty(string path);

/// <summary>
/// Checks whether the specified destination file already exists.
/// </summary>
Expand Down
0