List of usage examples for org.eclipse.jgit.api CloneCommand setCloneSubmodules
public CloneCommand setCloneSubmodules(boolean cloneSubmodules)
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)); }/* w ww.j av a2 s .c o m*/ 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)); }/*ww w.jav a 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:io.hawkcd.agent.services.GitMaterialService.java
License:Apache License
@Override public String fetchMaterial(FetchMaterialTask task) { String errorMessage = null;//from w ww. j a v a 2 s . c o m String materialPath = Paths.get(AgentConfiguration.getInstallInfo().getAgentPipelinesDir(), task.getPipelineName(), task.getDestination()).toString(); GitMaterial definition = (GitMaterial) task.getMaterialDefinition(); CloneCommand clone = Git.cloneRepository(); clone.setURI(definition.getRepositoryUrl()); clone.setBranch(definition.getBranch()); clone.setDirectory(new File(materialPath)); clone.setCloneSubmodules(true); UsernamePasswordCredentialsProvider credentials = this.handleCredentials(definition); clone.setCredentialsProvider(credentials); try { Git git = clone.call(); git.close(); } catch (GitAPIException e) { errorMessage = e.getMessage(); } return errorMessage; }
From source file:org.flowerplatform.web.git.GitService.java
License:Open Source License
@RemoteInvocation public boolean cloneRepository(final ServiceInvocationContext context, List<PathFragment> selectedPath, String repositoryUrl, final List<String> selectedBranches, final String remoteName, final boolean cloneAllBranches) { tlCommand.set((InvokeServiceMethodServerCommand) context.getCommand()); final URIish uri; try {/*w w w. jav a2s . com*/ uri = new URIish(repositoryUrl.trim()); } catch (URISyntaxException e) { context.getCommunicationChannel().appendOrSendCommand( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getReason(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return false; } @SuppressWarnings("unchecked") final Pair<File, Object> node = (Pair<File, Object>) GenericTreeStatefulService .getNodeByPathFor(selectedPath, null); File gitReposFile = GitPlugin.getInstance().getUtils().getGitRepositoriesFile(node.a); final File mainRepo = GitPlugin.getInstance().getUtils() .getMainRepositoryFile(new File(gitReposFile, uri.getHumanishName()), true); final ProgressMonitor monitor = ProgressMonitor.create( GitPlugin.getInstance().getMessage("git.clone.monitor.title", uri), context.getCommunicationChannel()); monitor.beginTask(GitPlugin.getInstance().getMessage("git.clone.monitor.title", uri), 2); Job job = new Job( MessageFormat.format(GitPlugin.getInstance().getMessage("git.clone.monitor.title", uri), uri)) { @Override protected IStatus run(IProgressMonitor m) { Repository repository = null; try { CloneCommand cloneRepository = Git.cloneRepository(); cloneRepository.setNoCheckout(true); cloneRepository.setDirectory(mainRepo); cloneRepository.setProgressMonitor(new GitProgressMonitor(new SubProgressMonitor(monitor, 1))); cloneRepository.setRemote(remoteName); cloneRepository.setURI(uri.toString()); cloneRepository.setTimeout(30); cloneRepository.setCloneAllBranches(cloneAllBranches); cloneRepository.setCloneSubmodules(false); if (selectedBranches.size() > 0) { cloneRepository.setBranchesToClone(selectedBranches); } Git git = cloneRepository.call(); repository = git.getRepository(); // notify clients about changes dispatchContentUpdate(node); monitor.worked(1); } catch (Exception e) { if (repository != null) repository.close(); GitPlugin.getInstance().getUtils().delete(mainRepo.getParentFile()); if (monitor.isCanceled()) { return Status.OK_STATUS; } if (GitPlugin.getInstance().getUtils().isAuthentificationException(e)) { openLoginWindow(); return Status.OK_STATUS; } logger.debug(GitPlugin.getInstance().getMessage("git.cloneWizard.error", new Object[] { mainRepo.getName() }), e); context.getCommunicationChannel() .appendOrSendCommand(new DisplaySimpleMessageClientCommand( CommonPlugin.getInstance().getMessage("error"), GitPlugin.getInstance().getMessage("git.cloneWizard.error", new Object[] { mainRepo.getName() }), DisplaySimpleMessageClientCommand.ICON_ERROR)); return Status.CANCEL_STATUS; } finally { monitor.done(); if (repository != null) { repository.close(); } } return Status.OK_STATUS; } }; job.schedule(); return true; }