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

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

Introduction

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

Prototype

public SubmoduleInitCommand 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);
                init.call();//from   w  w w  . j  a  v  a2  s  .  c  o m
                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

/**
 * Initialize 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/*from w  w w .  ja v a 2s  .  co  m*/
 *            repository-relative paths of the submodules to initialized; if empty, all submodules will be
 *            initialized.
 */
public static void initSubmodules(final Path localClonePath, final Iterable<String> submodulePaths) {

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

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