Search in sources :

Example 6 with RemoteResourceMappingContext

use of org.eclipse.core.resources.mapping.RemoteResourceMappingContext in project egit by eclipse.

the class GitSubscriberResourceMappingContextTest method hasLocalChangeInNewFolder.

@Test
public void hasLocalChangeInNewFolder() throws Exception {
    iProject.getFolder("folder").create(false, true, null);
    RemoteResourceMappingContext context = prepareContext(MASTER, MASTER);
    // Folder is now known, but not yet file in it
    File file = testRepo.createFile(iProject, "folder/b.txt");
    IFile iFile = testRepo.getIFile(iProject, file);
    refresh(context, iFile);
    assertTrue(context.hasLocalChange(iFile, new NullProgressMonitor()));
    testRepo.addToIndex(iProject, file);
    refresh(context, iFile);
    assertTrue(context.hasLocalChange(iFile, new NullProgressMonitor()));
    JGitTestUtil.write(file, "changed content b");
    refresh(context, iFile);
    assertTrue(context.hasLocalChange(iFile, new NullProgressMonitor()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 7 with RemoteResourceMappingContext

use of org.eclipse.core.resources.mapping.RemoteResourceMappingContext in project egit by eclipse.

the class GitSubscriberResourceMappingContextTest method hasLocalAndRemoteChange.

@Test
public void hasLocalAndRemoteChange() throws Exception {
    File file1 = testRepo.createFile(iProject, "file1.sample");
    testRepo.appendContentAndCommit(iProject, file1, "initial content", "first commit in master");
    IFile iFile1 = testRepo.getIFile(iProject, file1);
    testRepo.createAndCheckoutBranch(MASTER, BRANCH);
    setContentsAndCommit(iFile1, "changed content in branch", "first commit in BRANCH");
    testRepo.checkoutBranch(MASTER);
    setContentsAndCommit(iFile1, "changed content in master", "second commit in MASTER");
    RemoteResourceMappingContext context = prepareContext(MASTER, BRANCH);
    assertTrue(context.hasRemoteChange(iFile1, new NullProgressMonitor()));
    assertTrue(context.hasLocalChange(iFile1, new NullProgressMonitor()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 8 with RemoteResourceMappingContext

use of org.eclipse.core.resources.mapping.RemoteResourceMappingContext in project egit by eclipse.

the class GitSubscriberResourceMappingContextTest method hasLocalChange.

@Test
public void hasLocalChange() throws Exception {
    File file1 = testRepo.createFile(iProject, "a.txt");
    File file2 = testRepo.createFile(iProject, "b.txt");
    testRepo.appendContentAndCommit(iProject, file1, "content a", "commit a");
    testRepo.appendContentAndCommit(iProject, file2, "content b", "commit b");
    IFile iFile1 = testRepo.getIFile(iProject, file1);
    IFile iFile2 = testRepo.getIFile(iProject, file2);
    RemoteResourceMappingContext context = prepareContext(MASTER, MASTER);
    assertFalse(context.hasLocalChange(iFile1, new NullProgressMonitor()));
    assertFalse(context.hasLocalChange(iFile2, new NullProgressMonitor()));
    JGitTestUtil.write(file1, "changed content a");
    JGitTestUtil.write(file2, "changed content b");
    refresh(context, iFile1, iFile2);
    assertTrue(context.hasLocalChange(iFile1, new NullProgressMonitor()));
    assertTrue(context.hasLocalChange(iFile2, new NullProgressMonitor()));
    JGitTestUtil.write(file2, "content b");
    refresh(context, iFile2);
    assertTrue(context.hasLocalChange(iFile1, new NullProgressMonitor()));
    assertFalse(context.hasLocalChange(iFile2, new NullProgressMonitor()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 9 with RemoteResourceMappingContext

use of org.eclipse.core.resources.mapping.RemoteResourceMappingContext in project egit by eclipse.

the class GitSubscriberResourceMappingContextTest method hasRemoteChangeInNewFile.

@Test
public void hasRemoteChangeInNewFile() throws Exception {
    File file1 = testRepo.createFile(iProject, "file1.sample");
    String initialContent1 = "some content for the first file";
    testRepo.appendContentAndCommit(iProject, file1, initialContent1, "first file - initial commit");
    IFile iFile1 = testRepo.getIFile(iProject, file1);
    testRepo.createAndCheckoutBranch(MASTER, BRANCH);
    File file2 = testRepo.createFile(iProject, "file2.sample");
    String initialContent2 = "some content for the second file";
    testRepo.appendContentAndCommit(iProject, file2, initialContent2, "second file - initial commit");
    IFile iFile2 = testRepo.getIFile(iProject, file2);
    testRepo.checkoutBranch(MASTER);
    RemoteResourceMappingContext context = prepareContext(MASTER, BRANCH);
    assertFalse(context.hasRemoteChange(iFile1, new NullProgressMonitor()));
    assertTrue(context.hasRemoteChange(iFile2, new NullProgressMonitor()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 10 with RemoteResourceMappingContext

use of org.eclipse.core.resources.mapping.RemoteResourceMappingContext in project egit by eclipse.

the class GitSubscriberResourceMappingContextTest method hasNestedDeletion.

@Test
public void hasNestedDeletion() throws Exception {
    File file1 = testRepo.createFile(iProject, "sub/subfolder/file1.sample");
    testRepo.appendContentAndCommit(iProject, file1, "initial content", "first commit in master");
    IFile iFile1 = testRepo.getIFile(iProject, file1);
    assertTrue(iFile1.exists());
    IContainer subfolder = iFile1.getParent();
    assertTrue(subfolder instanceof IFolder);
    assertEquals("subfolder", subfolder.getName());
    IContainer sub = subfolder.getParent();
    assertTrue(sub instanceof IFolder);
    assertEquals("sub", sub.getName());
    testRepo.createAndCheckoutBranch(MASTER, BRANCH);
    iFile1.delete(true, new NullProgressMonitor());
    subfolder.delete(true, new NullProgressMonitor());
    sub.delete(true, new NullProgressMonitor());
    try (Git git = new Git(testRepo.getRepository())) {
        git.add().addFilepattern(iProject.getName() + "/sub/subfolder/file1.sample").setUpdate(true).call();
    }
    testRepo.commit("Deleted sub/subfolder/file1.sample");
    assertFalse(iFile1.exists());
    assertFalse(subfolder.exists());
    assertFalse(sub.exists());
    RemoteResourceMappingContext context = prepareContext(BRANCH, MASTER);
    boolean hasFile1 = false;
    for (IResource member : context.fetchMembers(iProject, new NullProgressMonitor())) {
        if (sub.getName().equals(member.getName())) {
            for (IResource child : context.fetchMembers(sub, new NullProgressMonitor())) {
                if (subfolder.getName().equals(child.getName())) {
                    for (IResource grandchild : context.fetchMembers(subfolder, new NullProgressMonitor())) {
                        if (iFile1.getName().equals(grandchild.getName())) {
                            hasFile1 = true;
                            break;
                        }
                    }
                    break;
                }
            }
            break;
        }
    }
    assertTrue(hasFile1);
    assertFalse(context.hasRemoteChange(iFile1, new NullProgressMonitor()));
    assertTrue(context.hasLocalChange(iFile1, new NullProgressMonitor()));
    assertFalse(context.hasLocalChange(subfolder, new NullProgressMonitor()));
    assertFalse(context.hasLocalChange(sub, new NullProgressMonitor()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) Git(org.eclipse.jgit.api.Git) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) IContainer(org.eclipse.core.resources.IContainer) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

RemoteResourceMappingContext (org.eclipse.core.resources.mapping.RemoteResourceMappingContext)13 IFile (org.eclipse.core.resources.IFile)12 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)11 Test (org.junit.Test)11 File (java.io.File)10 IResource (org.eclipse.core.resources.IResource)3 IFolder (org.eclipse.core.resources.IFolder)2 Git (org.eclipse.jgit.api.Git)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 IContainer (org.eclipse.core.resources.IContainer)1 IStorage (org.eclipse.core.resources.IStorage)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 ResourceTraversal (org.eclipse.core.resources.mapping.ResourceTraversal)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1