CloneCommand cloneCommand = Git.cloneRepository() .setURI(uri.toASCIIString()) .setBranchesToClone(singleton("refs/heads/" + branch)) .setBranch("refs/heads/" + branch) .setDirectory(directory.toFile());
/** * Function to clone the repository * * @throws IOException if something goes wrong, this exception is thrown */ public void cloneRepository() throws IOException { try { Git.cloneRepository() .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))) .setURI(url) .setDirectory(directory) .setBranchesToClone(singleton(branch)) .setBranch(branch) .call(); } catch (GitAPIException ex) { //Because the GitAPIException is abstract and cannot be instantiated, another (similar) exception is used throw new IOException("[+]There was an error cloing " + name + ". Verify your internet connection and the permissions of the folder!"); } }
cloneCommand.setBranchesToClone(Arrays.asList(fullRefName)); cloneCommand.setBranch(fullRefName);
cloneCommand.setBranchesToClone(Arrays.asList("refs/heads/" + branch));
cloneCommand.setBranchesToClone(Arrays.asList(fullRefName)); cloneCommand.setBranch(fullRefName);
private Git cloneRepository(final File workingDir) throws GitAPIException { final CloneCommand cloneCommand = Git.cloneRepository() .setURI(gitUrl) .setDirectory(workingDir) .setProgressMonitor(PROGRESS_MONITOR) .setCredentialsProvider(user) .setTimeout(cloneTimeoutSeconds); if (StringUtils.isNotEmpty(branchName)) { final String refBranchName = "refs/heads/" + branchName; cloneCommand.setBranchesToClone(ImmutableSet.of(refBranchName)) .setBranch(refBranchName); // prevent clone command from looking at the HEAD of the master branch } return cloneCommand.call(); }
private Git initGitRepo() { try { log.info("try to init repo {}", gitSettings.getUrl()); File gitDir = gitDirPath.toFile(); FileUtils.deleteQuietly(gitDir); gitDir.mkdirs(); Git git = Git.cloneRepository() .setURI(gitSettings.getUrl()) .setCredentialsProvider(cp) .setDirectory(gitDir) .setBranchesToClone(singleton(HEAD + gitSettings.getBranch())) .setBranch(HEAD + gitSettings.getBranch()) .call(); log.info("repo was cloned from url: {} to dir: {}, branch: {} ", gitSettings.getUrl(), gitDir, git.getRepository().getBranch()); return git; } catch (Exception e) { throw Throwables.asRuntime(e); } }
.setURI(remotePath) .setDirectory(localFile) .setBranchesToClone(branchList) .setCredentialsProvider(credentialsProvider) .call();
.setDirectory(local) .setBranch(branch) .setBranchesToClone(Collections.singletonList(Constants.R_HEADS + branch));