.setBranch(this.branchName) .setTransportConfigCallback(buildTransportConfigCallback()) .setCredentialsProvider(getCredentialsProvider()) .call();
.setURI(REMOTE_URL) .setDirectory(localPath) .setCredentialsProvider(allowHosts) .call()) {
.setURI(REMOTE_URL) .setDirectory(localPath) .setCredentialsProvider(allowHosts) .call()) {
CloneCommand getCloneCommandByCloneRepository() { return Git.cloneRepository().setCredentialsProvider(this.provider) .setTransportConfigCallback(this.callback); }
public Git cloneInto(File dir, boolean isBare) throws GitAPIException { Preconditions.checkNotNull(dir); Preconditions.checkArgument(dir.exists(),"dir does not exist: "+dir.getAbsolutePath()); CloneCommand cc = Git.cloneRepository().setURI(url).setBare(isBare) .setDirectory(dir).setCloneAllBranches(true); if ((!Strings.isNullOrEmpty(username)) || (!Strings.isNullOrEmpty(password))) { cc = cc.setCredentialsProvider(new UsernamePasswordCredentialsProvider( Strings.nullToEmpty(username), Strings .nullToEmpty(password))); } Git git = cc.call(); return git; }
public static void cloneRepo(File projectFolder, String cloneUrl, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey, String remote) { // clone the repo! boolean cloneAll = false; LOG.info("Cloning git repo " + cloneUrl + " into directory " + projectFolder.getAbsolutePath()); CloneCommand command = Git.cloneRepository(); GitHelpers.configureCommand(command, credentialsProvider, sshPrivateKey, sshPublicKey); command = command.setCredentialsProvider(credentialsProvider). setCloneAllBranches(cloneAll).setURI(cloneUrl).setDirectory(projectFolder).setRemote(remote); try { command.call(); } catch (Throwable e) { LOG.error("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage(), e); throw new RuntimeException("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage()); } }
/** * In lieu of sparse checkout since it's not yet supported in JGit: * https://bugs.eclipse.org/bugs/show_bug.cgi?id=383772 */ public void cloneNoCheckout(boolean withProgress) throws Exception { CloneCommand clone = Git.cloneRepository().setURI(repositoryUrl).setDirectory(localRepo.getDirectory().getParentFile()).setNoCheckout(true); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=442029 if (credentialsProvider != null) clone.setCredentialsProvider(credentialsProvider); if (withProgress) clone.setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))); clone.call(); }
public void cloneRepo(String branch) throws Exception { CloneCommand cloneCommand = Git.cloneRepository().setURI(repositoryUrl).setDirectory(localRepo.getDirectory().getParentFile()); if (branch != null) cloneCommand.setBranch(branch); if (credentialsProvider != null) cloneCommand.setCredentialsProvider(credentialsProvider); cloneCommand.call(); }
/** * Clones a private remote git repository. Caller is responsible of closing git repository. * * @param remoteUrl * to connect. * @param localPath * where to clone the repo. * @param username * to connect * @param password * to connect * * @return Git instance. Caller is responsible to close the connection. */ public Git cloneRepository(String remoteUrl, Path localPath, String username, String password) { try { return Git.cloneRepository() .setURI(remoteUrl) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)) .setDirectory(localPath.toFile()) .call(); } catch (GitAPIException e) { throw new IllegalStateException(e); } }
public static void cloneRepo(File projectFolder, String cloneUrl, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey, String remote, String tag) { StopWatch watch = new StopWatch(); // clone the repo! boolean cloneAll = true; LOG.info("Cloning git repo " + cloneUrl + " into directory " + projectFolder.getAbsolutePath() + " cloneAllBranches: " + cloneAll); CloneCommand command = Git.cloneRepository(); GitUtils.configureCommand(command, credentialsProvider, sshPrivateKey, sshPublicKey); command = command.setCredentialsProvider(credentialsProvider). setCloneAllBranches(cloneAll).setURI(cloneUrl).setDirectory(projectFolder).setRemote(remote); try { Git git = command.call(); if (tag != null){ git.checkout().setName(tag).call(); } } catch (Throwable e) { LOG.error("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage(), e); throw new RuntimeException("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage()); } finally { LOG.info("cloneRepo took " + watch.taken()); } }
private Git getGitRepositoryRefList(String repositoryUrl, File localFile, String user, String pwd) throws Exception { //System.err.println("repositoryUrl:"+repositoryUrl); //System.err.println("localFile:"+localFile); CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(user, pwd); return Git.cloneRepository() .setURI(repositoryUrl) .setDirectory(localFile) .setCredentialsProvider(credentialsProvider) .call(); }
private Git gitClone() throws GitAPIException { return Git.cloneRepository() .setURI(url) .setCredentialsProvider(credentialsProvider()) .setDirectory(gitDir) .call(); }
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 gitClone() throws GitAPIException { return Git.cloneRepository().setURI(url).setCredentialsProvider(credentialsProvider()).setDirectory(gitDir).call(); }
private Git gitClone(File dir) { Git git = gitOpen(dir); if (git != null) { log.info("already cloned ..."); return git; } CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setURI(repo); cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)); cloneCommand.setDirectory(dir); try { cloneCommand.call(); } catch (GitAPIException e) { log.error(e.getMessage(), e); } return gitOpen(dir); }
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); } }
public synchronized void ensureLocalClone() throws IOException { GitRepository gitRepository = getGitRepository(); try { if (git != null) { return; } File dir = Files.createTempDir(); logger.info("cloning {} into {}", gitRepository.getUrl(), dir); CloneCommand cc = Git.cloneRepository() .setURI(gitRepository.getUrl()).setBare(true) .setDirectory(dir).setCloneAllBranches(true); if ((!Strings.isNullOrEmpty(gitRepository.getUsername())) || (!Strings.isNullOrEmpty(gitRepository.getPassword()))) { cc = cc.setCredentialsProvider(new UsernamePasswordCredentialsProvider( Strings.nullToEmpty(gitRepository.getUsername()), Strings.nullToEmpty(gitRepository.getPassword()))); } git = cc.call(); repo = git.getRepository(); } catch (GitAPIException e) { throw new IOException(e); } }
private Git cloneRepository(final File workingDir) throws GitAPIException { return Git.cloneRepository() .setURI(gitUrl) .setDirectory(workingDir) .setProgressMonitor(PROGRESS_MONITOR) .setCredentialsProvider(user) .setTimeout(cloneTimeoutSeconds) .call(); }
protected Object doInBackground(String... params) { final AuthData authData = AuthData.getInstance(context); final ConnectionType connection = SshSessionFactory.getConnectionType(context); File localPath = new File(context.getFilesDir() + "/" + GIT_DIR); FileUtils.deleteFile(localPath); CloneCommand cloneCommand = Git.cloneRepository(); String url = getUrl(context); if (connection != ConnectionType.kHttp) cloneCommand.setTransportConfigCallback(new CustomTransportConfigCallback(context)); System.setProperty("user.home", context.getFilesDir().getAbsolutePath() ); try { cloneCommand .setURI(url) .setDirectory(localPath) .setCredentialsProvider(new CredentialsProviderAllowHost(authData.getUser(), authData.getPassword())) .setTransportConfigCallback(new CustomTransportConfigCallback(context)) .setBare(false) .call(); } catch (Exception e) { e.printStackTrace(); return e; } return null; }
public static void cloneRepo(String uri, File cloneTo, String branch, GitUser user) { Git result = null; try { result = Git.cloneRepository().setURI(uri).setDirectory(cloneTo) .setBranch(branch).setBare(false).setRemote(REMOTE_NAME) .setNoCheckout(false).setCloneAllBranches(false).setCloneSubmodules(false) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(user.getUsername(), user.getPassword())).call(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (result != null) { result.close(); } } }