Rewrite check for valid bare repo

This commit is contained in:
Paul Campbell 2018-06-02 12:54:57 +01:00
parent 11575f53e7
commit 048f610cf4

View file

@ -4,6 +4,7 @@ import org.assertj.core.api.WithAssertions;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.InitCommand; import org.eclipse.jgit.api.InitCommand;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
@ -37,19 +38,9 @@ class GitDBTest implements WithAssertions {
} }
private void assertThatIsBareRepo(final Path dbDir) throws IOException { private void assertThatIsBareRepo(final Path dbDir) throws IOException {
final DirectoryStream<Path> paths = Files.newDirectoryStream(dbDir); final Git git = Git.open(dbDir.toFile());
assertThat(paths.iterator()) assertThat(git.getRepository().findRef(Constants.HEAD)).isNotNull();
.contains( assertThat(git.getRepository().isBare()).isTrue();
dbDir.resolve("branches"),
dbDir.resolve("HEAD"),
dbDir.resolve("config"),
dbDir.resolve("refs"),
dbDir.resolve("logs"),
dbDir.resolve("hooks"),
dbDir.resolve("objects")
);
final List<String> config = Files.readAllLines(dbDir.resolve("config"));
assertThat(config).contains("\tbare = true");
} }
private Path dirDoesNotExist() throws IOException { private Path dirDoesNotExist() throws IOException {