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));
}
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);
}
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);
}
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()]);
}
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);
}
}
Aggregations