}
private Repository callInternal() {
final Platform platform = platform();
final File workingDirectory = platform.pwd();
final Optional<URL> repoUrl = new ResolveGeogigDir(platform).call();
final boolean repoExisted = repoUrl.isPresent();
final File envHome;
if (repoExisted) {
// we're at either the repo working dir or a subdirectory of it
try {
envHome = new File(repoUrl.get().toURI());
} catch (URISyntaxException e) {
throw Throwables.propagate(e);
}
} else {
envHome = new File(workingDirectory, ".geogig");
if (!envHome.mkdirs()) {
throw new RuntimeException("Unable to create geogig environment at '"
+ envHome.getAbsolutePath() + "'");
}
}
Map<String, String> effectiveConfigBuilder = Maps.newTreeMap();
addDefaults(defaults, effectiveConfigBuilder);
if (config != null) {
effectiveConfigBuilder.putAll(config);
}
if (filterFile != null) {
try {
final String FILTER_FILE = "filter.ini";
File oldFilterFile = new File(filterFile);
if (!oldFilterFile.exists()) {
throw new FileNotFoundException("No filter file found at " + filterFile + ".");
}
Optional<URL> envHomeURL = new ResolveGeogigDir(platform).call();
Preconditions.checkState(envHomeURL.isPresent(), "Not inside a geogig directory");
final URL url = envHomeURL.get();
if (!"file".equals(url.getProtocol())) {
throw new UnsupportedOperationException(
"Sparse clone works only against file system repositories. "
+ "Repository location: " + url.toExternalForm());
}
File repoDir;
try {
repoDir = new File(url.toURI());
} catch (URISyntaxException e) {
throw new IllegalStateException("Unable to access directory "
+ url.toExternalForm(), e);
}
File newFilterFile = new File(repoDir, FILTER_FILE);
Files.copy(oldFilterFile, newFilterFile);
effectiveConfigBuilder.put("sparse.filter", FILTER_FILE);
} catch (Exception e) {
throw new IllegalStateException("Unable to copy filter file at path " + filterFile
+ " to the new repository.", e);
}
}
try {
Preconditions.checkState(envHome.toURI().toURL()
.equals(new ResolveGeogigDir(platform).call().get()));
} catch (MalformedURLException e) {
Throwables.propagate(e);
}
Repository repository;