List of usage examples for org.eclipse.jgit.api Git submoduleInit
public SubmoduleInitCommand submoduleInit()
From source file:com.google.devtools.build.lib.bazel.repository.GitCloneFunction.java
License:Open Source License
@Nullable @Override//from w w w .j av a 2 s . c om public SkyValue compute(SkyKey skyKey, Environment env) throws RepositoryFunctionException { GitRepositoryDescriptor descriptor = (GitRepositoryDescriptor) skyKey.argument(); Git git = null; try { if (descriptor.directory.exists()) { if (isUpToDate(descriptor)) { return new HttpDownloadValue(descriptor.directory); } try { FileSystemUtils.deleteTree(descriptor.directory); } catch (IOException e) { throw new RepositoryFunctionException(e, Transience.TRANSIENT); } } git = Git.cloneRepository().setURI(descriptor.remote) .setCredentialsProvider(new NetRCCredentialsProvider()) .setDirectory(descriptor.directory.getPathFile()).setCloneSubmodules(false).setNoCheckout(true) .setProgressMonitor(new GitProgressMonitor("Cloning " + descriptor.remote, reporter)).call(); git.checkout().setCreateBranch(true).setName("bazel-checkout").setStartPoint(descriptor.checkout) .call(); // Using CloneCommand.setCloneSubmodules() results in SubmoduleInitCommand and // SubmoduleUpdateCommand to be called recursively for all submodules. This is not // desirable for repositories, such as github.com/rust-lang/rust-installer, which // recursively includes itself as a submodule, which would result in an infinite // loop if submodules are cloned recursively. For now, limit submodules to only // the first level. if (descriptor.initSubmodules && !git.submoduleInit().call().isEmpty()) { git.submoduleUpdate() .setProgressMonitor( new GitProgressMonitor("Cloning submodules for " + descriptor.remote, reporter)) .call(); } } catch (InvalidRemoteException e) { throw new RepositoryFunctionException(new IOException("Invalid Git repository URI: " + e.getMessage()), Transience.PERSISTENT); } catch (RefNotFoundException | InvalidRefNameException e) { throw new RepositoryFunctionException( new IOException("Invalid branch, tag, or commit: " + e.getMessage()), Transience.PERSISTENT); } catch (GitAPIException e) { throw new RepositoryFunctionException(new IOException(e.getMessage()), Transience.TRANSIENT); } finally { if (git != null) { git.close(); } } return new HttpDownloadValue(descriptor.directory); }
From source file:com.google.devtools.build.lib.bazel.repository.GitCloner.java
License:Open Source License
public static SkyValue clone(Rule rule, Path outputDirectory, EventHandler eventHandler, Map<String, String> clientEnvironment) throws RepositoryFunctionException { WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule); if (mapper.isAttributeValueExplicitlySpecified("commit") == mapper .isAttributeValueExplicitlySpecified("tag")) { throw new RepositoryFunctionException( new EvalException(rule.getLocation(), "One of either commit or tag must be defined"), Transience.PERSISTENT);//from w ww .ja v a2s. c om } GitRepositoryDescriptor descriptor; String startingPoint; try { if (mapper.isAttributeValueExplicitlySpecified("commit")) { startingPoint = mapper.get("commit", Type.STRING); } else { startingPoint = "tags/" + mapper.get("tag", Type.STRING); } descriptor = new GitRepositoryDescriptor(mapper.get("remote", Type.STRING), startingPoint, mapper.get("init_submodules", Type.BOOLEAN), outputDirectory); } catch (EvalException e) { throw new RepositoryFunctionException(e, Transience.PERSISTENT); } // Setup proxy if remote is http or https if (descriptor.remote != null && Ascii.toLowerCase(descriptor.remote).startsWith("http")) { try { new ProxyHelper(clientEnvironment).createProxyIfNeeded(new URL(descriptor.remote)); } catch (IOException ie) { throw new RepositoryFunctionException(ie, Transience.TRANSIENT); } } Git git = null; try { if (descriptor.directory.exists()) { if (isUpToDate(descriptor)) { return new HttpDownloadValue(descriptor.directory); } try { FileSystemUtils.deleteTree(descriptor.directory); } catch (IOException e) { throw new RepositoryFunctionException(e, Transience.TRANSIENT); } } git = Git.cloneRepository().setURI(descriptor.remote) .setCredentialsProvider(new NetRCCredentialsProvider()) .setDirectory(descriptor.directory.getPathFile()).setCloneSubmodules(false).setNoCheckout(true) .setProgressMonitor(new GitProgressMonitor("Cloning " + descriptor.remote, eventHandler)) .call(); git.checkout().setCreateBranch(true).setName("bazel-checkout").setStartPoint(descriptor.checkout) .call(); // Using CloneCommand.setCloneSubmodules() results in SubmoduleInitCommand and // SubmoduleUpdateCommand to be called recursively for all submodules. This is not // desirable for repositories, such as github.com/rust-lang/rust-installer, which // recursively includes itself as a submodule, which would result in an infinite // loop if submodules are cloned recursively. For now, limit submodules to only // the first level. if (descriptor.initSubmodules && !git.submoduleInit().call().isEmpty()) { git.submoduleUpdate() .setProgressMonitor( new GitProgressMonitor("Cloning submodules for " + descriptor.remote, eventHandler)) .call(); } } catch (InvalidRemoteException e) { throw new RepositoryFunctionException(new IOException("Invalid Git repository URI: " + e.getMessage()), Transience.PERSISTENT); } catch (RefNotFoundException | InvalidRefNameException e) { throw new RepositoryFunctionException( new IOException("Invalid branch, tag, or commit: " + e.getMessage()), Transience.PERSISTENT); } catch (GitAPIException e) { // This is a sad attempt to actually get a useful error message out of jGit, which will bury // the actual (useful) cause of the exception under several throws. StringBuilder errmsg = new StringBuilder(); errmsg.append(e.getMessage()); Throwable throwable = e; while (throwable.getCause() != null) { throwable = throwable.getCause(); errmsg.append(" caused by " + throwable.getMessage()); } throw new RepositoryFunctionException(new IOException("Error cloning repository: " + errmsg), Transience.PERSISTENT); } catch (JGitInternalException e) { // This is a lame catch-all for jgit throwing RuntimeExceptions all over the place because, // as the docs put it, "a lot of exceptions are so low-level that is is unlikely that the // caller of the command can handle them effectively." Thanks, jgit. throw new RepositoryFunctionException(new IOException(e.getMessage()), Transience.PERSISTENT); } finally { if (git != null) { git.close(); } } return new HttpDownloadValue(descriptor.directory); }
From source file:org.eclipse.egit.core.op.SubmoduleUpdateOperation.java
License:Open Source License
public void execute(final IProgressMonitor monitor) throws CoreException { IWorkspaceRunnable action = new IWorkspaceRunnable() { public void run(IProgressMonitor pm) throws CoreException { pm.beginTask("", 3); //$NON-NLS-1$ Git git = Git.wrap(repository); Collection<String> updated = null; try { SubmoduleInitCommand init = git.submoduleInit(); for (String path : paths) init.addPath(path);//from w w w .j av a 2s . c om init.call(); pm.worked(1); SubmoduleUpdateCommand update = git.submoduleUpdate(); for (String path : paths) update.addPath(path); update.setProgressMonitor(new EclipseGitProgressTransformer(new SubProgressMonitor(pm, 2))); updated = update.call(); pm.worked(1); SubProgressMonitor refreshMonitor = new SubProgressMonitor(pm, 1); refreshMonitor.beginTask("", updated.size()); //$NON-NLS-1$ for (String path : updated) { Repository subRepo = SubmoduleWalk.getSubmoduleRepository(repository, path); if (subRepo != null) ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(subRepo), new SubProgressMonitor(refreshMonitor, 1)); else refreshMonitor.worked(1); } refreshMonitor.done(); } catch (GitAPIException e) { throw new TeamException(e.getLocalizedMessage(), e.getCause()); } catch (IOException e) { throw new TeamException(e.getLocalizedMessage(), e.getCause()); } finally { if (updated != null && !updated.isEmpty()) repository.notifyIndexChanged(); pm.done(); } } }; ResourcesPlugin.getWorkspace().run(action, monitor != null ? monitor : new NullProgressMonitor()); }
From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java
License:Open Source License
private static void addSubmodules(SetupTaskContext context, Git git, SubProgressMonitor monitor) throws Exception { context.log("Adding submodules"); git.submoduleInit().call(); SubmoduleUpdateCommand updateCommand = git.submoduleUpdate(); updateCommand.setProgressMonitor(new EclipseGitProgressTransformer(monitor)); updateCommand.call();/*from ww w .ja va2 s. c om*/ }