Search in sources :

Example 26 with IndexDiffData

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

the class IndexDiffCacheTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    testRepository = new TestRepository(gitDir);
    repository = testRepository.getRepository();
    listenerCalled = new AtomicBoolean(false);
    indexDiffDataResult = new AtomicReference<>(null);
    indexDiffListener = new IndexDiffChangedListener() {

        @Override
        public void indexDiffChanged(Repository repo, IndexDiffData indexDiffData) {
            listenerCalled.set(true);
            indexDiffDataResult.set(indexDiffData);
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRepository(org.eclipse.egit.core.test.TestRepository) TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) IndexDiffChangedListener(org.eclipse.egit.core.internal.indexdiff.IndexDiffChangedListener) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Before(org.junit.Before)

Example 27 with IndexDiffData

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

the class IndexDiffCacheTest method testAddIgnoredFolder.

@Test
public void testAddIgnoredFolder() throws Exception {
    testRepository.connect(project.project);
    project.createFile(".gitignore", "ignore\n".getBytes("UTF-8"));
    project.createFolder("ignore");
    project.createFile("ignore/file.txt", new byte[] {});
    project.createFolder("sub");
    testRepository.addToIndex(project.project);
    testRepository.createInitialCommit("testAddFileInIgnoredFolder\n\nfirst commit\n");
    prepareCacheEntry();
    IndexDiffData data1 = waitForListenerCalled();
    assertThat(data1.getIgnoredNotInIndex(), hasItem("Project-1/ignore"));
    project.createFolder("sub/ignore");
    IndexDiffData data2 = waitForListenerCalled();
    assertThat(data2.getIgnoredNotInIndex(), hasItem("Project-1/ignore"));
    assertThat(data2.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 data3 = waitForListenerCalled();
    assertThat(data3.getUntracked(), hasItem("Project-1/sub/ignorenot"));
    assertThat(data3.getIgnoredNotInIndex(), hasItem("Project-1/ignore"));
    assertThat(data3.getIgnoredNotInIndex(), hasItem("Project-1/sub/ignore"));
}
Also used : IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 28 with IndexDiffData

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

the class LabelEventJob method decorateResource.

/**
 * Decorates a single resource (i.e. a project).
 *
 * @param resource the resource to decorate
 * @param decoration the decoration
 * @throws CoreException
 */
private void decorateResource(@NonNull IResource resource, IDecoration decoration) throws CoreException {
    if (resource.getType() == IResource.ROOT || !resource.isAccessible()) {
        return;
    }
    IndexDiffData indexDiffData = ResourceStateFactory.getInstance().getIndexDiffDataOrNull(resource);
    if (indexDiffData == null) {
        return;
    }
    IDecoratableResource decoratableResource = null;
    try {
        decoratableResource = new DecoratableResourceAdapter(indexDiffData, resource);
    } catch (IOException e) {
        throw new CoreException(Activator.createErrorStatus(NLS.bind(UIText.Decorator_exceptionMessage, resource), e));
    }
    helper.decorate(decoration, decoratableResource);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData)

Example 29 with IndexDiffData

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

the class DecoratableResourceAdapterTest method testDecorationModifiedFile.

@Test
public void testDecorationModifiedFile() 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("First commit").call();
    // Change file content
    write(f, "SomethingElse");
    IDecoratableResource[] expectedDRs = new IDecoratableResource[] { new TestDecoratableResource(project).tracked().dirty(), new TestDecoratableResource(file).tracked().dirty() };
    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) Test(org.junit.Test)

Example 30 with IndexDiffData

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

the class DecoratableResourceAdapterTest method testDecorationNewFileInOneSubfolder.

@Test
public void testDecorationNewFileInOneSubfolder() throws Exception {
    IFolder folder = project.getFolder(TEST_FOLDER);
    folder.create(true, true, null);
    IFolder subFolder = folder.getFolder(SUB_FOLDER);
    subFolder.create(true, true, null);
    IFolder subFolder2 = folder.getFolder(SUB_FOLDER2);
    subFolder2.create(true, true, null);
    write(new File(subFolder2.getLocation().toFile().getAbsolutePath(), TEST_FILE), "Something");
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    IResource file = subFolder2.findMember(TEST_FILE);
    IDecoratableResource[] expectedDRs = new IDecoratableResource[] { new TestDecoratableResource(project).tracked().dirty(), new TestDecoratableResource(folder).dirty(), new TestDecoratableResource(subFolder).ignored(), new TestDecoratableResource(subFolder2).dirty(), new TestDecoratableResource(file) };
    waitForIndexDiffUpdate(true);
    IndexDiffData indexDiffData = indexDiffCacheEntry.getIndexDiff();
    IDecoratableResource[] actualDRs = { new DecoratableResourceAdapter(indexDiffData, project), new DecoratableResourceAdapter(indexDiffData, folder), new DecoratableResourceAdapter(indexDiffData, subFolder), new DecoratableResourceAdapter(indexDiffData, subFolder2), 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) IFolder(org.eclipse.core.resources.IFolder) 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