diff options
author | Robin Stocker <robin@nibor.org> | 2014-08-17 17:39:02 +1000 |
---|---|---|
committer | Chris Aniszczyk <caniszczyk@gmail.com> | 2014-08-17 19:12:04 -0400 |
commit | 8e19fea1a9fb222d09b3fc32b1c71c86ff07e7cd (patch) | |
tree | a78dee3c3bae04b6b7f64216053cec5a9e87f0ca | |
parent | 4bdd0037aa3ca8ca7c3996510e9ea292526c6a29 (diff) | |
download | jgit-8e19fea1a9fb222d09b3fc32b1c71c86ff07e7cd.tar.gz jgit-8e19fea1a9fb222d09b3fc32b1c71c86ff07e7cd.zip |
Add tests for checking out tags with CheckoutCommand
Change-Id: Ifec3ac59264c91e154b832fdd907736faf8a8412
Signed-off-by: Robin Stocker <robin@nibor.org>
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java | 32 |
1 files changed, 29 insertions, 3 deletions
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 8487f880f1..f13fb20261 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 @@ -207,6 +207,28 @@ public class CheckoutCommandTest extends RepositoryTestCase { } @Test + public void testCheckoutLightweightTag() throws Exception { + git.tag().setAnnotated(false).setName("test-tag") + .setObjectId(initialCommit).call(); + Ref result = git.checkout().setName("test-tag").call(); + + assertNull(result); + assertEquals(initialCommit.getId(), db.resolve(Constants.HEAD)); + assertHeadDetached(); + } + + @Test + public void testCheckoutAnnotatedTag() throws Exception { + git.tag().setAnnotated(true).setName("test-tag") + .setObjectId(initialCommit).call(); + Ref result = git.checkout().setName("test-tag").call(); + + assertNull(result); + assertEquals(initialCommit.getId(), db.resolve(Constants.HEAD)); + assertHeadDetached(); + } + + @Test public void testCheckoutRemoteTrackingWithUpstream() throws Exception { Repository db2 = createRepositoryWithRemote(); @@ -326,9 +348,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { co = git.checkout(); co.setName(commitId).call(); - Ref head = db.getRef(Constants.HEAD); - assertFalse(head.isSymbolic()); - assertSame(head, head.getTarget()); + assertHeadDetached(); } @Test @@ -421,6 +441,12 @@ public class CheckoutCommandTest extends RepositoryTestCase { assertNull(db.resolve("HEAD")); } + private void assertHeadDetached() throws IOException { + Ref head = db.getRef(Constants.HEAD); + assertFalse(head.isSymbolic()); + assertSame(head, head.getTarget()); + } + private void assertRepositoryCondition(int files) throws GitAPIException { org.eclipse.jgit.api.Status status = this.git.status().call(); assertFalse(status.isClean()); |