Search in sources :

Example 1 with SubmoduleUpdateCommand

use of org.eclipse.jgit.api.SubmoduleUpdateCommand in project egit by eclipse.

the class SubmoduleUpdateOperation method execute.

@Override
public void execute(final IProgressMonitor monitor) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor pm) throws CoreException {
            RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
            SubMonitor progress = SubMonitor.convert(pm, 4);
            progress.setTaskName(MessageFormat.format(CoreText.SubmoduleUpdateOperation_updating, util.getRepositoryName(repository)));
            Git git = Git.wrap(repository);
            Collection<String> updated = null;
            try {
                SubmoduleInitCommand init = git.submoduleInit();
                for (String path : paths) init.addPath(path);
                init.call();
                progress.worked(1);
                SubmoduleUpdateCommand update = git.submoduleUpdate();
                for (String path : paths) update.addPath(path);
                update.setProgressMonitor(new EclipseGitProgressTransformer(progress.newChild(2)));
                MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
                if (strategy != null) {
                    update.setStrategy(strategy);
                }
                update.setCallback(new CloneCommand.Callback() {

                    @Override
                    public void initializedSubmodules(Collection<String> submodules) {
                    // Nothing to do
                    }

                    @Override
                    public void cloningSubmodule(String path) {
                        progress.setTaskName(MessageFormat.format(CoreText.SubmoduleUpdateOperation_cloning, util.getRepositoryName(repository), path));
                    }

                    @Override
                    public void checkingOut(AnyObjectId commit, String path) {
                    // Nothing to do
                    }
                });
                updated = update.call();
                SubMonitor refreshMonitor = progress.newChild(1).setWorkRemaining(updated.size());
                for (String path : updated) {
                    Repository subRepo = SubmoduleWalk.getSubmoduleRepository(repository, path);
                    if (subRepo != null) {
                        ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(subRepo), refreshMonitor.newChild(1));
                    } else {
                        refreshMonitor.worked(1);
                    }
                }
            } 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();
                }
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
Also used : CloneCommand(org.eclipse.jgit.api.CloneCommand) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) SubmoduleUpdateCommand(org.eclipse.jgit.api.SubmoduleUpdateCommand) MergeStrategy(org.eclipse.jgit.merge.MergeStrategy) SubMonitor(org.eclipse.core.runtime.SubMonitor) EclipseGitProgressTransformer(org.eclipse.egit.core.EclipseGitProgressTransformer) IOException(java.io.IOException) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) SubmoduleInitCommand(org.eclipse.jgit.api.SubmoduleInitCommand)

Aggregations

IOException (java.io.IOException)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 EclipseGitProgressTransformer (org.eclipse.egit.core.EclipseGitProgressTransformer)1 RepositoryUtil (org.eclipse.egit.core.RepositoryUtil)1 CloneCommand (org.eclipse.jgit.api.CloneCommand)1 Git (org.eclipse.jgit.api.Git)1 SubmoduleInitCommand (org.eclipse.jgit.api.SubmoduleInitCommand)1 SubmoduleUpdateCommand (org.eclipse.jgit.api.SubmoduleUpdateCommand)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 AnyObjectId (org.eclipse.jgit.lib.AnyObjectId)1 Repository (org.eclipse.jgit.lib.Repository)1 MergeStrategy (org.eclipse.jgit.merge.MergeStrategy)1 TeamException (org.eclipse.team.core.TeamException)1