Browse Source

Add tests for checking out tags with CheckoutCommand

Change-Id: Ifec3ac59264c91e154b832fdd907736faf8a8412
Signed-off-by: Robin Stocker <robin@nibor.org>
stable-3.5
Robin Stocker 10 years ago committed by Chris Aniszczyk
parent
commit
8e19fea1a9
  1. 32
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java

32
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()); 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 @Test
public void testCheckoutRemoteTrackingWithUpstream() throws Exception { public void testCheckoutRemoteTrackingWithUpstream() throws Exception {
Repository db2 = createRepositoryWithRemote(); Repository db2 = createRepositoryWithRemote();
@ -326,9 +348,7 @@ public class CheckoutCommandTest extends RepositoryTestCase {
co = git.checkout(); co = git.checkout();
co.setName(commitId).call(); co.setName(commitId).call();
Ref head = db.getRef(Constants.HEAD); assertHeadDetached();
assertFalse(head.isSymbolic());
assertSame(head, head.getTarget());
} }
@Test @Test
@ -421,6 +441,12 @@ public class CheckoutCommandTest extends RepositoryTestCase {
assertNull(db.resolve("HEAD")); 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 { private void assertRepositoryCondition(int files) throws GitAPIException {
org.eclipse.jgit.api.Status status = this.git.status().call(); org.eclipse.jgit.api.Status status = this.git.status().call();
assertFalse(status.isClean()); assertFalse(status.isClean());

Loading…
Cancel
Save