use of org.eclipse.team.core.mapping.IResourceMappingMerger in project egit by eclipse.
the class GitSubscriberMergeContextTest method mergeModelNoConflict.
@Test
public void mergeModelNoConflict() throws Exception {
File file1 = testRepo.createFile(iProject, "file1." + SAMPLE_FILE_EXTENSION);
File file2 = testRepo.createFile(iProject, "file2." + SAMPLE_FILE_EXTENSION);
String initialContent1 = "some content for the first file";
String initialContent2 = "some content for the second file";
testRepo.appendContentAndCommit(iProject, file1, initialContent1, "first file - initial commit");
testRepo.appendContentAndCommit(iProject, file2, initialContent2, "second file - initial commit");
IFile iFile1 = testRepo.getIFile(iProject, file1);
IFile iFile2 = testRepo.getIFile(iProject, file2);
String repoRelativePath1 = testRepo.getRepoRelativePath(iFile1.getLocation().toPortableString());
String repoRelativePath2 = testRepo.getRepoRelativePath(iFile2.getLocation().toPortableString());
testRepo.createAndCheckoutBranch(MASTER, BRANCH);
final String branchChanges = "branch changes\n";
setContentsAndCommit(testRepo, iFile1, branchChanges + initialContent1, "branch commit");
setContentsAndCommit(testRepo, iFile2, branchChanges + initialContent2, "branch commit");
testRepo.checkoutBranch(MASTER);
final String masterChanges = "some changes\n";
setContentsAndCommit(testRepo, iFile1, initialContent1 + masterChanges, "master commit");
setContentsAndCommit(testRepo, iFile2, initialContent2 + masterChanges, "master commit");
iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
// end setup
IMergeContext mergeContext = prepareModelContext(repo, iFile1, MASTER, BRANCH);
IDiff node = mergeContext.getDiffTree().getDiff(iFile1);
assertNotNull(node);
node = mergeContext.getDiffTree().getDiff(iFile2);
assertNotNull(node);
IResourceMappingMerger merger = createMerger();
IStatus mergeStatus = merger.merge(mergeContext, new NullProgressMonitor());
assertEquals(IStatus.OK, mergeStatus.getSeverity());
assertContentEquals(iFile1, branchChanges + initialContent1 + masterChanges);
assertContentEquals(iFile2, branchChanges + initialContent2 + masterChanges);
Status status = status(repo);
assertEquals(2, status.getChanged().size());
assertEquals(0, status.getModified().size());
assertTrue(status.getChanged().contains(repoRelativePath1));
assertTrue(status.getChanged().contains(repoRelativePath2));
}
use of org.eclipse.team.core.mapping.IResourceMappingMerger in project egit by eclipse.
the class GitSubscriberMergeContextTest method mergeModelWithConflict.
@Test
public void mergeModelWithConflict() throws Exception {
File file1 = testRepo.createFile(iProject, "file1." + SAMPLE_FILE_EXTENSION);
File file2 = testRepo.createFile(iProject, "file2." + SAMPLE_FILE_EXTENSION);
String initialContent1 = "some content for the first file";
String initialContent2 = "some content for the second file";
testRepo.appendContentAndCommit(iProject, file1, initialContent1, "first file - initial commit");
testRepo.appendContentAndCommit(iProject, file2, initialContent2, "second file - initial commit");
IFile iFile1 = testRepo.getIFile(iProject, file1);
IFile iFile2 = testRepo.getIFile(iProject, file2);
testRepo.createAndCheckoutBranch(MASTER, BRANCH);
final String branchChanges = "branch changes\n";
setContentsAndCommit(testRepo, iFile1, initialContent1 + branchChanges, "branch commit");
setContentsAndCommit(testRepo, iFile2, initialContent2 + branchChanges, "branch commit");
testRepo.checkoutBranch(MASTER);
final String masterChanges = "some changes\n";
setContentsAndCommit(testRepo, iFile1, initialContent1 + masterChanges, "master commit");
setContentsAndCommit(testRepo, iFile2, initialContent2 + masterChanges, "master commit");
iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
// end setup
IMergeContext mergeContext = prepareModelContext(repo, iFile1, MASTER, BRANCH);
IDiff node = mergeContext.getDiffTree().getDiff(iFile1);
assertNotNull(node);
node = mergeContext.getDiffTree().getDiff(iFile2);
assertNotNull(node);
IResourceMappingMerger merger = createMerger();
IStatus mergeStatus = merger.merge(mergeContext, new NullProgressMonitor());
assertEquals(IStatus.ERROR, mergeStatus.getSeverity());
assertTrue(mergeStatus instanceof IMergeStatus);
assertEquals(2, ((IMergeStatus) mergeStatus).getConflictingMappings().length);
Set<IFile> conflictingFiles = new LinkedHashSet<IFile>();
for (ResourceMapping conflictingMapping : ((IMergeStatus) mergeStatus).getConflictingMappings()) {
assertTrue(conflictingMapping instanceof SampleResourceMapping && conflictingMapping.getModelObject() instanceof IFile);
conflictingFiles.add((IFile) conflictingMapping.getModelObject());
}
assertTrue(conflictingFiles.contains(iFile1));
assertTrue(conflictingFiles.contains(iFile2));
assertContentEquals(iFile1, initialContent1 + masterChanges);
assertContentEquals(iFile2, initialContent2 + masterChanges);
Status status = status(repo);
assertEquals(0, status.getChanged().size());
assertEquals(0, status.getModified().size());
}
use of org.eclipse.team.core.mapping.IResourceMappingMerger in project egit by eclipse.
the class GitSubscriberMergeContextTest method mergeModelWithDeletedFileNoConflict.
@Test
public void mergeModelWithDeletedFileNoConflict() throws Exception {
IEclipsePreferences p = InstanceScope.INSTANCE.getNode(Activator.getPluginId());
p.putBoolean(GitCorePreferences.core_autoStageDeletion, true);
File file1 = testRepo.createFile(iProject, "file1." + SAMPLE_FILE_EXTENSION);
File file2 = testRepo.createFile(iProject, "file2." + SAMPLE_FILE_EXTENSION);
String initialContent1 = "some content for the first file";
String initialContent2 = "some content for the second file";
testRepo.appendContentAndCommit(iProject, file1, initialContent1, "first file - initial commit");
testRepo.appendContentAndCommit(iProject, file2, initialContent2, "second file - initial commit");
IFile iFile1 = testRepo.getIFile(iProject, file1);
IFile iFile2 = testRepo.getIFile(iProject, file2);
String repoRelativePath1 = testRepo.getRepoRelativePath(iFile1.getLocation().toPortableString());
String repoRelativePath2 = testRepo.getRepoRelativePath(iFile2.getLocation().toPortableString());
testRepo.createAndCheckoutBranch(MASTER, BRANCH);
final String branchChanges = "branch changes\n";
setContentsAndCommit(testRepo, iFile1, branchChanges + initialContent1, "branch commit");
iFile2.delete(true, new NullProgressMonitor());
TestUtils.waitForJobs(500, 5000, null);
assertFalse(iFile2.exists());
testRepo.addAndCommit(iProject, file2, "branch commit - deleted file2." + SAMPLE_FILE_EXTENSION);
testRepo.checkoutBranch(MASTER);
iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
TestUtils.waitForJobs(500, 5000, null);
if (!iFile2.exists()) {
// Debug output to track down sporadically failing test
System.out.println(iFile2 + " is synchronized? " + Boolean.toString(iFile2.isSynchronized(IResource.DEPTH_ZERO)));
System.out.println(TestUtils.dumpThreads());
System.out.println("***** WARNING: IFile reported as not existing");
System.out.println(iProject + " is open? " + Boolean.toString(iProject.isOpen()));
System.out.println(file2.getPath() + " exists? " + Boolean.toString(file2.exists()));
System.out.println(iFile2 + " exists now? " + Boolean.toString(iFile2.exists()));
iFile2 = iProject.getFile(iFile2.getName());
System.out.println(iFile2 + " exists now? " + Boolean.toString(iFile2.exists()));
fail(iFile2 + " reported not to exist");
}
assertTrue(iFile2.exists());
final String masterChanges = "some changes\n";
setContentsAndCommit(testRepo, iFile1, initialContent1 + masterChanges, "master commit");
iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
// end setup
TestUtils.waitForJobs(500, 5000, null);
IMergeContext mergeContext = prepareModelContext(repo, iFile1, MASTER, BRANCH);
IDiff node = mergeContext.getDiffTree().getDiff(iFile1);
assertNotNull(node);
node = mergeContext.getDiffTree().getDiff(iFile2);
assertNotNull(node);
IResourceMappingMerger merger = createMerger();
IStatus mergeStatus = merger.merge(mergeContext, new NullProgressMonitor());
assertEquals(IStatus.OK, mergeStatus.getSeverity());
assertContentEquals(iFile1, branchChanges + initialContent1 + masterChanges);
assertFalse(iFile2.exists());
Status status = status(repo);
assertEquals(1, status.getChanged().size());
assertEquals(1, status.getRemoved().size());
assertEquals(0, status.getModified().size());
assertTrue(status.getChanged().contains(repoRelativePath1));
assertTrue(status.getRemoved().contains(repoRelativePath2));
}
Aggregations