Skip to content

Commit

Permalink
fix(app): apache#1347 Fix the usage of karavan.git.branch on git clone
Browse files Browse the repository at this point in the history
Closes: apache#1347
  • Loading branch information
thgruiz committed Sep 2, 2024
1 parent e5cb7b7 commit 6ce81dc
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public Git getGit(boolean checkout, String folder) throws GitAPIException, IOExc
git = init(folder, gitConfig.getUri(), gitConfig.getBranch());
} else {
try {
git = clone(folder, gitConfig.getUri());
git = clone(folder, gitConfig.getUri(), gitConfig.getBranch());
var branch = git.branchList().call().stream().filter(ref -> ref.getName().equals("refs/heads/" + gitConfig.getBranch())).findFirst();
if (branch.isEmpty()) {
createBranch(git, gitConfig.getBranch());
Expand Down Expand Up @@ -332,11 +332,12 @@ public void deleteProject(String projectId, String authorName, String authorEmai
}
}

private Git clone(String dir, String uri) throws GitAPIException, URISyntaxException {
private Git clone(String dir, String uri, String branch) throws GitAPIException, URISyntaxException {
CloneCommand command = Git.cloneRepository();
command.setCloneAllBranches(false);
command.setDirectory(Paths.get(dir).toFile());
command.setURI(uri);
command.setBranch(branch);
setCredentials(command);
Git git = command.call();
addRemote(git, uri);
Expand Down Expand Up @@ -430,7 +431,7 @@ public boolean checkGit() throws Exception {
GitConfig gitConfig = getGitConfig();
String uuid = UUID.randomUUID().toString();
String folder = vertx.fileSystem().createTempDirectoryBlocking(uuid);
try (Git git = clone(folder, gitConfig.getUri())) {
try (Git git = clone(folder, gitConfig.getUri(), gitConfig.getBranch())) {
LOGGER.info("Git is ready");
} catch (Exception e) {
LOGGER.info("Error connecting git: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
Expand Down

0 comments on commit 6ce81dc

Please sign in to comment.