Browse Source

Add tests for more coverage of CheckoutCommand

Change-Id: Id3ab5f56f88d7e9636c71b30258c268a75fc422e
Signed-off-by: Robin Stocker <robin@nibor.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-2.1
Robin Stocker 12 years ago committed by Matthias Sohn
parent
commit
11533f5d1d
  1. 65
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java

65
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java

@ -43,6 +43,8 @@
*/ */
package org.eclipse.jgit.api; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -234,6 +236,69 @@ public class CheckoutCommandTest extends RepositoryTestCase {
assertTrue(a.exists()); 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 @Test
public void testDetachedHeadOnCheckout() throws JGitInternalException, public void testDetachedHeadOnCheckout() throws JGitInternalException,
IOException, GitAPIException { IOException, GitAPIException {

Loading…
Cancel
Save