log.info("Initializing git context.");
int tenantId = Integer.parseInt(repositoryInformation.getTenantId());
String gitLocalRepoPath = repositoryInformation.getRepoPath();
RepositoryContext gitRepoCtx = new RepositoryContext();
String gitRemoteRepoUrl = repositoryInformation.getRepoUrl();
boolean isMultitenant = repositoryInformation.isMultitenant();
log.info("local path " + gitLocalRepoPath);
log.info("remote url " + gitRemoteRepoUrl);
log.info("tenant " + tenantId);
gitRepoCtx.setTenantId(tenantId);
gitRepoCtx.setGitLocalRepoPath(getRepoPathForTenantId(tenantId,gitLocalRepoPath,isMultitenant));
gitRepoCtx.setGitRemoteRepoUrl(gitRemoteRepoUrl);
gitRepoCtx.setRepoUsername(repositoryInformation.getRepoUsername());
gitRepoCtx.setRepoPassword(repositoryInformation.getRepoPassword());
try {
if(isKeyBasedAuthentication(gitRemoteRepoUrl, tenantId)) {
gitRepoCtx.setKeyBasedAuthentication(true);
initSSHAuthentication();
}
else
gitRepoCtx.setKeyBasedAuthentication(false);
} catch (Exception e1) {
log.error("Exception occurred.. " + e1.getMessage(), e1);
}
FileRepository localRepo = null;
try {
// localRepo = new FileRepository(new File(gitLocalRepoPath + "/.git"));
// Fixing STRATOS-380
localRepo = new FileRepository(new File(gitRepoCtx.getGitLocalRepoPath() + "/.git"));
} catch (IOException e) {
e.printStackTrace();
}
gitRepoCtx.setLocalRepo(localRepo);
gitRepoCtx.setGit(new Git(localRepo));
gitRepoCtx.setCloneExists(false);
cacheGitRepoContext(tenantId, gitRepoCtx);
}