]> source.dussan.org Git - jgit.git/commitdiff
Add tests for more coverage of CheckoutCommand 00/7200/2
authorRobin Stocker <robin@nibor.org>
Mon, 3 Sep 2012 06:44:28 +0000 (08:44 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 3 Sep 2012 06:44:28 +0000 (08:44 +0200)
Change-Id: Id3ab5f56f88d7e9636c71b30258c268a75fc422e
Signed-off-by: Robin Stocker <robin@nibor.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java

index dc9303aecf7a7547ba7076e2bdd663797c407179..b75d0bdc4ccae82584e38d878a88127531e2d2ac 100644 (file)
@@ -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 {