Search in sources :

Example 6 with IndexDiffCacheEntry

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

the class RepositoryUtil method hasChanges.

/**
 * Determines whether the given {@link Repository} has any changes by
 * checking the {@link IndexDiffCacheEntry} of the repository.
 *
 * @param repository
 *            to check
 * @return {@code true} if the repository has any changes, {@code false}
 *         otherwise
 */
public static boolean hasChanges(@NonNull Repository repository) {
    IndexDiffCacheEntry entry = Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
    IndexDiffData data = entry != null ? entry.getIndexDiff() : null;
    return data != null && data.hasChanges();
}
Also used : IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData)

Example 7 with IndexDiffCacheEntry

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

the class SubmoduleFolderTest method testStageUnstageInSubRepo.

/**
 * Tests AddToIndex and RemoveFromIndex commands on a file from a submodule
 * folder. Verifies the execution of the command by testing the state of the
 * file in the index diff after it has been executed. Additionally verifies
 * that decorations do get updated.
 *
 * @throws Exception
 */
@Test
public void testStageUnstageInSubRepo() throws Exception {
    IFolder childProjectFolder = childFolder.getFolder(CHILDPROJECT);
    IFolder folder = childProjectFolder.getFolder(FOLDER);
    IFile file = folder.getFile(FILE1);
    touch(PROJ1, file.getProjectRelativePath().toOSString(), "Modified");
    TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
    SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
    SWTBotTreeItem node = TestUtil.navigateTo(projectExplorerTree, file.getFullPath().segments());
    TestUtil.waitForDecorations();
    assertTrue(node.getText().startsWith("> " + file.getName()));
    node.select();
    ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Team", util.getPluginLocalizedValue("AddToIndexAction_label"));
    TestUtil.joinJobs(ADD_TO_INDEX);
    TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
    IndexDiffCacheEntry cache = Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(subRepository);
    IResourceState state = ResourceStateFactory.getInstance().get(cache.getIndexDiff(), file);
    assertTrue("File should be staged", state.isStaged());
    TestUtil.waitForDecorations();
    assertFalse(node.getText().startsWith("> "));
    ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Team", util.getPluginLocalizedValue("RemoveFromIndexAction_label"));
    TestUtil.joinJobs(REMOVE_FROM_INDEX);
    TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
    state = ResourceStateFactory.getInstance().get(cache.getIndexDiff(), file);
    assertFalse("File should not be staged", state.isStaged());
    assertTrue("File should be dirty", state.isDirty());
    TestUtil.waitForDecorations();
    assertTrue(node.getText().startsWith("> " + file.getName()));
}
Also used : IResourceState(org.eclipse.egit.ui.internal.resources.IResourceState) IFile(org.eclipse.core.resources.IFile) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 8 with IndexDiffCacheEntry

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry 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 9 with IndexDiffCacheEntry

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

the class IndexDiffCacheTest method prepareCacheEntry.

private IndexDiffCacheEntry prepareCacheEntry() {
    listenerCalled.set(false);
    indexDiffDataResult.set(null);
    IndexDiffCache indexDiffCache = Activator.getDefault().getIndexDiffCache();
    indexDiffCache.addIndexDiffChangedListener(indexDiffListener);
    // This call should trigger an indexDiffChanged event
    IndexDiffCacheEntry cacheEntry = indexDiffCache.getIndexDiffCacheEntry(repository);
    return cacheEntry;
}
Also used : IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)

Example 10 with IndexDiffCacheEntry

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

the class StashCreateHandler method isEnabled.

static boolean isEnabled(Repository repository) {
    if (repository == null)
        return false;
    if (!repository.getRepositoryState().canCommit())
        return false;
    IndexDiffCacheEntry entry = Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
    if (entry == null)
        return false;
    IndexDiffData diff = entry.getIndexDiff();
    if (diff == null)
        return false;
    if (diff.getAdded().isEmpty() && diff.getChanged().isEmpty() && diff.getRemoved().isEmpty() && diff.getUntracked().isEmpty() && diff.getModified().isEmpty() && diff.getMissing().isEmpty())
        return false;
    return true;
}
Also used : IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData)

Aggregations

IndexDiffCacheEntry (org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry)17 IndexDiffCache (org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)8 IndexDiffData (org.eclipse.egit.core.internal.indexdiff.IndexDiffData)8 Repository (org.eclipse.jgit.lib.Repository)5 Collection (java.util.Collection)4 IOException (java.io.IOException)3 IFile (org.eclipse.core.resources.IFile)3 IResource (org.eclipse.core.resources.IResource)3 IPath (org.eclipse.core.runtime.IPath)3 Map (java.util.Map)2 CoreException (org.eclipse.core.runtime.CoreException)2 Path (org.eclipse.core.runtime.Path)2 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1