Search in sources :

Example 1 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitLazyResourceVariantTreeSubscriber method getSyncInfo.

@Override
protected SyncInfo getSyncInfo(IResource local, IResourceVariant base, IResourceVariant remote) throws TeamException {
    if (getDataSet().shouldBeIncluded(local)) {
        return super.getSyncInfo(local, base, remote);
    }
    // Otherwise, the given resource was not in the original scope this
    // subscriber was built. However, we want to access it anyway.
    IProject project = local.getProject();
    Repository repo = ResourceUtil.getRepository(local);
    if (repo == null) {
        return null;
    }
    GitSynchronizeData data = getDataSet().getData(project);
    if (data == null) {
        for (GitSynchronizeData sd : getDataSet()) {
            if (repo.equals(sd.getRepository())) {
                data = sd;
                break;
            }
        }
    }
    if (data == null) {
        return null;
    }
    return getSyncInfo(local, base, remote, data);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Repository(org.eclipse.jgit.lib.Repository) IProject(org.eclipse.core.resources.IProject)

Example 2 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitChangeSetModelProvider method getMappings.

@Override
public ResourceMapping[] getMappings(IResource resource, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    if (context instanceof GitSubscriberResourceMappingContext) {
        GitSubscriberResourceMappingContext gitContext = (GitSubscriberResourceMappingContext) context;
        GitSynchronizeDataSet gsds = gitContext.getSyncData();
        GitSynchronizeData data = gsds.getData(resource.getProject());
        if (data != null) {
            GitModelObject object = null;
            try {
                object = GitModelObject.createRoot(data);
            } catch (IOException e) {
                Activator.logError(e.getMessage(), e);
            }
            if (object != null) {
                ResourceMapping rm = AdapterUtils.adapt(object, ResourceMapping.class);
                return new ResourceMapping[] { rm };
            }
        }
    }
    return super.getMappings(resource, context, monitor);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IOException(java.io.IOException) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Example 3 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class GitSynchronizeWizard method performFinish.

@Override
public boolean performFinish() {
    GitSynchronizeDataSet gsdSet = new GitSynchronizeDataSet(page.forceFetch());
    Map<Repository, String> branches = page.getSelectedBranches();
    boolean shouldIncludeLocal = page.shouldIncludeLocal();
    for (Entry<Repository, String> branchesEntry : branches.entrySet()) try {
        Repository repo = branchesEntry.getKey();
        GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, branchesEntry.getValue(), shouldIncludeLocal);
        Set<IResource> resources = getSelectedResources(repo);
        if (resources != null && resources.size() > 0)
            data.setIncludedResources(resources);
        gsdSet.add(data);
    } catch (IOException e) {
        Activator.logError(e.getMessage(), e);
    }
    Set<IProject> selectedProjects = page.getSelectedProjects();
    GitModelSynchronize.launch(gsdSet, selectedProjects.toArray(new IResource[selectedProjects.size()]));
    return true;
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Repository(org.eclipse.jgit.lib.Repository) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) Set(java.util.Set) HashSet(java.util.HashSet) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 4 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class ModelAwareGitSynchronizer method createResourceMappingContext.

/**
 * @param resources
 * @param repository
 * @param leftRev
 * @param rightRev
 * @param includeLocal
 * @param monitor
 * @return A resource mapping context to access the versions of the content
 *         of the resources involved in the synchronization.
 */
protected ResourceMappingContext createResourceMappingContext(Set<IResource> resources, Repository repository, String leftRev, String rightRev, boolean includeLocal, IProgressMonitor monitor) {
    try {
        GitSynchronizeData gsd = new GitSynchronizeData(repository, leftRev, rightRev, includeLocal, resources);
        GitSynchronizeDataSet gsds = new GitSynchronizeDataSet(gsd);
        GitLazyResourceVariantTreeSubscriber subscriber = new GitLazyResourceVariantTreeSubscriber(gsds);
        subscriber.init(monitor);
        return new GitSubscriberResourceMappingContext(subscriber, gsds);
    } catch (IOException e) {
        Activator.logError(e.getMessage(), e);
    }
    return ResourceMappingContext.LOCAL_CONTEXT;
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) GitLazyResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitLazyResourceVariantTreeSubscriber) IOException(java.io.IOException)

Example 5 with GitSynchronizeData

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeData in project egit by eclipse.

the class SynchronizeFetchJob method runInWorkspace.

@Override
public IStatus runInWorkspace(IProgressMonitor monitor) {
    SubMonitor progress = SubMonitor.convert(monitor, gsdSet.size());
    progress.setTaskName(UIText.SynchronizeFetchJob_TaskName);
    for (GitSynchronizeData gsd : gsdSet) {
        Repository repo = gsd.getRepository();
        StoredConfig repoConfig = repo.getConfig();
        String remoteName = gsd.getDstRemoteName();
        if (remoteName == null) {
            progress.worked(1);
            continue;
        }
        progress.subTask(NLS.bind(UIText.SynchronizeFetchJob_SubTaskName, remoteName));
        RemoteConfig config;
        try {
            config = new RemoteConfig(repoConfig, remoteName);
        } catch (URISyntaxException e) {
            Activator.logError(e.getMessage(), e);
            progress.worked(1);
            continue;
        }
        FetchOperationUI fetchOperationUI = new FetchOperationUI(repo, config, timeout, false);
        fetchOperationUI.setCredentialsProvider(new EGitCredentialsProvider());
        try {
            fetchOperationUI.execute(progress.newChild(1));
            gsd.updateRevs();
        } catch (Exception e) {
            showInformationDialog(remoteName);
            Activator.logError(e.getMessage(), e);
        }
    }
    return Status.OK_STATUS;
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Repository(org.eclipse.jgit.lib.Repository) SubMonitor(org.eclipse.core.runtime.SubMonitor) URISyntaxException(java.net.URISyntaxException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) URISyntaxException(java.net.URISyntaxException) FetchOperationUI(org.eclipse.egit.ui.internal.fetch.FetchOperationUI)

Aggregations

GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)42 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)26 Test (org.junit.Test)15 Repository (org.eclipse.jgit.lib.Repository)14 IResource (org.eclipse.core.resources.IResource)13 IFile (org.eclipse.core.resources.IFile)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 IResourceVariant (org.eclipse.team.core.variants.IResourceVariant)9 IOException (java.io.IOException)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 HashSet (java.util.HashSet)7 IProject (org.eclipse.core.resources.IProject)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IStorage (org.eclipse.core.resources.IStorage)6 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)5 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)3 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)3