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

Commit a45847e

Browse files
grokysJasmine
authored andcommitted
Just test for existing directory.
Rather than .git/HEAD.
1 parent 6f7adfb commit a45847e

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

src/GitHub.App/ViewModels/RepositoryCloneViewModel.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ IObservable<Unit> OnCloneRepository(object state)
153153
});
154154
}
155155

156-
bool IsAlreadyRepoAtPath(string baseRepositoryPath)
156+
bool IsAlreadyRepoAtPath(string path)
157157
{
158158
bool isAlreadyRepoAtPath = false;
159159

@@ -162,26 +162,14 @@ bool IsAlreadyRepoAtPath(string baseRepositoryPath)
162162
var validationResult = BaseRepositoryPathValidator.ValidationResult;
163163
if (validationResult != null && validationResult.IsValid)
164164
{
165-
string potentialPath = Path.Combine(baseRepositoryPath, SelectedRepository.Name);
166-
isAlreadyRepoAtPath = IsGitRepo(potentialPath);
165+
string potentialPath = Path.Combine(path, SelectedRepository.Name);
166+
isAlreadyRepoAtPath = operatingSystem.Directory.Exists(potentialPath);
167167
}
168168
}
169169

170170
return isAlreadyRepoAtPath;
171171
}
172172

173-
bool IsGitRepo(string path)
174-
{
175-
try
176-
{
177-
return operatingSystem.File.Exists(Path.Combine(path, ".git", "HEAD"));
178-
}
179-
catch (PathTooLongException)
180-
{
181-
return false;
182-
}
183-
}
184-
185173
/// <summary>
186174
/// Path to clone repositories into
187175
/// </summary>

src/UnitTests/GitHub.App/ViewModels/RepositoryCloneViewModelTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ public void IsInvalidWhenDestinationRepositoryExists()
208208
repositoryHost.ModelService.GetRepositories().Returns(Observable.Return(new[] { repo }));
209209
var cloneService = Substitute.For<IRepositoryCloneService>();
210210
var os = Substitute.For<IOperatingSystem>();
211-
var files = Substitute.For<IFileFacade>();
212-
os.File.Returns(files);
213-
files.Exists(@"c:\foo\bar\.git\HEAD").Returns(true);
211+
var directories = Substitute.For<IDirectoryFacade>();
212+
os.Directory.Returns(directories);
213+
directories.Exists(@"c:\foo\bar").Returns(true);
214214
var vm = new RepositoryCloneViewModel(
215215
repositoryHost,
216216
cloneService,

0 commit comments

Comments
 (0)