Skip to content
Permalink
Browse files

43: Repository.get should return Optional.empty on non-existing direc…

…tory

Reviewed-by: rwestberg
  • Loading branch information
Erik Helin
Erik Helin committed Jul 4, 2019
1 parent e83e473 commit 90edbabb55e9bbbe7129fac23396f1c8e5d2e499
@@ -701,6 +701,10 @@ public Hash head() throws IOException {
}

public static Optional<Repository> get(Path p) throws IOException {
if (!Files.exists(p)) {
return Optional.empty();
}

var r = new GitRepository(p);
return r.exists() ? Optional.of(new GitRepository(r.root())) : Optional.empty();
}
@@ -395,6 +395,10 @@ public boolean isClean() throws IOException {

@Override
public boolean exists() throws IOException {
if (!Files.exists(dir)) {
return false;
}

try {
root();
return true;
@@ -657,6 +661,10 @@ public Hash head() throws IOException {
}

public static Optional<Repository> get(Path p) throws IOException {
if (!Files.exists(p)) {
return Optional.empty();
}

var r = new HgRepository(p);
return r.exists() ? Optional.of(new HgRepository(r.root())) : Optional.empty();
}
@@ -24,6 +24,7 @@

import org.openjdk.skara.test.TemporaryDirectory;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;

@@ -1430,4 +1431,11 @@ void testShowOnExecutableFiles(VCS vcs) throws IOException {
assertEquals(Optional.of(List.of("echo 'goodbye'")), r.lines(readWriteExecutableFile, hash2));
}
}

@Test
void testGetAndExistsOnNonExistingDirectory() throws IOException {
var nonExistingDirectory = Path.of("this", "does", "not", "exist");
assertEquals(Optional.empty(), Repository.get(nonExistingDirectory));
assertEquals(false, Repository.exists(nonExistingDirectory));
}
}

0 comments on commit 90edbab

Please sign in to comment.
You can’t perform that action at this time.