List of usage examples for org.eclipse.jgit.api Git submoduleUpdate
public SubmoduleUpdateCommand submoduleUpdate()
From source file:com.google.devtools.build.lib.bazel.repository.GitCloneFunction.java
License:Open Source License
@Nullable @Override// www . j a va2 s . c o m 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 w w . j av a 2 s. 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:edu.tum.cs.mylyn.provisioning.git.ui.GitProvisioningWizard.java
License:Open Source License
private void pull(Repository repository) throws IOException { Git git = new Git(repository); PullCommand pull = git.pull();//from w w w.ja va 2 s . c o m pull.setCredentialsProvider(new EGitCredentialsProvider()); try { pull.call(); } catch (TransportException e) { throw new IOException(e); } catch (GitAPIException e) { throw new IOException(e); } SubmoduleUpdateCommand update = git.submoduleUpdate(); try { update.call(); } catch (Exception e) { throw new IOException(e); } }
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 www . j a v a 2 s . c o m 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();// w ww.j a v a 2 s. co m SubmoduleUpdateCommand updateCommand = git.submoduleUpdate(); updateCommand.setProgressMonitor(new EclipseGitProgressTransformer(monitor)); updateCommand.call(); }
From source file:org.gradle.vcs.git.internal.GitVersionControlSystem.java
License:Apache License
private static void updateSubModules(Git git) throws IOException, GitAPIException { SubmoduleWalk walker = SubmoduleWalk.forIndex(git.getRepository()); try {//from ww w . j av a2s. com while (walker.next()) { Repository submodule = walker.getRepository(); try { Git submoduleGit = Git.wrap(submodule); submoduleGit.fetch().call(); git.submoduleUpdate().addPath(walker.getPath()).call(); submoduleGit.reset().setMode(ResetCommand.ResetType.HARD).call(); updateSubModules(submoduleGit); } finally { submodule.close(); } } } finally { walker.close(); } }