Search in sources :

Example 1 with InvalidConfigurationException

use of org.eclipse.jgit.api.errors.InvalidConfigurationException in project egit by eclipse.

the class PullOperation method execute.

@Override
public void execute(IProgressMonitor m) throws CoreException {
    if (!results.isEmpty())
        throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), CoreText.OperationAlreadyExecuted));
    SubMonitor totalProgress = SubMonitor.convert(m, NLS.bind(CoreText.PullOperation_TaskName, Integer.valueOf(repositories.length)), 1);
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor mymonitor) throws CoreException {
            if (mymonitor.isCanceled())
                throw new CoreException(Status.CANCEL_STATUS);
            SubMonitor progress = SubMonitor.convert(mymonitor, repositories.length * 2);
            for (int i = 0; i < repositories.length; i++) {
                Repository repository = repositories[i];
                IProject[] validProjects = ProjectUtil.getValidOpenProjects(repository);
                PullResult pullResult = null;
                try (Git git = new Git(repository)) {
                    PullCommand pull = git.pull();
                    SubMonitor newChild = progress.newChild(1, SubMonitor.SUPPRESS_NONE);
                    pull.setProgressMonitor(new EclipseGitProgressTransformer(newChild));
                    pull.setTimeout(timeout);
                    pull.setCredentialsProvider(credentialsProvider);
                    PullReferenceConfig config = configs.get(repository);
                    newChild.setTaskName(getPullTaskName(repository, config));
                    if (config != null) {
                        if (config.getRemote() != null) {
                            pull.setRemote(config.getRemote());
                        }
                        if (config.getReference() != null) {
                            pull.setRemoteBranchName(config.getReference());
                        }
                        pull.setRebase(config.getUpstreamConfig());
                    }
                    MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
                    if (strategy != null) {
                        pull.setStrategy(strategy);
                    }
                    pullResult = pull.call();
                    results.put(repository, pullResult);
                } catch (DetachedHeadException e) {
                    results.put(repository, Activator.error(CoreText.PullOperation_DetachedHeadMessage, e));
                } catch (InvalidConfigurationException e) {
                    IStatus error = Activator.error(CoreText.PullOperation_PullNotConfiguredMessage, e);
                    results.put(repository, error);
                } catch (GitAPIException e) {
                    results.put(repository, Activator.error(e.getMessage(), e));
                } catch (JGitInternalException e) {
                    Throwable cause = e.getCause();
                    if (cause == null || !(cause instanceof TransportException))
                        cause = e;
                    results.put(repository, Activator.error(cause.getMessage(), cause));
                } finally {
                    if (refreshNeeded(pullResult)) {
                        ProjectUtil.refreshValidProjects(validProjects, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
                    } else {
                        progress.worked(1);
                    }
                }
            }
        }
    };
    // lock workspace to protect working tree changes
    ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, totalProgress);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) MergeStatus(org.eclipse.jgit.api.MergeResult.MergeStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) PullCommand(org.eclipse.jgit.api.PullCommand) IStatus(org.eclipse.core.runtime.IStatus) MergeStrategy(org.eclipse.jgit.merge.MergeStrategy) SubMonitor(org.eclipse.core.runtime.SubMonitor) EclipseGitProgressTransformer(org.eclipse.egit.core.EclipseGitProgressTransformer) TransportException(org.eclipse.jgit.errors.TransportException) IProject(org.eclipse.core.resources.IProject) PullResult(org.eclipse.jgit.api.PullResult) InvalidConfigurationException(org.eclipse.jgit.api.errors.InvalidConfigurationException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) CoreException(org.eclipse.core.runtime.CoreException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) DetachedHeadException(org.eclipse.jgit.api.errors.DetachedHeadException)

Aggregations

IProject (org.eclipse.core.resources.IProject)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 EclipseGitProgressTransformer (org.eclipse.egit.core.EclipseGitProgressTransformer)1 Git (org.eclipse.jgit.api.Git)1 MergeStatus (org.eclipse.jgit.api.MergeResult.MergeStatus)1 PullCommand (org.eclipse.jgit.api.PullCommand)1 PullResult (org.eclipse.jgit.api.PullResult)1 DetachedHeadException (org.eclipse.jgit.api.errors.DetachedHeadException)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 InvalidConfigurationException (org.eclipse.jgit.api.errors.InvalidConfigurationException)1 JGitInternalException (org.eclipse.jgit.api.errors.JGitInternalException)1 TransportException (org.eclipse.jgit.errors.TransportException)1 Repository (org.eclipse.jgit.lib.Repository)1 MergeStrategy (org.eclipse.jgit.merge.MergeStrategy)1