aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
diff options
context:
space:
mode:
authorMathias Kinzler <mathias.kinzler@sap.com>2010-12-20 10:35:10 +0100
committerChris Aniszczyk <caniszczyk@gmail.com>2010-12-20 09:30:40 -0600
commit89a4dcf71ff3326aa6313b3a988b7721c3470858 (patch)
treea5286f9b13d5d634f9bf2704f6a1996444a807c1 /org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
parent0c22243c4a59560529e7bd271094837c0fbf5295 (diff)
downloadjgit-89a4dcf71ff3326aa6313b3a988b7721c3470858.tar.gz
jgit-89a4dcf71ff3326aa6313b3a988b7721c3470858.zip
Checkout: fix handling if name does not refer to a local branch
The CheckoutCommand does not handle names other than local branch names properly; it must detach HEAD if such a name is encountered (for example a commit ID or a remote tracking branch). Change-Id: I5d55177f4029bcc34fc2649fd564b125a2929cc4 Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java19
1 files changed, 18 insertions, 1 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 cf78a0e563..1166464d5e 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
@@ -52,6 +52,7 @@ import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -97,9 +98,12 @@ public class CheckoutCommandTest extends RepositoryTestCase {
git.checkout().setName("test").call();
assertEquals("[Test.txt, mode:100644, content:Some change]",
indexState(CONTENT));
- git.checkout().setName("master").call();
+ Ref result = git.checkout().setName("master").call();
assertEquals("[Test.txt, mode:100644, content:Hello world]",
indexState(CONTENT));
+ assertEquals("refs/heads/master", result.getName());
+ assertEquals("refs/heads/master", git.getRepository()
+ .getFullBranch());
} catch (Exception e) {
fail(e.getMessage());
}
@@ -171,4 +175,17 @@ public class CheckoutCommandTest extends RepositoryTestCase {
fis.close();
}
}
+
+ public void testCheckoutCommit() {
+ try {
+ Ref result = git.checkout().setName(initialCommit.name()).call();
+ assertEquals("[Test.txt, mode:100644, content:Hello world]",
+ indexState(CONTENT));
+ assertNull(result);
+ assertEquals(initialCommit.name(), git.getRepository()
+ .getFullBranch());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ }
}