Search in sources :

Example 31 with IndexDiffData

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.

the class DecoratableResourceAdapterTest method testDecorationAddedFile.

@Test
public void testDecorationAddedFile() throws Exception {
    // Create new file
    write(new File(project.getLocation().toFile(), TEST_FILE), "Something");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    IResource file = project.findMember(TEST_FILE);
    // Add file
    git.add().addFilepattern(".").call();
    IDecoratableResource[] expectedDRs = new IDecoratableResource[] { new TestDecoratableResource(project).tracked().modified(), new TestDecoratableResource(file).tracked().added() };
    waitForIndexDiffUpdate(true);
    IndexDiffData indexDiffData = indexDiffCacheEntry.getIndexDiff();
    IDecoratableResource[] actualDRs = { new DecoratableResourceAdapter(indexDiffData, project), new DecoratableResourceAdapter(indexDiffData, file) };
    assertArrayEquals(expectedDRs, actualDRs);
}
Also used : File(java.io.File) IResource(org.eclipse.core.resources.IResource) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 32 with IndexDiffData

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.

the class DecoratableResourceAdapterTest method testDecorationDeletedFile.

@Test
public void testDecorationDeletedFile() throws Exception {
    // Create new file
    File f = new File(project.getLocation().toFile(), TEST_FILE);
    write(f, "Something");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    // Add and commit file
    git.add().addFilepattern(".").call();
    git.commit().setMessage("First commit").call();
    // Delete file
    FileUtils.delete(f);
    IDecoratableResource expectedDR = new TestDecoratableResource(project).tracked().dirty();
    waitForIndexDiffUpdate(true);
    IndexDiffData indexDiffData = indexDiffCacheEntry.getIndexDiff();
    IDecoratableResource actualDR = new DecoratableResourceAdapter(indexDiffData, project);
    assertEquals(expectedDR, actualDR);
    assertHasUnstagedChanges(true, actualDR);
}
Also used : File(java.io.File) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 33 with IndexDiffData

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.

the class DecoratableResourceAdapterTest method testDecorationCommittedFile.

@Test
public void testDecorationCommittedFile() throws Exception {
    // Create new file
    write(new File(project.getLocation().toFile(), TEST_FILE), "Something");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    IResource file = project.findMember(TEST_FILE);
    // Add and commit file
    git.add().addFilepattern(".").call();
    git.commit().setMessage("First commit").call();
    IDecoratableResource[] expectedDRs = new IDecoratableResource[] { new TestDecoratableResource(project).tracked(), new TestDecoratableResource(file).tracked() };
    waitForIndexDiffUpdate(true);
    IndexDiffData indexDiffData = indexDiffCacheEntry.getIndexDiff();
    IDecoratableResource[] actualDRs = { new DecoratableResourceAdapter(indexDiffData, project), new DecoratableResourceAdapter(indexDiffData, file) };
    assertArrayEquals(expectedDRs, actualDRs);
    assertHasUnstagedChanges(false, actualDRs);
}
Also used : File(java.io.File) IResource(org.eclipse.core.resources.IResource) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 34 with IndexDiffData

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.

the class DecoratableResourceAdapterTest method testDecorationFileInIgnoredFolder.

@Test
public void testDecorationFileInIgnoredFolder() throws Exception {
    // Create new file
    FileUtils.mkdir(new File(project.getLocation().toFile(), "dir"));
    write(new File(project.getLocation().toFile(), "dir/file"), "Something");
    write(new File(project.getLocation().toFile(), ".gitignore"), "dir");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    IResource dir = project.findMember("dir");
    IResource file = project.findMember("dir/file");
    IResource gitignore = project.findMember(".gitignore");
    IDecoratableResource[] expectedDRs = new IDecoratableResource[] { new TestDecoratableResource(project).tracked().dirty(), new TestDecoratableResource(gitignore), new TestDecoratableResource(file).ignored(), new TestDecoratableResource(dir).ignored() };
    waitForIndexDiffUpdate(true);
    IndexDiffData indexDiffData = indexDiffCacheEntry.getIndexDiff();
    IDecoratableResource[] actualDRs = { new DecoratableResourceAdapter(indexDiffData, project), new DecoratableResourceAdapter(indexDiffData, gitignore), new DecoratableResourceAdapter(indexDiffData, file), new DecoratableResourceAdapter(indexDiffData, dir) };
    assertArrayEquals(expectedDRs, actualDRs);
}
Also used : File(java.io.File) IResource(org.eclipse.core.resources.IResource) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 35 with IndexDiffData

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.

the class DecoratableResourceAdapterTest method testDecorationConflictingFile.

@Test
public void testDecorationConflictingFile() throws Exception {
    // Create new file
    File f = new File(project.getLocation().toFile(), TEST_FILE);
    write(f, "Something");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    IResource file = project.findMember(TEST_FILE);
    // Add and commit file
    git.add().addFilepattern(".").call();
    git.commit().setMessage("Commit on master branch").call();
    // Create and checkout new branch, change file content, add and commit
    // file
    git.checkout().setCreateBranch(true).setName("first_topic").call();
    write(f, "SomethingElse");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    git.add().addFilepattern(".").call();
    RevCommit commitOnFirstTopicBranch = git.commit().setMessage("Commit on first topic branch").call();
    // Create and checkout new branch (from master), change file content,
    // add and commit file
    git.checkout().setName("master").call();
    git.checkout().setCreateBranch(true).setName("second_topic").call();
    write(f, "SomethingDifferent");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    git.add().addFilepattern(".").call();
    git.commit().setMessage("Commit on second topic branch").call();
    // Merge HEAD ('Commit on second topic branch') with 'Commit on first
    // topic branch' to create a conflict
    assertTrue(git.merge().include(commitOnFirstTopicBranch).call().getMergeStatus() == MergeStatus.CONFLICTING);
    IDecoratableResource[] expectedDRs = new IDecoratableResource[] { new TestDecoratableResource(project).tracked().conflicts(), new TestDecoratableResource(file).tracked().conflicts() };
    waitForIndexDiffUpdate(true);
    IndexDiffData indexDiffData = indexDiffCacheEntry.getIndexDiff();
    IDecoratableResource[] actualDRs = { new DecoratableResourceAdapter(indexDiffData, project), new DecoratableResourceAdapter(indexDiffData, file) };
    assertArrayEquals(expectedDRs, actualDRs);
    assertHasUnstagedChanges(true, actualDRs);
}
Also used : File(java.io.File) IResource(org.eclipse.core.resources.IResource) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

IndexDiffData (org.eclipse.egit.core.internal.indexdiff.IndexDiffData)47 Test (org.junit.Test)34 IResource (org.eclipse.core.resources.IResource)14 File (java.io.File)11 IFile (org.eclipse.core.resources.IFile)10 IndexDiffCacheEntry (org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 IFolder (org.eclipse.core.resources.IFolder)4 MergeResult (org.eclipse.jgit.api.MergeResult)4 Repository (org.eclipse.jgit.lib.Repository)4 IOException (java.io.IOException)3 CoreException (org.eclipse.core.runtime.CoreException)3 IndexDiffCache (org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IndexDiffChangedListener (org.eclipse.egit.core.internal.indexdiff.IndexDiffChangedListener)2