List of usage examples for org.eclipse.jgit.api Git cloneRepository
public static CloneCommand cloneRepository()
From source file:com.kolich.blog.components.GitRepository.java
License:Open Source License
@Injectable public GitRepository(@Required final ServletContext context, @Required final BlogEventBus eventBus) throws Exception { eventBus_ = eventBus;/*from w w w .ja va 2 s.c om*/ executor_ = newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setDaemon(true).setNameFormat("blog-git-puller").build()); final File repoDir = getRepoDir(context); logger__.info("Activated repository path: {}", repoDir.getCanonicalFile()); // If were not in dev mode, and the clone path doesn't exist or we need to force clone from // scratch, do that now. final boolean clone = (!repoDir.exists() || shouldCloneOnStartup__); if (!isDevMode__ && clone) { logger__.info("Clone path does not exist, or we were asked to re-clone. Cloning from: {}", blogRepoCloneUrl__); // Recursively delete the existing clone of the repo, if it exists, and clone the repository. FileUtils.deleteDirectory(repoDir); Git.cloneRepository().setURI(blogRepoCloneUrl__).setDirectory(repoDir).setBranch("master").call(); } // Construct a new pointer to the repository on disk. repo_ = new FileRepositoryBuilder().setWorkTree(repoDir).readEnvironment().build(); git_ = new Git(repo_); logger__.info("Successfully initialized repository at: {}", repo_); }
From source file:com.maiereni.sling.sources.git.GitProjectDownloader.java
License:Apache License
private Git cloneRepository(final File directory, final String url, final String branchName) throws Exception { CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setURI(url);/*ww w. ja v a 2 s . c o m*/ /* if (StringUtils.isNoneBlank(user, password)) { cloneCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider(user, password)); }*/ cloneCommand.setDirectory(directory); cloneCommand.setBranch(branchName); logger.debug("Clone the repository"); return cloneCommand.call(); }
From source file:com.maiereni.synchronizer.git.utils.GitDownloaderImpl.java
License:Apache License
private Git createRepository(final File fRepo, final GitProperties properties) throws Exception { if (StringUtils.isEmpty(properties.getRemote())) { throw new Exception("The remote URL of Git cannot be null"); }//from w w w . j av a 2 s. c o m logger.debug("Create repository at " + fRepo.getPath()); CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setURI(properties.getRemote()); if (StringUtils.isNotBlank(properties.getUserName()) && StringUtils.isNotBlank(properties.getPassword())) { logger.debug("Set credentials"); cloneCommand.setCredentialsProvider( new UsernamePasswordCredentialsProvider(properties.getUserName(), properties.getPassword())); } cloneCommand.setDirectory(fRepo); cloneCommand.setBranch(properties.getBranchName()); logger.debug("Clone the repository"); return cloneCommand.call(); }
From source file:com.meltmedia.cadmium.core.git.GitService.java
License:Apache License
public static GitService cloneRepo(String uri, String dir) throws Exception { if (dir == null || !FileSystemManager.exists(dir)) { log.debug("Cloning \"" + uri + "\" to \"" + dir + "\""); CloneCommand clone = Git.cloneRepository(); clone.setCloneAllBranches(false); clone.setCloneSubmodules(false); if (dir != null) { clone.setDirectory(new File(dir)); }//from w ww. j a v a 2 s . com clone.setURI(uri); try { return new GitService(clone.call()); } catch (Exception e) { if (new File(dir).exists()) { FileUtils.forceDelete(new File(dir)); } throw e; } } return null; }
From source file:com.microsoft.tfs.client.eclipse.ui.egit.importwizard.CloneGitRepositoryCommand.java
License:Open Source License
private boolean cloneRepository(final IProgressMonitor progressMonitor) { final CloneCommand cloneRepository = Git.cloneRepository(); cloneRepository.setCredentialsProvider(credentialsProvider); cloneRepository.setProgressMonitor(new CloneProgress(progressMonitor)); final File workFolder = new File(workingDirectory); if (!workFolder.exists()) { if (!workFolder.mkdirs()) { if (!workFolder.isDirectory()) { final String errorMessageFormat = "Cannot create {0} directory"; //$NON-NLS-1$ throw new RuntimeException(MessageFormat.format(errorMessageFormat, workingDirectory)); }/*from www . j a va 2 s.c om*/ } } cloneRepository.setDirectory(new File(workingDirectory)); cloneRepository.setRemote(remoteName); cloneRepository.setURI(URIUtils.encodeQueryIgnoringPercentCharacters(repositoryUrl.toString())); cloneRepository.setCloneAllBranches(true); cloneRepository.setBranchesToClone(Arrays.asList(refs)); cloneRepository.setBranch(defaultRef); cloneRepository.setNoCheckout(false); cloneRepository.setTimeout(timeout); cloneRepository.setCloneSubmodules(cloneSubmodules); try { cloneRepository.call(); if (progressMonitor.isCanceled()) { throw new CanceledException(); } registerClonedRepository(workingDirectory); } catch (final CanceledException e) { throw e; } catch (final Exception e) { logger.error("Error cloning repository:", e); //$NON-NLS-1$ errorMessage = e.getLocalizedMessage(); return false; } return true; }
From source file:com.oneandone.relesia.connector.scm.git.GitConnector.java
License:Apache License
@Override public void cloneProject(String location, String tag) { authenticate();//from w w w. j a v a2 s. c o m String branch = "".equals(tag) ? "HEAD" : (tagsPath + tag).trim(); File path = new File(localPath + location).getAbsoluteFile(); fileService.delete(path); try (Git result = Git.cloneRepository().setURI(remotePath) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(this.user, this.password)) .setDirectory(path).setBranch(branch).call()) { } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } }
From source file:com.passgit.app.PassGit.java
License:Open Source License
public void cloneRepository() { String remoteUrl = JOptionPane.showInputDialog("Clone Git repository"); if (remoteUrl != null) { try (Git result = Git.cloneRepository().setURI(remoteUrl).call()) { System.out.println("Having repository: " + result.getRepository().getDirectory()); } catch (GitAPIException ex) { Logger.getLogger(PassGit.class.getName()).log(Level.SEVERE, null, ex); }//from w w w. j av a 2 s .c o m } }
From source file:com.photon.phresco.framework.impl.SCMManagerImpl.java
License:Apache License
private void importFromGit(RepoDetail repodetail, File gitImportTemp) throws Exception { if (debugEnabled) { S_LOGGER.debug("Entering Method SCMManagerImpl.importFromGit()"); }/*from www . java 2s .co m*/ if (StringUtils.isEmpty(repodetail.getBranch())) { repodetail.setBranch(MASTER); } // For https and ssh additionalAuthentication(repodetail.getPassPhrase()); UsernamePasswordCredentialsProvider userCredential = new UsernamePasswordCredentialsProvider( repodetail.getUserName(), repodetail.getPassword()); Git r = Git.cloneRepository().setDirectory(gitImportTemp).setCredentialsProvider(userCredential) .setURI(repodetail.getRepoUrl()) // .setProgressMonitor(new TextProgressMonitor()) .setBranch(repodetail.getBranch()).call(); r.getRepository().close(); }
From source file:com.romanenco.gitt.git.GitHelper.java
License:Open Source License
/** * Clone remote HTTP/S repo to local file system. * //from w w w. j av a2s . c om * @param url * @param localPath * @param user * @param password * @throws GitError */ public static void clone(String url, String localPath, String user, String password, ProgressMonitor monitor) throws GitError { Log.d(TAG, "Cloning: " + url); CloneCommand clone = Git.cloneRepository(); clone.setTimeout(30); // set time out for bad servers clone.setURI(url); clone.setDirectory(new File(localPath)); if ((user != null) && (password != null)) { UsernamePasswordCredentialsProvider access = new UsernamePasswordCredentialsProvider(user, password); clone.setCredentialsProvider(access); } if (monitor != null) { clone.setProgressMonitor(monitor); } try { FileUtils.deleteDirectory(new File(localPath)); clone.call(); return; } catch (InvalidRemoteException e) { Log.e(TAG, "InvalidRemote", e); GittApp.saveErrorTrace(e); throw new NotGitRepoError(); } catch (TransportException e) { String trace = GittApp.saveErrorTrace(e); if (trace.indexOf("not authorized") != -1) { Log.e(TAG, "Auth", e); throw new AuthFailError(); } Log.e(TAG, "Transport", e); throw new ConnectionError(); } catch (GitAPIException e) { Log.e(TAG, "GitApi", e); GittApp.saveErrorTrace(e); } catch (IOException e) { Log.e(TAG, "IO", e); GittApp.saveErrorTrace(e); } catch (JGitInternalException e) { Log.e(TAG, "GitInternal", e); GittApp.saveErrorTrace(e); if (e.getCause() instanceof NotSupportedException) { throw new ConnectionError(); } else { throw new GitError(); } } throw new GitError(); }
From source file:com.sap.dirigible.ide.jgit.connector.JGitConnector.java
License:Open Source License
/** * /* w ww .ja v a2s .c o m*/ * Clones secured git remote repository to the file system. * * @param gitDirectory * where the remote repository will be cloned * @param repositoryURI * repository's URI example: https://qwerty.com/xyz/abc.git * @param username * the username used for authentication * @param password * the password used for authentication * * @throws InvalidRemoteException * @throws TransportException * @throws GitAPIException */ public static void cloneRepository(File gitDirectory, String repositoryURI, String username, String password) throws InvalidRemoteException, TransportException, GitAPIException { try { CloneCommand cloneCommand = Git.cloneRepository(); cloneCommand.setURI(repositoryURI); if (!StringUtils.isEmptyOrNull(username) && !StringUtils.isEmptyOrNull(password)) { cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)); } cloneCommand.setRemote(Constants.DEFAULT_REMOTE_NAME); cloneCommand.setDirectory(gitDirectory); cloneCommand.call(); } catch (NullPointerException e) { throw new TransportException(INVALID_USERNAME_AND_PASSWORD); } }