Search in sources :

Example 16 with IndexDiffData

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

the class DecoratableWorkingSetTest method testAnyConflictsIsConflicts.

@Test
public void testAnyConflictsIsConflicts() throws Exception {
    // Create new file and commit
    IFile file = createFile(project1, TEST_FILE, "Something");
    gitAdd(git, file);
    RevCommit masterCommit = gitCommit(git);
    // Create and checkout new branch, change file content, add and commit
    // file
    git.checkout().setCreateBranch(true).setName("first_topic").call();
    file = findFile(project1, TEST_FILE);
    write(file.getLocation().toFile(), "First Topic Content");
    project1.refreshLocal(IResource.DEPTH_INFINITE, null);
    gitAdd(git, file);
    RevCommit firstTopicCommit = gitCommit(git);
    // Create and checkout new branch (from master), change file content,
    // add and commit file
    git.checkout().setCreateBranch(true).setStartPoint(masterCommit).setName("second_topic").call();
    file = findFile(project1, TEST_FILE);
    write(file.getLocation().toFile(), "Second Topic Content");
    project1.refreshLocal(IResource.DEPTH_INFINITE, null);
    gitAdd(git, file);
    gitCommit(git);
    // merge second_topic with first_topic
    MergeResult mergeResult = git.merge().include(firstTopicCommit).call();
    assertEquals(MergeStatus.CONFLICTING, mergeResult.getMergeStatus());
    IDecoratableResource[] expectedDRs = new IDecoratableResource[] { newExpectedDecoratableResource(project1).tracked().conflicts(), newExpectedDecoratableResource(file).tracked().conflicts(), newExpectedDecoratableWorkingSet(WORKING_SET).tracked().conflicts() };
    IndexDiffData indexDiffData = waitForIndexDiff(true);
    IDecoratableResource[] actualDRs = { newDecoratableResource(indexDiffData, project1), newDecoratableResource(indexDiffData, file), newDecoratableWorkingSet(resourceMapping) };
    assertArrayEquals(expectedDRs, actualDRs);
    assertHasUnstagedChanges(true, actualDRs);
    assertDecorationConflicts(resourceMapping);
}
Also used : IFile(org.eclipse.core.resources.IFile) MergeResult(org.eclipse.jgit.api.MergeResult) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 17 with IndexDiffData

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

the class IndexDiffCacheTest method testAddingAFile.

@Test
public void testAddingAFile() throws Exception {
    new ConnectProviderOperation(project.project, repository.getDirectory()).execute(null);
    // create first commit containing a dummy file
    testRepository.createInitialCommit("testBranchOperation\n\nfirst commit\n");
    prepareCacheEntry();
    waitForListenerCalled();
    final String fileName = "aFile";
    // This call should trigger an indexDiffChanged event (triggered via
    // resource changed event)
    project.createFile(fileName, "content".getBytes("UTF-8"));
    IndexDiffData indexDiffData = waitForListenerCalled();
    String path = project.project.getFile(fileName).getFullPath().toString().substring(1);
    if (!indexDiffData.getUntracked().contains(path))
        fail("IndexDiffData did not contain aFile as untracked");
    // This call should trigger an indexDiffChanged event
    try (Git git = new Git(repository)) {
        git.add().addFilepattern(path).call();
    }
    IndexDiffData indexDiffData2 = waitForListenerCalled();
    if (indexDiffData2.getUntracked().contains(path))
        fail("IndexDiffData contains aFile as untracked");
    if (!indexDiffData2.getAdded().contains(path))
        fail("IndexDiffData does not contain aFile as added");
}
Also used : Git(org.eclipse.jgit.api.Git) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 18 with IndexDiffData

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

the class IndexDiffCacheTest method testAddAndRemoveGitIgnoreFileToIgnoredDir.

@Test
public void testAddAndRemoveGitIgnoreFileToIgnoredDir() throws Exception {
    testRepository.connect(project.project);
    project.createFile(".gitignore", "ignore\n".getBytes("UTF-8"));
    project.createFolder("sub");
    project.createFile("sub/ignore", new byte[] {});
    testRepository.addToIndex(project.project);
    testRepository.createInitialCommit("testRemoveIgnoredFile\n\nfirst commit\n");
    prepareCacheEntry();
    IndexDiffData data1 = waitForListenerCalled();
    assertThat(data1.getIgnoredNotInIndex(), hasItem("Project-1/sub/ignore"));
    project.createFile("sub/ignored", "Ignored".getBytes("UTF-8"));
    // adding this file will trigger a refresh, so no manual refresh must be
    // required.
    project.createFile("sub/.gitignore", "ignored\n".getBytes("UTF-8"));
    IndexDiffData data2 = waitForListenerCalled();
    assertThat(data2.getIgnoredNotInIndex(), hasItem("Project-1/sub/ignored"));
    // removing must also trigger the listener
    project.getProject().getFile("sub/.gitignore").delete(true, null);
    IndexDiffData data3 = waitForListenerCalled();
    assertThat(data3.getUntracked(), hasItem("Project-1/sub/ignored"));
}
Also used : IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 19 with IndexDiffData

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

the class IndexDiffCacheTest method testRemoveIgnoredFile.

@Test
public void testRemoveIgnoredFile() throws Exception {
    testRepository.connect(project.project);
    project.createFile(".gitignore", "ignore\n".getBytes("UTF-8"));
    project.createFolder("sub");
    IFile file = project.createFile("sub/ignore", new byte[] {});
    testRepository.addToIndex(project.project);
    testRepository.createInitialCommit("testRemoveIgnoredFile\n\nfirst commit\n");
    IndexDiffCacheEntry entry = prepareCacheEntry();
    IndexDiffData data1 = waitForListenerCalled();
    assertThat(data1.getIgnoredNotInIndex(), hasItem("Project-1/sub/ignore"));
    // Must not change anything (ignored path starts with this string, but
    // it's not a prefix path of it)
    project.createFile("sub/ignorenot", new byte[] {});
    IndexDiffData data2 = waitForListenerCalled();
    assertThat(data2.getIgnoredNotInIndex(), hasItem("Project-1/sub/ignore"));
    file.delete(false, null);
    waitForListenerNotCalled();
    // need explicit as ignored file shall not trigger.
    entry.refresh();
    IndexDiffData data3 = waitForListenerCalled();
    assertThat(data3.getIgnoredNotInIndex(), not(hasItem("Project-1/sub/ignore")));
}
Also used : IFile(org.eclipse.core.resources.IFile) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 20 with IndexDiffData

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

the class IndexDiffCacheTest method testAddAndRemoveFileToIgnoredDir.

@Test
public void testAddAndRemoveFileToIgnoredDir() throws Exception {
    testRepository.connect(project.project);
    project.createFile(".gitignore", "sub\n".getBytes("UTF-8"));
    project.createFolder("sub");
    project.createFile("sub/ignore", new byte[] {});
    testRepository.addToIndex(project.project);
    testRepository.createInitialCommit("testRemoveIgnoredFile\n\nfirst commit\n");
    prepareCacheEntry();
    IndexDiffData data1 = waitForListenerCalled();
    assertThat(data1.getIgnoredNotInIndex(), hasItem("Project-1/sub"));
    // creating a file in an ignored directory will not trigger the listener
    project.createFile("sub/ignored", "Ignored".getBytes("UTF-8"));
    waitForListenerNotCalled();
    // removing must also not trigger the listener
    project.getProject().getFile("sub/ignored").delete(true, null);
    waitForListenerNotCalled();
}
Also used : IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) 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