Skip to content

Commit

Permalink
Fix the usage of karavan.git.branch on git clone (Closes issue #1347) (
Browse files Browse the repository at this point in the history
…#1393)

* docs(app): Adds more details on log message on git init

when something is wrong with initial git clone

* fix(app): #1347 Fix the usage of karavan.git.branch on git clone

Closes: #1347
  • Loading branch information
thgruiz authored Sep 4, 2024
1 parent ce35a3b commit d319dfa
Showing 1 changed file with 5 additions and 4 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 All @@ -202,7 +202,7 @@ public Git getGit(boolean checkout, String folder) throws GitAPIException, IOExc
checkout(git, false, null, null, gitConfig.getBranch());
}
} catch (RefNotFoundException | InvalidRemoteException | TransportException e) {
LOGGER.error("New repository");
LOGGER.error("New repository", e);
git = init(folder, gitConfig.getUri(), gitConfig.getBranch());
} catch (Exception e) {
LOGGER.error("Error", e);
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 d319dfa

Please sign in to comment.