Search in sources :

Example 16 with GitSynchronizeData

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

the class GitResourceVariantTreeTest method shouldReturnNullResourceVariant.

/**
 * Checks that getResourceVariant will not throw NPE for null argument. This
 * method is called with null argument when local or remote resource does
 * not exist.
 *
 * @throws Exception
 */
@Test
public void shouldReturnNullResourceVariant() throws Exception {
    // when
    try (Git git = new Git(repo)) {
        git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
    }
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, false);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    // given
    GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(null, dataSet);
    // then
    assertNull(grvt.getResourceVariant(null));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Git(org.eclipse.jgit.api.Git) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) Test(org.junit.Test)

Example 17 with GitSynchronizeData

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

the class GitSubscriberResourceMappingContextTest method prepareContext.

private RemoteResourceMappingContext prepareContext(String srcRev, String dstRev) throws Exception {
    GitSynchronizeData gsd = new GitSynchronizeData(repo, srcRev, dstRev, true);
    GitSynchronizeDataSet gsds = new GitSynchronizeDataSet(gsd);
    GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(gsds);
    subscriber.init(new NullProgressMonitor());
    return new GitSubscriberResourceMappingContext(subscriber, gsds);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)

Example 18 with GitSynchronizeData

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

the class GitResourceVariantTreeSubscriber method getDiff.

@Override
public IDiff getDiff(IResource resource) throws CoreException {
    final GitSynchronizeData syncData = gsds.getData(resource.getProject());
    if (syncData == null || syncData.shouldIncludeLocal())
        return super.getDiff(resource);
    SyncInfo info = getSyncInfo(resource);
    if (info == null || info.getKind() == SyncInfo.IN_SYNC)
        return null;
    return syncInfoConverter.getDeltaFor(info);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) SyncInfo(org.eclipse.team.core.synchronize.SyncInfo)

Example 19 with GitSynchronizeData

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

the class GitResourceVariantTreeSubscriber method members.

/**
 * Returns all members of the given resource as recorded by git. Resources
 * ignored by git via .gitignore will not be returned, even if they exist in
 * the workspace.
 *
 * @param res
 *            the resource to get the members of
 * @return the resources, which may or may not exist in the workspace
 */
@Override
public IResource[] members(IResource res) throws TeamException {
    if (res.getType() == IResource.FILE || !gsds.shouldBeIncluded(res)) {
        return new IResource[0];
    }
    GitSynchronizeData gsd = gsds.getData(res.getProject());
    Repository repo = gsd.getRepository();
    GitSyncObjectCache repoCache = cache.get(repo);
    Collection<IResource> allMembers = new ArrayList<>();
    Map<String, IResource> existingMembers = new HashMap<>();
    String path = stripWorkDir(repo.getWorkTree(), res.getLocation().toFile());
    GitSyncObjectCache cachedMembers = repoCache.get(path);
    // one if it's a file vs.folder conflict.
    try {
        IContainer container = (IContainer) res;
        // Existing resources
        if (container.exists()) {
            for (IResource member : container.members()) {
                existingMembers.put(member.getName(), member);
            }
        }
        // Now add the ones from git
        if (cachedMembers != null) {
            Collection<GitSyncObjectCache> members = cachedMembers.members();
            if (members != null) {
                for (GitSyncObjectCache gitMember : members) {
                    String name = gitMember.getName();
                    IResource existing = existingMembers.get(name);
                    if (existing != null) {
                        allMembers.add(existing);
                    }
                    if (existing == null || (existing.getType() != IResource.FILE) != gitMember.getDiffEntry().isTree()) {
                        // Non-existing, or file vs. folder
                        IPath localPath = new Path(name);
                        if (gitMember.getDiffEntry().isTree()) {
                            allMembers.add(container.getFolder(localPath));
                        } else {
                            allMembers.add(container.getFile(localPath));
                        }
                    }
                }
            }
        }
    } catch (CoreException e) {
        throw TeamException.asTeamException(e);
    }
    return allMembers.toArray(new IResource[allMembers.size()]);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 20 with GitSynchronizeData

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

the class GitSubscriberMergeContext method handleRepositoryChange.

private void handleRepositoryChange(Repository which) {
    boolean shouldRefresh = false;
    for (GitSynchronizeData gsd : gsds) {
        if (which.equals(gsd.getRepository())) {
            updateRevs(gsd);
            shouldRefresh = true;
        }
    }
    if (!shouldRefresh)
        return;
    subscriber.reset(this.gsds);
    ResourceTraversal[] traversals = getScopeManager().getScope().getTraversals();
    try {
        subscriber.refresh(traversals, new NullProgressMonitor());
    } catch (TeamException e) {
        Activator.logError(CoreText.GitSubscriberMergeContext_FailedRefreshSyncView, e);
    }
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TeamException(org.eclipse.team.core.TeamException)

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