Search in sources :

Example 41 with IndexDiffData

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);
}
Also used : 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 42 with IndexDiffData

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);
}
Also used : IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 43 with IndexDiffData

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);
}
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 44 with IndexDiffData

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) Test(org.junit.Test)

Example 45 with IndexDiffData

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DirCache(org.eclipse.jgit.dircache.DirCache) DirCacheBuilder(org.eclipse.jgit.dircache.DirCacheBuilder) LockFailedException(org.eclipse.jgit.errors.LockFailedException) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IOException(java.io.IOException) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData)

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