use of org.eclipse.team.core.variants.IResourceVariantTree in project egit by eclipse.
the class GitResourceVariantTreeSubscriberTest method getSourceVariant.
private IResourceVariant getSourceVariant(GitResourceVariantTreeSubscriber subscriber, IResource resource, boolean includeLocal) throws TeamException {
IResourceVariantTree tree = subscriber.getSourceTree();
assertNotNull(tree);
assertTrue(tree instanceof GitSourceResourceVariantTree);
IResourceVariant resourceVariant = tree.getResourceVariant(resource);
assertNotNull(resourceVariant);
if (includeLocal)
assertTrue(resourceVariant instanceof GitLocalResourceVariant);
else
assertTrue(resourceVariant instanceof GitRemoteResource);
return resourceVariant;
}
use of org.eclipse.team.core.variants.IResourceVariantTree in project egit by eclipse.
the class GitResourceVariantTreeSubscriberTest method getRemoteVariant.
private IResourceVariant getRemoteVariant(GitResourceVariantTreeSubscriber subscriber, IResource resource) throws TeamException {
IResourceVariantTree tree = subscriber.getRemoteTree();
assertNotNull(tree);
assertTrue(tree instanceof GitRemoteResourceVariantTree);
IResourceVariant resourceVariant = tree.getResourceVariant(resource);
assertNotNull(resourceVariant);
assertTrue(resourceVariant instanceof GitRemoteResource);
return resourceVariant;
}
use of org.eclipse.team.core.variants.IResourceVariantTree in project egit by eclipse.
the class GitResourceVariantTreeSubscriberTest method getBaseVariant.
private IResourceVariant getBaseVariant(GitResourceVariantTreeSubscriber subscriber, IResource resource) throws TeamException {
IResourceVariantTree tree = subscriber.getBaseTree();
assertNotNull(tree);
assertTrue(tree instanceof GitBaseResourceVariantTree);
IResourceVariant resourceVariant = tree.getResourceVariant(resource);
assertNotNull(resourceVariant);
assertTrue(resourceVariant instanceof GitRemoteResource);
return resourceVariant;
}
use of org.eclipse.team.core.variants.IResourceVariantTree in project egit by eclipse.
the class GitResourceVariantTreeTest method shouldNotReturnNullOnSameResouceVariant.
@Test
public void shouldNotReturnNullOnSameResouceVariant() throws Exception {
String modifiedFileName = "changingFile." + SampleModelProvider.SAMPLE_FILE_EXTENSION;
String unchangedFileName = "notChangingFile." + SampleModelProvider.SAMPLE_FILE_EXTENSION;
String removedFileName = "toBeRemovedFile." + SampleModelProvider.SAMPLE_FILE_EXTENSION;
File modifiedFile = testRepo.createFile(iProject, modifiedFileName);
File unchangedFile = testRepo.createFile(iProject, unchangedFileName);
File removedFile = testRepo.createFile(iProject, removedFileName);
testRepo.appendFileContent(modifiedFile, "My content is changing");
testRepo.appendFileContent(unchangedFile, "My content is constant");
testRepo.appendFileContent(removedFile, "I will be removed");
IFile iModifiedFile = testRepo.getIFile(iProject, modifiedFile);
IFile iUnchangedFile = testRepo.getIFile(iProject, unchangedFile);
IFile iRemovedFile = testRepo.getIFile(iProject, removedFile);
testRepo.trackAllFiles(iProject);
RevCommit firstCommit = testRepo.commit("C1");
testRepo.appendFileContent(modifiedFile, " My content has changed");
testRepo.track(modifiedFile);
testRepo.removeFromIndex(removedFile);
RevCommit secondCommit = testRepo.commit("C2");
// @formatter:off
// History (X means has changed)
// ------------------------------------------------------------
// files C1 [HEAD] C2
// changingFile.sample |-----X----------|-------X-------|->
// notChangingFile.sample |-----X----------|---------------|->
// toBeRemovedFile.sample |-----X----------|-------X-------|->
// -------------------------------------------------------------
// @formatter:on
testRepo.checkoutBranch(firstCommit.getName());
iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
// Now synchronize the two commits using our logical model provider
SampleModelProvider provider = new SampleModelProvider();
// Get the affected resources
ResourceMapping[] mappings = provider.getMappings(iModifiedFile, ResourceMappingContext.LOCAL_CONTEXT, new NullProgressMonitor());
Set<IResource> includedResource = collectResources(mappings);
Set<IResource> expectedIncludedResources = new HashSet<IResource>();
expectedIncludedResources.add(iModifiedFile);
expectedIncludedResources.add(iUnchangedFile);
expectedIncludedResources.add(iRemovedFile);
assertEquals(expectedIncludedResources, includedResource);
// Synchronize the data
final GitSynchronizeData data = new GitSynchronizeData(testRepo.getRepository(), firstCommit.getName(), secondCommit.getName(), true, includedResource);
GitSynchronizeDataSet gitSynchDataSet = new GitSynchronizeDataSet(data);
final GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(gitSynchDataSet);
subscriber.init(new NullProgressMonitor());
IResourceVariantTree sourceVariantTree = subscriber.getSourceTree();
assertNotNull(sourceVariantTree);
IResourceVariantTree remoteVariantTree = subscriber.getRemoteTree();
assertNotNull(remoteVariantTree);
// In the use case in which the file has been deleted the source variant is
// not null whereas the remote variant is null.It seems quite logic.
// However in the second use case we have the same result, the source variant is
// not null whereas the remote is null. In both cases the null value does
// not mean the same thing. In the first case, the null value means that
// the resource is no longer in the repository and in the second the
// null value means there is no change between the two versions.
// Using these values I am not able to distinguish both case.
// It is in contradiction with test #shouldReturnNullResourceVariant2()
// and test #shoulReturnSameResourceVariant(). However I haven't found
// another way to handle this case. Maybe something can be
// done with ThreeWayDiffEntry.scan(tw) to force including in the cache
// some entry even if they have not changed. For example,
// ThreeWayDiffEntry.scan(tw,includedSource) or maybe try preventing the variant
// tree to return null by walking throught the repository and looking for the file...
IResourceVariant unchangedSourceVariant = sourceVariantTree.getResourceVariant(iUnchangedFile);
IResourceVariant unchangedRemoteVariant = remoteVariantTree.getResourceVariant(iUnchangedFile);
assertNotNull(unchangedSourceVariant);
assertNotNull(unchangedRemoteVariant);
IResourceVariant removedSourceVariant = sourceVariantTree.getResourceVariant(iRemovedFile);
IResourceVariant removedRemoteVariant = remoteVariantTree.getResourceVariant(iRemovedFile);
assertNotNull(removedSourceVariant);
assertNull(removedRemoteVariant);
GitSubscriberResourceMappingContext context = new GitSubscriberResourceMappingContext(subscriber, gitSynchDataSet);
assertFalse(context.hasLocalChange(iUnchangedFile, new NullProgressMonitor()));
assertFalse(context.hasRemoteChange(iUnchangedFile, new NullProgressMonitor()));
assertFalse(context.hasLocalChange(iModifiedFile, new NullProgressMonitor()));
assertTrue(context.hasRemoteChange(iModifiedFile, new NullProgressMonitor()));
assertFalse(context.hasLocalChange(iRemovedFile, new NullProgressMonitor()));
assertTrue(context.hasRemoteChange(iRemovedFile, new NullProgressMonitor()));
}
Aggregations