From 8e19fea1a9fb222d09b3fc32b1c71c86ff07e7cd Mon Sep 17 00:00:00 2001 From: Robin Stocker Date: Sun, 17 Aug 2014 17:39:02 +1000 Subject: [PATCH] Add tests for checking out tags with CheckoutCommand Change-Id: Ifec3ac59264c91e154b832fdd907736faf8a8412 Signed-off-by: Robin Stocker --- .../eclipse/jgit/api/CheckoutCommandTest.java | 32 +++++++++++++++++-- 1 file 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 8487f880f..f13fb2026 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 @@ -206,6 +206,28 @@ public class CheckoutCommandTest extends RepositoryTestCase { assertEquals(initialCommit.name(), git.getRepository().getFullBranch()); } + @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());