use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class DecoratableResourceMappingTest method testDecorationConflictingOverDirty.
/**
* Tests that if the resource mapping is both conflicting and dirty, that
* the conflicting decoration image is used over the dirty decoration image.
*
* @throws Exception
*/
@Test
public void testDecorationConflictingOverDirty() throws Exception {
// commit changes on master
gitAdd(git, rmContentA);
gitAdd(git, rmContentB);
RevCommit masterCommit = gitCommit(git);
// add change on new branch first_topic
git.checkout().setCreateBranch(true).setName("first_topic").call();
rmContentA = findFile(project, RM_CONTENT_A_FILE_NAME);
write(rmContentA.getLocation().toFile(), "First Topic Content");
project.refreshLocal(IResource.DEPTH_INFINITE, null);
gitAdd(git, rmContentA);
RevCommit firstTopicCommit = gitCommit(git);
// add change on new branch second_topic
git.checkout().setCreateBranch(true).setStartPoint(masterCommit).setName("second_topic").call();
rmContentA = findFile(project, RM_CONTENT_A_FILE_NAME);
write(rmContentA.getLocation().toFile(), "Second Topic Content");
project.refreshLocal(IResource.DEPTH_INFINITE, null);
gitAdd(git, rmContentA);
gitCommit(git);
// modify b to make it dirty
write(rmContentB.getLocation().toFile(), "Changed content");
// merge second_topic with first_topic
MergeResult mergeResult = git.merge().include(firstTopicCommit).call();
assertEquals(MergeStatus.CONFLICTING, mergeResult.getMergeStatus());
IDecoratableResource[] expectedDRs = new IDecoratableResource[] { newExpectedDecoratableResource(rmContentA).tracked().conflicts(), newExpectedDecoratableResource(rmContentB).tracked().dirty(), newExpectedDecoratableResourceMapping().tracked().dirty().conflicts() };
IndexDiffData indexDiffData = waitForIndexDiff(true);
IDecoratableResource[] actualDRs = { newDecoratableResource(indexDiffData, rmContentA), newDecoratableResource(indexDiffData, rmContentB), newDecoratableResourceMapping(resourceMapping) };
assertArrayEquals(expectedDRs, actualDRs);
assertDecorationConflicts(resourceMapping);
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class DecoratableWorkingSetTest method testAnyTrackedIsTracked.
@Test
public void testAnyTrackedIsTracked() throws Exception {
IDecoratableResource[] expectedDRs = new IDecoratableResource[] { newExpectedDecoratableResource(project1).tracked(), newExpectedDecoratableResource(project2), newExpectedDecoratableWorkingSet(WORKING_SET).tracked() };
IndexDiffData indexDiffData = waitForIndexDiff(true);
IDecoratableResource[] actualDRs = { newDecoratableResource(indexDiffData, project1), newDecoratableResource(indexDiffData, project2), newDecoratableWorkingSet(resourceMapping) };
assertArrayEquals(expectedDRs, actualDRs);
assertDecorationTracked(resourceMapping);
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class DecoratableWorkingSetTest method testDecorationConflictingOverDirty.
@Test
public void testDecorationConflictingOverDirty() throws Exception {
// Create new file and commit
IFile file = createFile(project1, TEST_FILE, "Something");
IFile file2 = createFile(project1, TEST_FILE2, "Another Something");
gitAdd(git, file);
gitAdd(git, file2);
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);
// modify file2 to make it dirty
write(file2.getLocation().toFile(), "Changed content");
// 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().dirty().conflicts(), newExpectedDecoratableResource(file).tracked().conflicts(), newExpectedDecoratableResource(file2).tracked().dirty(), newExpectedDecoratableWorkingSet(WORKING_SET).tracked().dirty().conflicts() };
IndexDiffData indexDiffData = waitForIndexDiff(true);
IDecoratableResource[] actualDRs = { newDecoratableResource(indexDiffData, project1), newDecoratableResource(indexDiffData, file), newDecoratableResource(indexDiffData, file2), newDecoratableWorkingSet(resourceMapping) };
assertArrayEquals(expectedDRs, actualDRs);
assertHasUnstagedChanges(true, actualDRs);
assertDecorationConflicts(resourceMapping);
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class DecoratableWorkingSetTest method testAnyDirtyIsDirty.
@Test
public void testAnyDirtyIsDirty() throws Exception {
// Create new file and commit
IFile file = createFile(project1, TEST_FILE, "Something");
gitAdd(git, file);
gitCommit(git);
// change file content to make it dirty
write(file.getLocation().toFile(), "Change");
IDecoratableResource[] expectedDRs = new IDecoratableResource[] { newExpectedDecoratableResource(project1).tracked().dirty(), newExpectedDecoratableResource(file).tracked().dirty(), newExpectedDecoratableWorkingSet(WORKING_SET).tracked().dirty() };
waitForIndexDiff(true);
IndexDiffData indexDiffData = indexDiffCacheEntry.getIndexDiff();
IDecoratableResource[] actualDRs = { newDecoratableResource(indexDiffData, project1), newDecoratableResource(indexDiffData, file), newDecoratableWorkingSet(resourceMapping) };
assertArrayEquals(expectedDRs, actualDRs);
assertHasUnstagedChanges(true, actualDRs);
assertDecorationDirty(resourceMapping);
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class GitMoveDeleteHook method deleteFile.
@Override
public boolean deleteFile(final IResourceTree tree, final IFile file, final int updateFlags, final IProgressMonitor monitor) {
if (!org.eclipse.egit.core.Activator.autoStageDeletion()) {
return false;
}
// Linked resources are not files, hence not tracked by git
if (file.isLinked())
return false;
final boolean force = (updateFlags & IResource.FORCE) == IResource.FORCE;
if (!force && !tree.isSynchronized(file, IResource.DEPTH_ZERO))
return false;
final RepositoryMapping map = RepositoryMapping.getMapping(file);
if (map == null)
return false;
String repoRelativePath = map.getRepoRelativePath(file);
IndexDiffCache indexDiffCache = Activator.getDefault().getIndexDiffCache();
IndexDiffCacheEntry indexDiffCacheEntry = indexDiffCache.getIndexDiffCacheEntry(map.getRepository());
if (indexDiffCacheEntry == null) {
return false;
}
IndexDiffData indexDiff = indexDiffCacheEntry.getIndexDiff();
if (indexDiff != null) {
if (indexDiff.getUntracked().contains(repoRelativePath))
return false;
if (indexDiff.getIgnoredNotInIndex().contains(repoRelativePath))
return false;
}
if (!file.exists())
return false;
if (file.isDerived())
return false;
DirCache dirc = null;
try {
dirc = map.getRepository().lockDirCache();
final int first = dirc.findEntry(repoRelativePath);
if (first < 0) {
dirc.unlock();
return false;
}
final DirCacheBuilder edit = dirc.builder();
if (first > 0)
edit.keep(0, first);
final int next = dirc.nextEntry(first);
if (next < dirc.getEntryCount())
edit.keep(next, dirc.getEntryCount() - next);
if (!edit.commit())
tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, null));
tree.standardDeleteFile(file, updateFlags, monitor);
} catch (LockFailedException e) {
// FIXME The index is currently locked. This notably happens during
// rebase operations. auto-staging deletions should be queued... and
// the queued job will have to double-check whether the file has
// truly been deleted or if it was only deleted to be replaced by
// another version.
// This hook only exists to automatically add changes to the index.
// If the index is currently locked, do not accept the
// responsibility of deleting the file, return false to tell the
// workspace it can continue with the standard deletion. The user
// will have to stage the deletion later on _if_ this was truly
// needed, which won't happen for calls triggered by merge
// operations from the merge strategies.
Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.getPluginId(), MessageFormat.format(CoreText.MoveDeleteHook_cannotAutoStageDeletion, file.getLocation())));
return FINISH_FOR_ME;
} catch (IOException e) {
tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, e));
} finally {
if (dirc != null)
dirc.unlock();
}
return true;
}
Aggregations