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

Commit 7c998ec

Browse files
committed
Enable clone and disable open button on empty dir.
- Currently clone button is disabled and open button is enabled on empty directories. - Desired behavior should support cloning to empty directories. - Non-empty directory message is not shown when the directory is empty.
1 parent 1cf7713 commit 7c998ec

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/GitHub.App/Services/RepositoryCloneService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ public async Task CloneRepository(
232232
/// <inheritdoc/>
233233
public bool DestinationDirectoryExists(string path) => operatingSystem.Directory.DirectoryExists(path);
234234

235+
/// <inheritdoc/>
236+
public bool DestinationDirectoryEmpty(string path) => !DestinationDirectoryExists(path) || operatingSystem.Directory.GetDirectory(path).IsEmpty;
237+
235238
/// <inheritdoc/>
236239
public bool DestinationFileExists(string path) => operatingSystem.File.Exists(path);
237240

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

Lines changed: 9 additions & 2 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(
@@ -240,6 +242,11 @@ string ValidatePathWarning(RepositoryModel repositoryModel, string path)
240242
{
241243
using (var repository = gitService.GetRepository(path))
242244
{
245+
if (service.DestinationDirectoryEmpty(path))
246+
{
247+
return null;
248+
}
249+
243250
if (repository == null)
244251
{
245252
return Resources.CantFindARepositoryAtLocalPath;

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>

0 commit comments

Comments
 (0)