Skip to content
Snippets Groups Projects
Commit 7bcddd72 authored by Georg Seibt's avatar Georg Seibt :nerd:
Browse files

differentiate between failure modes in the logging done in importRepository(),...

differentiate between failure modes in the logging done in importRepository(), try and use the canonical file path for the URL as a fallback
parent 764ee71d
No related branches found
No related tags found
No related merge requests found
......@@ -6,11 +6,13 @@ import de.uni_passau.fim.seibt.gitwrapper.process.ToolNotWorkingException;
import de.uni_passau.fim.seibt.gitwrapper.process.ToolWrapper;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Scanner;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -135,24 +137,39 @@ public class GitWrapper extends ToolWrapper {
*/
public Optional<Repository> importRepository(File directory) {
if (!isGitDir(directory)) {
LOG.warning(() -> directory + " does not contain a git repository.");
return Optional.empty();
}
// TODO add fallback method for determining URL
Optional<ExecRes> result = exec(directory, "config", "--get", "remote.origin.url");
Optional<String> url = result.map(res -> {
Optional<ExecRes> originURL = exec(directory, "config", "--get", "remote.origin.url");
Function<ExecRes, Repository> toRepository = res -> {
String repoUrl = null;
if (failed(res) || (repoUrl = res.getStdOutTrimmed()).isEmpty()) {
// there was no remote url
LOG.fine(String.format("Repository %s does not hab an origin url, using the local path", directory));
repoUrl = directory.getAbsolutePath();
if (failed(res)) {
LOG.warning(() -> String.format("Failed to get the origin url for the repository in %s. Using the " +
"canonical directory path.", directory));
} else if (res.getStdOutTrimmed().isEmpty()) {
LOG.warning(() -> String.format("Repository in %s does not have an origin url. Using the canonical " +
"directory path.", directory));
} else {
repoUrl = res.getStdOutTrimmed();
}
if (repoUrl == null) {
try {
repoUrl = directory.getCanonicalPath();
} catch (IOException e) {
LOG.log(Level.WARNING, e, () -> "Exception computing the canonical path for " + directory +
". Using the absolute path instead.");
repoUrl = directory.getAbsolutePath();
}
}
return repoUrl;
});
return Optional.of(new Repository(this, url.orElse(""), directory));
return new Repository(this, repoUrl, directory);
};
return originURL.map(toRepository);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment