aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorSasa Zivkov <sasa.zivkov@sap.com>2011-03-25 14:28:56 +0100
committerSasa Zivkov <sasa.zivkov@sap.com>2011-03-25 15:02:49 +0100
commit3a86868c0883d2a564db88bf9ae4a5fe235bb63f (patch)
tree85dc0137dc60870b86e90d2804b273b7c7307411 /org.eclipse.jgit.test
parent55b7bd247ef86c6650c9acc364f426cec38723b5 (diff)
downloadjgit-3a86868c0883d2a564db88bf9ae4a5fe235bb63f.tar.gz
jgit-3a86868c0883d2a564db88bf9ae4a5fe235bb63f.zip
Detaching HEAD when checking out the same commit.
Detaching HEAD didn't work in some corner checkout cases. If, for example, HEAD is symbolic ref to refs/heads/master, refs/heads/master is ref to commit c0ffee... then: checkout c0ffee... would leave the HEAD unchanged. The same symptom occurs when checking out a remote tracking branch or a tag that references the same commit as refs/heads/master. In the above case, the RefUpdate class didn't have enough information to decide if the update needed to detach symbolic ref because it dealt only with new/old objectIDs. Therefore, this fix introduced the RefUpdate.detachingSymbolicRef flag. Bug: 315166 Change-Id: I085c98b77ea8f9104a213978ea0d4ac6fd58f49b Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java17
1 files changed, 17 insertions, 0 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 21fbe0a134..6e9f851793 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
@@ -47,6 +47,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -239,4 +240,20 @@ public class CheckoutCommandTest extends RepositoryTestCase {
fail(e.getMessage());
}
}
+
+ @Test
+ public void testDetachedHeadOnCheckout() throws JGitInternalException,
+ RefAlreadyExistsException, RefNotFoundException,
+ InvalidRefNameException, IOException {
+ CheckoutCommand co = git.checkout();
+ co.setName("master").call();
+
+ String commitId = db.getRef(Constants.MASTER).getObjectId().name();
+ co = git.checkout();
+ co.setName(commitId).call();
+
+ Ref head = db.getRef(Constants.HEAD);
+ assertFalse(head.isSymbolic());
+ assertSame(head, head.getTarget());
+ }
}