Example usage for org.eclipse.jgit.api SubmoduleUpdateCommand addPath

List of usage examples for org.eclipse.jgit.api SubmoduleUpdateCommand addPath

Introduction

In this page you can find the example usage for org.eclipse.jgit.api SubmoduleUpdateCommand addPath.

Prototype

public SubmoduleUpdateCommand addPath(String path) 

Source Link

Document

Add repository-relative submodule path to initialize

Usage

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 .  ja  v  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.n4js.utils.git.GitUtils.java

License:Open Source License

/**
 * Update the submodules with the given repository-relative <code>submodulePaths</code> inside the Git repository at
 * the given clone path. Throws exceptions in case of error.
 *
 * @param submodulePaths//w  ww  . j a v  a  2 s .  c o m
 *            repository-relative paths of the submodules to update; if empty, all submodules will be updated.
 */
public static void updateSubmodules(final Path localClonePath, final Iterable<String> submodulePaths,
        final IProgressMonitor monitor) {

    if (!isValidLocalClonePath(localClonePath)) {
        throw new IllegalArgumentException("invalid localClonePath: " + localClonePath);
    }

    @SuppressWarnings("restriction")
    final ProgressMonitor gitMonitor = null == monitor ? createMonitor()
            : new org.eclipse.egit.core.EclipseGitProgressTransformer(monitor);

    try (final Git git = open(localClonePath.toFile())) {
        final SubmoduleUpdateCommand cmd = git.submoduleUpdate();
        for (String submodulePath : submodulePaths) {
            cmd.addPath(submodulePath);
        }
        cmd.setProgressMonitor(gitMonitor);
        cmd.setTransportConfigCallback(TRANSPORT_CALLBACK);
        cmd.call();
    } catch (Exception e) {
        LOGGER.error(e.getClass().getSimpleName() + " while trying to update submodules "
                + Iterables.toString(submodulePaths) + " of repository '" + localClonePath + "':"
                + e.getLocalizedMessage());
        Throwables.throwIfUnchecked(e);
        throw new RuntimeException(e);
    }
}