Search in sources :

Example 1 with IMergeContext

use of org.eclipse.team.core.mapping.IMergeContext in project egit by eclipse.

the class GitSubscriberMergeContextTest method mergeWithConflict.

@Test
public void mergeWithConflict() throws Exception {
    String fileName = "src/Main.java";
    File file = testRepo.createFile(iProject, fileName);
    final String initialContent = "class Main {}\n";
    testRepo.appendContentAndCommit(iProject, file, initialContent, "some file");
    testRepo.addToIndex(iProject.getFile(".classpath"));
    testRepo.addToIndex(iProject.getFile(".project"));
    testRepo.commit("project files");
    IFile workspaceFile = testRepo.getIFile(iProject, file);
    String repoRelativePath = testRepo.getRepoRelativePath(workspaceFile.getLocation().toPortableString());
    testRepo.createAndCheckoutBranch(MASTER, BRANCH);
    final String branchChanges = "branch changes\n";
    setContentsAndCommit(testRepo, workspaceFile, initialContent + branchChanges, "branch commit");
    testRepo.checkoutBranch(MASTER);
    final String masterChanges = "some changes\n";
    setContentsAndCommit(testRepo, workspaceFile, initialContent + masterChanges, "master commit");
    iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    // end setup
    IMergeContext mergeContext = prepareContext(repo, workspaceFile, MASTER, BRANCH);
    IDiff node = mergeContext.getDiffTree().getDiff(workspaceFile);
    assertNotNull(node);
    IStatus mergeStatus = mergeContext.merge(node, false, new NullProgressMonitor());
    assertEquals(IStatus.ERROR, mergeStatus.getSeverity());
    assertContentEquals(workspaceFile, initialContent + masterChanges);
    Status status = status(repo);
    assertEquals(0, status.getChanged().size());
    assertEquals(0, status.getModified().size());
    assertFalse(status.getChanged().contains(repoRelativePath));
}
Also used : Status(org.eclipse.jgit.api.Status) IStatus(org.eclipse.core.runtime.IStatus) IMergeStatus(org.eclipse.team.core.mapping.IMergeStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IMergeContext(org.eclipse.team.core.mapping.IMergeContext) IDiff(org.eclipse.team.core.diff.IDiff) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 2 with IMergeContext

use of org.eclipse.team.core.mapping.IMergeContext in project egit by eclipse.

the class GitSubscriberMergeContextTest method mergeNoConflict.

@Test
public void mergeNoConflict() throws Exception {
    String fileName = "src/Main.java";
    File file = testRepo.createFile(iProject, fileName);
    final String initialContent = "class Main {}\n";
    testRepo.appendContentAndCommit(iProject, file, initialContent, "some file");
    testRepo.addToIndex(iProject.getFile(".classpath"));
    testRepo.addToIndex(iProject.getFile(".project"));
    testRepo.commit("project files");
    IFile workspaceFile = testRepo.getIFile(iProject, file);
    String repoRelativePath = testRepo.getRepoRelativePath(workspaceFile.getLocation().toPortableString());
    testRepo.createAndCheckoutBranch(MASTER, BRANCH);
    final String branchChanges = "branch changes\n";
    setContentsAndCommit(testRepo, workspaceFile, branchChanges + initialContent, "branch commit");
    testRepo.checkoutBranch(MASTER);
    final String masterChanges = "some changes\n";
    setContentsAndCommit(testRepo, workspaceFile, initialContent + masterChanges, "master commit");
    iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    // end setup
    IMergeContext mergeContext = prepareContext(repo, workspaceFile, MASTER, BRANCH);
    IDiff node = mergeContext.getDiffTree().getDiff(workspaceFile);
    assertNotNull(node);
    IStatus mergeStatus = mergeContext.merge(node, false, new NullProgressMonitor());
    assertEquals(IStatus.OK, mergeStatus.getSeverity());
    assertContentEquals(workspaceFile, branchChanges + initialContent + masterChanges);
    Status status = status(repo);
    assertEquals(1, status.getChanged().size());
    assertEquals(0, status.getModified().size());
    assertTrue(status.getChanged().contains(repoRelativePath));
}
Also used : Status(org.eclipse.jgit.api.Status) IStatus(org.eclipse.core.runtime.IStatus) IMergeStatus(org.eclipse.team.core.mapping.IMergeStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IMergeContext(org.eclipse.team.core.mapping.IMergeContext) IDiff(org.eclipse.team.core.diff.IDiff) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 3 with IMergeContext

use of org.eclipse.team.core.mapping.IMergeContext 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));
}
Also used : Status(org.eclipse.jgit.api.Status) IStatus(org.eclipse.core.runtime.IStatus) IMergeStatus(org.eclipse.team.core.mapping.IMergeStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IMergeContext(org.eclipse.team.core.mapping.IMergeContext) IDiff(org.eclipse.team.core.diff.IDiff) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResourceMappingMerger(org.eclipse.team.core.mapping.IResourceMappingMerger) Test(org.junit.Test)

Example 4 with IMergeContext

use of org.eclipse.team.core.mapping.IMergeContext in project egit by eclipse.

the class GitSubscriberMergeContextTest method markAsMerged.

@Test
public void markAsMerged() throws Exception {
    String fileName = "src/Main.java";
    File file = testRepo.createFile(iProject, fileName);
    testRepo.appendContentAndCommit(iProject, file, "class Main {}", "some file");
    testRepo.addToIndex(iProject.getFile(".classpath"));
    testRepo.addToIndex(iProject.getFile(".project"));
    testRepo.commit("project files");
    IFile workspaceFile = testRepo.getIFile(iProject, file);
    testRepo.appendFileContent(file, "some changes");
    Status status = status(repo);
    assertEquals(0, status.getAdded().size());
    assertEquals(1, status.getModified().size());
    String repoRelativePath = testRepo.getRepoRelativePath(workspaceFile.getLocation().toPortableString());
    assertTrue(status.getModified().contains(repoRelativePath));
    iProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    IMergeContext mergeContext = prepareContext(repo, workspaceFile, HEAD, HEAD);
    IDiff node = mergeContext.getDiffTree().getDiff(workspaceFile);
    assertNotNull(node);
    // First of all, "markAsMerged" is not supposed to have any effect on a
    // folder.
    // Second, it should only be used on IDiff obtained from the context,
    // not created for the occasion.
    mergeContext.markAsMerged(node, true, null);
    status = status(repo);
    assertEquals(1, status.getChanged().size());
    assertEquals(0, status.getModified().size());
    assertTrue(status.getChanged().contains(repoRelativePath));
}
Also used : Status(org.eclipse.jgit.api.Status) IStatus(org.eclipse.core.runtime.IStatus) IMergeStatus(org.eclipse.team.core.mapping.IMergeStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IMergeContext(org.eclipse.team.core.mapping.IMergeContext) IDiff(org.eclipse.team.core.diff.IDiff) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 5 with IMergeContext

use of org.eclipse.team.core.mapping.IMergeContext 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());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SampleResourceMapping(org.eclipse.egit.core.test.models.SampleResourceMapping) Status(org.eclipse.jgit.api.Status) IStatus(org.eclipse.core.runtime.IStatus) IMergeStatus(org.eclipse.team.core.mapping.IMergeStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IMergeStatus(org.eclipse.team.core.mapping.IMergeStatus) IMergeContext(org.eclipse.team.core.mapping.IMergeContext) IDiff(org.eclipse.team.core.diff.IDiff) IResourceMappingMerger(org.eclipse.team.core.mapping.IResourceMappingMerger) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) SampleResourceMapping(org.eclipse.egit.core.test.models.SampleResourceMapping) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)6 IFile (org.eclipse.core.resources.IFile)6 IStatus (org.eclipse.core.runtime.IStatus)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 Status (org.eclipse.jgit.api.Status)6 IDiff (org.eclipse.team.core.diff.IDiff)6 IMergeContext (org.eclipse.team.core.mapping.IMergeContext)6 IMergeStatus (org.eclipse.team.core.mapping.IMergeStatus)6 Test (org.junit.Test)6 IResourceMappingMerger (org.eclipse.team.core.mapping.IResourceMappingMerger)3 LinkedHashSet (java.util.LinkedHashSet)1 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 SampleResourceMapping (org.eclipse.egit.core.test.models.SampleResourceMapping)1