this.configDirectory = configDirectory;
}
public void initialiseGitRepo() throws IOException, GitAPIException {
File confDir = getRootGitDirectory();
FileRepositoryBuilder builder = new FileRepositoryBuilder();
File gitDir = new File(confDir, ".git");
if (!gitDir.exists()) {
String repo = getRemoteRepository();
if (Strings.isNotBlank(repo) && isCloneRemoteRepoOnStartup()) {
boolean cloneAll = isCloneAllBranches();
LOG.info("Cloning git repo " + repo + " into directory " + confDir.getCanonicalPath() + " cloneAllBranches: " + cloneAll);
CloneCommand command = Git.cloneRepository().setCredentialsProvider(getCredentials()).
setCloneAllBranches(cloneAll).setURI(repo).setDirectory(confDir).setRemote(remote);
try {
git = command.call();
return;
} catch (Throwable e) {
LOG.error("Failed to command remote repo " + repo + " due: " + e.getMessage(), e);
// lets just use an empty repo instead
}
} else if (!isCloneRemoteRepoOnStartup()) {
LOG.info("Clone git repo on startup disabled");
}
InitCommand initCommand = Git.init();
initCommand.setDirectory(confDir);
git = initCommand.call();
LOG.info("Initialised an empty git configuration repo at {}", confDir.getCanonicalPath());
String branch = git.getRepository().getBranch();
configureBranch(branch);
importInitialContent(git, confDir, branch);
} else {
Repository repository = builder.setGitDir(gitDir)
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
git = new Git(repository);