diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/service/GitService.java b/karavan-app/src/main/java/org/apache/camel/karavan/service/GitService.java index 4a92db1480a..b191fab1d43 100644 --- a/karavan-app/src/main/java/org/apache/camel/karavan/service/GitService.java +++ b/karavan-app/src/main/java/org/apache/camel/karavan/service/GitService.java @@ -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()); @@ -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); @@ -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()));