diff options
author | Robin Stocker <robin@nibor.org> | 2012-09-23 01:57:20 +0200 |
---|---|---|
committer | Chris Aniszczyk <zx@twitter.com> | 2012-11-16 10:31:32 -0800 |
commit | cdaded26b0711bfd99cc2990db25b4562540c3b5 (patch) | |
tree | e036b301f6d625f19115c6602fbec7adf7d19740 /org.eclipse.jgit.test | |
parent | 20c829838ac101cf595ee9d4575d6b95a6d2c99d (diff) | |
download | jgit-cdaded26b0711bfd99cc2990db25b4562540c3b5.tar.gz jgit-cdaded26b0711bfd99cc2990db25b4562540c3b5.zip |
CheckoutCommand: Support checking out ours and theirs
The checkoutPaths body is split into two implementations, depending on
whether we are checking out the index or a branch. This improves
readability, as in the index case we now also need to have access to
DirCacheIterator.
Bug: 390147
Change-Id: I99fd599b25b2ace9bdd84535a56565286a3cb7f1
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java index d37f57293d..43b632d2c8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java @@ -47,6 +47,7 @@ import static org.junit.Assert.assertEquals; import java.io.File; import java.io.IOException; +import org.eclipse.jgit.api.CheckoutCommand.Stage; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEntry; @@ -246,10 +247,41 @@ public class PathCheckoutCommandTest extends RepositoryTestCase { assertEquals("a", read(test2)); } + @Test(expected = JGitInternalException.class) public void testCheckoutOfConflictingFileShouldThrow() throws Exception { - // Setup + setupConflictingState(); + + git.checkout().addPath(FILE1).call(); + } + + @Test + public void testCheckoutOurs() throws Exception { + setupConflictingState(); + + git.checkout().setStage(Stage.OURS).addPath(FILE1).call(); + + assertEquals("3", read(FILE1)); + assertStageOneToThree(FILE1); + } + + @Test + public void testCheckoutTheirs() throws Exception { + setupConflictingState(); + + git.checkout().setStage(Stage.THEIRS).addPath(FILE1).call(); + + assertEquals("Conflicting", read(FILE1)); + assertStageOneToThree(FILE1); + } + + @Test(expected = IllegalStateException.class) + public void testStageNotPossibleWithBranch() throws Exception { + git.checkout().setStage(Stage.OURS).setStartPoint("master").call(); + } + + private void setupConflictingState() throws Exception { git.checkout().setCreateBranch(true).setName("conflict") .setStartPoint(initialCommit).call(); writeTrashFile(FILE1, "Conflicting"); @@ -260,8 +292,18 @@ public class PathCheckoutCommandTest extends RepositoryTestCase { git.merge().include(conflict).call(); assertEquals(RepositoryState.MERGING, db.getRepositoryState()); + assertStageOneToThree(FILE1); + } - // Now check out the conflicting path - git.checkout().addPath(FILE1).call(); + private void assertStageOneToThree(String name) throws Exception { + DirCache cache = DirCache.read(db.getIndexFile(), db.getFS()); + int i = cache.findEntry(name); + DirCacheEntry stage1 = cache.getEntry(i); + DirCacheEntry stage2 = cache.getEntry(i + 1); + DirCacheEntry stage3 = cache.getEntry(i + 2); + + assertEquals(DirCacheEntry.STAGE_1, stage1.getStage()); + assertEquals(DirCacheEntry.STAGE_2, stage2.getStage()); + assertEquals(DirCacheEntry.STAGE_3, stage3.getStage()); } } |