List of usage examples for org.eclipse.jgit.api CloneCommand call
@Override public Git call() throws GitAPIException, InvalidRemoteException, org.eclipse.jgit.api.errors.TransportException
Executes the Clone command.
From source file:am.ik.categolj3.api.git.GitStore.java
License:Apache License
Git getGitDirectory() { try {//from w w w. j a v a2 s . co m if (gitProperties.getBaseDir().exists()) { if (gitProperties.isInit()) { FileSystemUtils.deleteRecursively(gitProperties.getBaseDir()); } else { return Git.open(gitProperties.getBaseDir()); } } CloneCommand clone = Git.cloneRepository().setURI(gitProperties.getUri()) .setDirectory(gitProperties.getBaseDir()); gitProperties.credentialsProvider().ifPresent(clone::setCredentialsProvider); return clone.call(); } catch (IOException e) { throw new UncheckedIOException(e); } catch (GitAPIException e) { throw new IllegalStateException(e); } }
From source file:bluej.groupwork.git.GitCloneCommand.java
License:Open Source License
@Override public TeamworkCommandResult getResult() { try {//from ww w .j a va 2 s. c o m String reposUrl = getRepository().getReposUrl(); CloneCommand cloneCommand = Git.cloneRepository(); disableFingerprintCheck(cloneCommand); cloneCommand.setDirectory(clonePath); cloneCommand.setURI(reposUrl); StoredConfig repoConfig = cloneCommand.call().getRepository().getConfig(); //save the repo repoConfig.setString("user", null, "name", getRepository().getYourName()); //register the user name repoConfig.setString("user", null, "email", getRepository().getYourEmail()); //register the user email repoConfig.save(); if (!isCancelled()) { return new TeamworkCommandResult(); } return new TeamworkCommandAborted(); } catch (GitAPIException | IOException ex) { return new TeamworkCommandError(ex.getMessage(), ex.getLocalizedMessage()); } }
From source file:com.bb.extensions.plugin.unittests.internal.git.GitWrapper.java
License:Open Source License
/** * Clones the git repository located at the given url to the given path. * /*from w w w .ja v a 2 s .c om*/ * @param path * * @param url * @return The GitWrapper to interact with the clone git repository. * @throws IllegalArgumentException */ public static GitWrapper cloneRepository(String path, String url) throws IllegalArgumentException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); File gitDir = new File(path); if (gitDir.exists() == false) { gitDir.mkdir(); } else if (gitDir.list().length > 0) { if (isGitRepository(gitDir)) { return openRepository(path); } else { throw new IllegalArgumentException("Cannot clone to a non-empty directory"); } } Repository repository; try { repository = builder.setGitDir(gitDir).readEnvironment().findGitDir().build(); GitWrapper gitWrapper = new GitWrapper(); gitWrapper.git = new Git(repository); CloneCommand clone = Git.cloneRepository(); clone.setBare(false); clone.setCloneAllBranches(true); clone.setDirectory(gitDir).setURI(url); // we have to close the newly returned Git object as call() creates // a new one every time clone.call().getRepository().close(); return gitWrapper; } catch (IOException e) { e.printStackTrace(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } return null; }
From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java
License:Apache License
public void cloneRepo(String branch) throws Exception { CloneCommand cloneCommand = Git.cloneRepository().setURI(repositoryUrl) .setDirectory(localRepo.getDirectory().getParentFile()); if (branch != null) cloneCommand.setBranch(branch);/*from w ww . ja va 2s . c om*/ if (credentialsProvider != null) cloneCommand.setCredentialsProvider(credentialsProvider); cloneCommand.call(); }
From source file:com.centurylink.mdw.dataaccess.file.VersionControlGit.java
License:Apache License
/** * In lieu of sparse checkout since it's not yet supported in JGit: * https://bugs.eclipse.org/bugs/show_bug.cgi?id=383772 *///from www . ja va2s. c o m 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(); }
From source file:com.crygier.git.rest.resources.RepositoryResource.java
License:Apache License
/** * Method handling HTTP GET requests. The returned object will be sent * to the client as "text/plain" media type. * * @return String that will be returned as a text/plain response. */// w w w . j av a 2s .c o m @GET @Path("/{repositoryName}/clone") @JSONP(queryParam = "callback") @Produces({ "application/javascript" }) public Map<String, Object> cloneRepository(@PathParam("repositoryName") String repositoryName, @QueryParam("url") String url, @QueryParam("directory") File directory) { Map<String, Object> answer = new HashMap<String, Object>(); try { URIish uri = new URIish(url); CloneCommand cloneCommand = Git.cloneRepository().setURI(url) .setDirectory(new File(directory, repositoryName.replaceAll(".git", ""))).setBare(false) .setProgressMonitor(new TextProgressMonitor()); Git git = cloneCommand.call(); answer.put("status", "ok"); git.getRepository().close(); answer.putAll(registerLocalRepository(repositoryName, directory)); } catch (GitAPIException e) { logger.log(Level.SEVERE, "Error Cloning", e); answer.put("errorMessage", e.getMessage()); } catch (URISyntaxException e) { logger.log(Level.SEVERE, "Invalid URL", e); answer.put("errorMessage", e.getMessage()); } return answer; }
From source file:com.denimgroup.threadfix.service.repository.GitServiceImpl.java
License:Mozilla Public License
private Git clone(Application application, File dirLocation) { Git git = null;/*from w ww.j a v a2 s. com*/ try { CloneCommand clone = Git.cloneRepository(); clone.setURI(application.getRepositoryUrl()).setDirectory(dirLocation) .setCredentialsProvider(getApplicationCredentials(application)); if (application.getRepositoryBranch() != null && !application.getRepositoryBranch().isEmpty()) { clone.setBranch(application.getRepositoryBranch()); } // clone git repo git = clone.call(); // checkout specific revision if (application.getRepositoryRevision() != null && !application.getRepositoryRevision().isEmpty()) { git.checkout().setCreateBranch(true).setStartPoint(application.getRepositoryRevision()) .setName(application.getRepositoryRevision()).call(); } } catch (WrongRepositoryStateException e) { log.error(EXCEPTION_MESSAGE, e); } catch (InvalidConfigurationException e) { log.error(EXCEPTION_MESSAGE, e); } catch (DetachedHeadException e) { log.error(EXCEPTION_MESSAGE, e); } catch (InvalidRemoteException e) { log.error(EXCEPTION_MESSAGE, e); } catch (CanceledException e) { log.error(EXCEPTION_MESSAGE, e); } catch (RefNotFoundException e) { log.error(EXCEPTION_MESSAGE, e); } catch (NoHeadException e) { log.error(EXCEPTION_MESSAGE, e); } catch (RefAlreadyExistsException e) { log.error(EXCEPTION_MESSAGE, e); } catch (CheckoutConflictException e) { log.error(EXCEPTION_MESSAGE, e); } catch (InvalidRefNameException e) { log.error(EXCEPTION_MESSAGE, e); } catch (TransportException e) { log.error(EXCEPTION_MESSAGE, e); } catch (GitAPIException e) { log.error(EXCEPTION_MESSAGE, e); } return git; }
From source file:com.ejwa.gitdepmavenplugin.DownloaderMojo.java
License:Open Source License
private Git clone(Pom pom, GitDependency dependency) throws MojoExecutionException { final CloneCommand c = new CloneCommand(); final String location = dependency.getLocation(); c.setURI(location);/*from w ww . j ava2 s . co m*/ c.setCloneAllBranches(true); c.setProgressMonitor(new TextProgressMonitor()); final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency); final String version = dependencyHandler.getDependencyVersion(pom); final String tempDirectory = Directory.getTempDirectoryString(location, version); c.setDirectory(new File(tempDirectory)); return c.call(); }
From source file:com.ejwa.mavengitdepplugin.DownloaderMojo.java
License:Open Source License
private Git clone(POM pom, GitDependency dependency) { final CloneCommand c = new CloneCommand(); c.setURI(dependency.getLocation());//from w ww . j a v a 2s . c o m c.setCloneAllBranches(true); c.setProgressMonitor(new TextProgressMonitor()); final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency); final String version = dependencyHandler.getDependencyVersion(pom); final String tempDirectory = Directory.getTempDirectoryString(dependency.getLocation(), version); c.setDirectory(new File(tempDirectory)); return c.call(); }
From source file:com.fanniemae.ezpie.common.GitOperations.java
License:Open Source License
public String cloneHTTP(String repo_url, String destination, String userID, String password, String branch) throws InvalidRemoteException, TransportException, GitAPIException, URISyntaxException { _repositoryHost = getHost(repo_url); setupProxy();/*w w w.j a v a 2 s . c o m*/ File localDir = new File(destination); CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setURI(repo_url); cloneCommand.setDirectory(localDir); if (StringUtilities.isNotNullOrEmpty(branch)) cloneCommand.setBranch(branch); if (StringUtilities.isNotNullOrEmpty(userID)) cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userID, password)); try (Writer writer = new StringWriter()) { TextProgressMonitor tpm = new TextProgressMonitor(writer); cloneCommand.setProgressMonitor(tpm); try (Git result = cloneCommand.call()) { } clearProxyAuthenticatorCache(); writer.flush(); return writer.toString(); } catch (IOException e) { throw new PieException("Error while trying to clone the git repository. " + e.getMessage(), e); } }