diff options
author | Robin Stocker <robin@nibor.org> | 2013-03-21 01:39:04 +0100 |
---|---|---|
committer | Chris Aniszczyk <zx@twitter.com> | 2013-04-19 10:05:06 -0500 |
commit | 1080cc5a0d67012c0ef08d9468fbbc9d90b0c238 (patch) | |
tree | 3a79d9f60f2cba1b50b2f7986c88c7c41e792ef7 /org.eclipse.jgit.test/tst | |
parent | 1c40d83f52730379e56b0a95485aad42a52b8e04 (diff) | |
download | jgit-1080cc5a0d67012c0ef08d9468fbbc9d90b0c238.tar.gz jgit-1080cc5a0d67012c0ef08d9468fbbc9d90b0c238.zip |
IndexDiff: Provide stage state for conflicting entries
Adds a new method getConflictingStageStates() which returns a
Map<String, StageState> (path to stage state). StageState is an enum for
all possible stage combinations (BOTH_DELETED, ADDED_BY_US, ...).
This can be used to implement the conflict text for unmerged paths in
output of "git status" or in EGit for decorations/hints.
Bug: 403697
Change-Id: Ib461640a43111b7df4a0debe92ff69b82171329c
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java index 6040dfed78..51ba5f13ea 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java @@ -2,6 +2,7 @@ * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com> * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> + * Copyright (C) 2013, Robin Stocker <robin@nibor.org> * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -46,6 +47,7 @@ package org.eclipse.jgit.lib; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.File; @@ -61,10 +63,12 @@ import org.eclipse.jgit.api.MergeResult; import org.eclipse.jgit.api.MergeResult.MergeStatus; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.dircache.DirCache; +import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit; import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lib.IndexDiff.StageState; import org.eclipse.jgit.merge.MergeStrategy; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.treewalk.FileTreeIterator; @@ -212,6 +216,8 @@ public class IndexDiffTest extends RepositoryTestCase { assertEquals("[]", diff.getMissing().toString()); assertEquals("[]", diff.getModified().toString()); assertEquals("[a]", diff.getConflicting().toString()); + assertEquals(StageState.BOTH_MODIFIED, + diff.getConflictingStageStates().get("a")); assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); } @@ -251,6 +257,8 @@ public class IndexDiffTest extends RepositoryTestCase { assertEquals("[]", diff.getMissing().toString()); assertEquals("[]", diff.getModified().toString()); assertEquals("[a]", diff.getConflicting().toString()); + assertEquals(StageState.DELETED_BY_THEM, + diff.getConflictingStageStates().get("a")); assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); } @@ -500,6 +508,46 @@ public class IndexDiffTest extends RepositoryTestCase { assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); } + @Test + public void testStageState() throws IOException { + final int base = DirCacheEntry.STAGE_1; + final int ours = DirCacheEntry.STAGE_2; + final int theirs = DirCacheEntry.STAGE_3; + verifyStageState(StageState.BOTH_DELETED, base); + verifyStageState(StageState.DELETED_BY_THEM, ours, base); + verifyStageState(StageState.DELETED_BY_US, base, theirs); + verifyStageState(StageState.BOTH_MODIFIED, base, ours, theirs); + verifyStageState(StageState.ADDED_BY_US, ours); + verifyStageState(StageState.BOTH_ADDED, ours, theirs); + verifyStageState(StageState.ADDED_BY_THEM, theirs); + + assertTrue(StageState.BOTH_DELETED.hasBase()); + assertFalse(StageState.BOTH_DELETED.hasOurs()); + assertFalse(StageState.BOTH_DELETED.hasTheirs()); + assertFalse(StageState.BOTH_ADDED.hasBase()); + assertTrue(StageState.BOTH_ADDED.hasOurs()); + assertTrue(StageState.BOTH_ADDED.hasTheirs()); + } + + private void verifyStageState(StageState expected, int... stages) + throws IOException { + DirCacheBuilder builder = db.lockDirCache().builder(); + for (int stage : stages) { + DirCacheEntry entry = createEntry("a", FileMode.REGULAR_FILE, + stage, "content"); + builder.add(entry); + } + builder.commit(); + + IndexDiff diff = new IndexDiff(db, Constants.HEAD, + new FileTreeIterator(db)); + diff.diff(); + + assertEquals( + "Conflict for entries in stages " + Arrays.toString(stages), + expected, diff.getConflictingStageStates().get("a")); + } + private void removeFromIndex(String path) throws IOException { final DirCache dirc = db.lockDirCache(); final DirCacheEditor edit = dirc.editor(); |