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();
}
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()));
}
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")));
}
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;
}
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;
}
Aggregations