List of usage examples for org.eclipse.jgit.api Git cloneRepository
public static CloneCommand cloneRepository()
From source file:com.creactiviti.piper.core.git.JGitTemplate.java
License:Apache License
private synchronized Repository getRepository(String aUrl, String aBranch) { try {/*from w ww . j av a2s . co m*/ clear(); logger.info("Cloning {} {}", aUrl, aBranch); Git git = Git.cloneRepository().setURI(aUrl).setBranch(aBranch).setDirectory(repositoryDir).call(); return (git.getRepository()); } catch (Exception e) { throw Throwables.propagate(e); } }
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. *///from w ww. j av a2 s .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.dc.runbook.dt.support.BasicGitClient.java
License:Apache License
public static void clone(String from, String to) { try {/* w ww .j a v a 2 s. c o m*/ Git.cloneRepository().setURI(from).setDirectory(new File(to)).call().close(); } catch (GitAPIException e) { throw new GitClientException("Error occurred while cloning from : " + from + " to : " + to, e); } }
From source file:com.dc.runbook.dt.support.BasicGitClient.java
License:Apache License
public static void forceClone(String from, String to) { try {//from w ww .jav a 2 s .co m File file = new File(to); if (file.exists()) { boolean deleted = deleteFiles(file); if (!deleted) { throw new GitClientException("Unable to delete folder : " + file.getAbsolutePath()); } } Git.cloneRepository().setURI(from).setDirectory(new File(to)).call().close(); } catch (GitAPIException e) { throw new GitClientException("Error occurred while cloning from : " + from + " to : " + to, e); } }
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 w w.j a v a 2 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.docmd.behavior.GitManager.java
public boolean gitClone(String path, String remoteURL, JTextArea console) throws IOException, GitAPIException, URISyntaxException { //validate remoteURL URIish repositoryAdress = new URIish(remoteURL); if (!isValidRemoteRepository(repositoryAdress)) return false; //prepare a new folder for the cloned repository File localPath = new File(""); String repositoryName = ""; StringTokenizer st = new StringTokenizer(remoteURL, "/"); while (st.hasMoreTokens()) { repositoryName = st.nextToken(); }//from w ww . j av a 2 s . c om repositoryName = repositoryName.substring(0, repositoryName.length() - 4); if (SYSTEM.contains("Windows")) localPath = new File(path + "\\" + repositoryName); else localPath = new File(path + "/" + repositoryName); //if the directory does not exist, create it if (!localPath.exists()) { console.setText(""); console.append("creating directory: " + localPath.getName()); boolean result = false; try { localPath.mkdir(); result = true; } catch (SecurityException se) { se.printStackTrace(); } if (result) { console.append("\nDIR created"); } } // then clone console.append("\n$git clone " + remoteURL); console.append("\nCloning from " + remoteURL + " to " + localPath); try (Git result = Git.cloneRepository().setURI(remoteURL).setDirectory(localPath) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(this.username, this.password)) .call()) { console.append("\nHaving repository: " + result.getRepository().getDirectory() + " on branch master"); this.repository = result.getRepository(); this.git = result; } return true; }
From source file:com.ericsson.eiffel.remrem.semantics.clone.PrepareLocalEiffelSchemas.java
License:Apache License
/** * This method is used to clone repository from github using the URL and branch to local destination folder. * //from w ww . jav a 2 s . c o m * @param repoURL * repository url to clone. * @param branch * specific branch name of the repository to clone * @param localEiffelRepoPath * destination path to clone the repo. */ private void cloneEiffelRepo(final String repoURL, final String branch, final File localEiffelRepoPath) { Git localGitRepo = null; // checking for repository exists or not in the localEiffelRepoPath try { if (!localEiffelRepoPath.exists()) { // cloning github repository by using URL and branch name into local localGitRepo = Git.cloneRepository().setURI(repoURL).setBranch("master") .setDirectory(localEiffelRepoPath).call(); } else { // If required repository already exists localGitRepo = Git.open(localEiffelRepoPath); // Reset to normal if uncommitted changes are present localGitRepo.reset().call(); //Checkout to master before pull the changes localGitRepo.checkout().setName(EiffelConstants.MASTER).call(); // To get the latest changes from remote repository. localGitRepo.pull().call(); } //checkout to input branch after changes pulled into local localGitRepo.checkout().setName(branch).call(); } catch (Exception e) { LOGGER.info( "please check proxy settings if proxy enabled update proxy.properties file to clone behind proxy"); e.printStackTrace(); } }
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();/*from 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); } }
From source file:com.fanniemae.ezpie.common.GitOperations.java
License:Open Source License
public String cloneSSH(String repo_url, String destination, String privateKey, String password, String branch) { if (_useProxy) { throw new PieException( "Network proxies do not support SSH, please use an http url to clone this repository."); }/* w w w. j a va2 s .c om*/ final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() { @Override protected void configure(Host host, Session session) { // This still checks existing host keys and will disable "unsafe" // authentication mechanisms if the host key doesn't match. session.setConfig("StrictHostKeyChecking", "no"); } @Override protected JSch createDefaultJSch(FS fs) throws JSchException { JSch defaultJSch = super.createDefaultJSch(fs); defaultJSch.addIdentity(privateKey, password); return defaultJSch; } }; CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setURI(repo_url); File dir = new File(destination); cloneCommand.setDirectory(dir); if (StringUtilities.isNotNullOrEmpty(branch)) cloneCommand.setBranch(branch); cloneCommand.setTransportConfigCallback(new TransportConfigCallback() { public void configure(Transport transport) { SshTransport sshTransport = (SshTransport) transport; sshTransport.setSshSessionFactory(sshSessionFactory); } }); try (Writer writer = new StringWriter()) { TextProgressMonitor tpm = new TextProgressMonitor(writer); cloneCommand.setProgressMonitor(tpm); try (Git result = cloneCommand.call()) { } writer.flush(); return writer.toString(); } catch (IOException | GitAPIException e) { throw new PieException("Error while trying to clone the git repository. " + e.getMessage(), e); } }
From source file:com.gitblit.servlet.GitServletTest.java
License:Apache License
@Test public void testClone() throws Exception { GitBlitSuite.close(ticgitFolder);// w w w . ja va2 s . co m if (ticgitFolder.exists()) { FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY); } CloneCommand clone = Git.cloneRepository(); clone.setURI(MessageFormat.format("{0}/ticgit.git", url)); clone.setDirectory(ticgitFolder); clone.setBare(false); clone.setCloneAllBranches(true); clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)); GitBlitSuite.close(clone.call()); assertTrue(true); }