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

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

Introduction

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

Prototype

@Override
public Collection<String> call() throws GitAPIException 

Source Link

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  2  s . co 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.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   www  .j a v a 2  s  . com*/
 *            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);
    }
}

From source file:org.eclipse.orion.server.git.servlets.GitSubmoduleHandlerV1.java

License:Open Source License

public static boolean updateSubmodules(Repository repo) throws GitAPIException {
    SubmoduleInitCommand init = new SubmoduleInitCommand(repo);
    init.call();
    SubmoduleUpdateCommand update = new SubmoduleUpdateCommand(repo);
    Collection<String> updated = update.call();
    SubmoduleStatusCommand status = new SubmoduleStatusCommand(repo);
    Map<String, SubmoduleStatus> statusResult = status.call();
    return updated.size() == statusResult.size();
}