From 11533f5d1de16496ad44abd70dd8d7fbe176bbbf Mon Sep 17 00:00:00 2001 From: Robin Stocker Date: Mon, 3 Sep 2012 08:44:28 +0200 Subject: [PATCH] Add tests for more coverage of CheckoutCommand Change-Id: Id3ab5f56f88d7e9636c71b30258c268a75fc422e Signed-off-by: Robin Stocker Signed-off-by: Matthias Sohn --- .../eclipse/jgit/api/CheckoutCommandTest.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java index dc9303aec..b75d0bdc4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java @@ -43,6 +43,8 @@ */ package org.eclipse.jgit.api; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -234,6 +236,69 @@ public class CheckoutCommandTest extends RepositoryTestCase { assertTrue(a.exists()); } + @Test + public void testCheckoutOfDirectoryShouldBeRecursive() throws Exception { + File a = writeTrashFile("dir/a.txt", "A"); + File b = writeTrashFile("dir/sub/b.txt", "B"); + git.add().addFilepattern("dir").call(); + git.commit().setMessage("Added dir").call(); + + write(a, "modified"); + write(b, "modified"); + git.checkout().addPath("dir").call(); + + assertThat(read(a), is("A")); + assertThat(read(b), is("B")); + } + + @Test + public void testCheckoutAllPaths() throws Exception { + File a = writeTrashFile("dir/a.txt", "A"); + File b = writeTrashFile("dir/sub/b.txt", "B"); + git.add().addFilepattern("dir").call(); + git.commit().setMessage("Added dir").call(); + + write(a, "modified"); + write(b, "modified"); + git.checkout().setAllPaths(true).call(); + + assertThat(read(a), is("A")); + assertThat(read(b), is("B")); + } + + @Test + public void testCheckoutWithStartPoint() throws Exception { + File a = writeTrashFile("a.txt", "A"); + git.add().addFilepattern("a.txt").call(); + RevCommit first = git.commit().setMessage("Added a").call(); + + write(a, "other"); + git.commit().setAll(true).setMessage("Other").call(); + + git.checkout().setCreateBranch(true).setName("a") + .setStartPoint(first.getId().getName()).call(); + + assertThat(read(a), is("A")); + } + + @Test + public void testCheckoutWithStartPointOnlyCertainFiles() throws Exception { + File a = writeTrashFile("a.txt", "A"); + File b = writeTrashFile("b.txt", "B"); + git.add().addFilepattern("a.txt").addFilepattern("b.txt").call(); + RevCommit first = git.commit().setMessage("First").call(); + + write(a, "other"); + write(b, "other"); + git.commit().setAll(true).setMessage("Other").call(); + + git.checkout().setCreateBranch(true).setName("a") + .setStartPoint(first.getId().getName()).addPath("a.txt").call(); + + assertThat(read(a), is("A")); + assertThat(read(b), is("other")); + } + @Test public void testDetachedHeadOnCheckout() throws JGitInternalException, IOException, GitAPIException {