in FlywayLambdaService/src/main/java/com/geekoosh/lambda/git/GitService.java [48:80]
public void cloneRepo() throws MigrationFilesException {
if(gitDirectory.exists()) {
try {
FileUtils.deleteDirectory(gitDirectory);
} catch (IOException e) {
throw new MigrationFilesException("Failed deleting existing git directory", e);
}
}
if(!gitDirectory.mkdir()) {
throw new MigrationFilesException("Git directory creation failed");
}
logger.info("Fetching from " + gitRequest.getGitRepository());
logger.info("Fetching from branch " + branchRef());
CloneCommand cloneCmd = Git.cloneRepository();
if(gitRequest.getUsername() != null && gitRequest.getPassword() != null) {
cloneCmd = cloneCmd.setCredentialsProvider(new UsernamePasswordCredentialsProvider(
gitRequest.getUsername(), gitRequest.getPassword()
));
}
cloneCmd
.setURI(gitRequest.getGitRepository())
.setBranchesToClone(Collections.singletonList(branchRef()))
.setBranch(branchRef())
.setDirectory(gitDirectory)
.setRemote("origin");
try {
repo = cloneCmd.call();
} catch (GitAPIException e) {
throw new MigrationFilesException("Failed cloning repo", e);
}
checkout();
}