summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorRobin Stocker <robin@nibor.org>2013-05-25 15:56:50 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2013-05-26 01:25:10 +0200
commit7bb2a1b8440386dead8b72c329b92e2473e89e32 (patch)
tree324c1e637e5237c4a9533b986c19102c3e60cb98 /org.eclipse.jgit
parent67783d7ded4ee05a88fde135036d2be976385641 (diff)
downloadjgit-7bb2a1b8440386dead8b72c329b92e2473e89e32.tar.gz
jgit-7bb2a1b8440386dead8b72c329b92e2473e89e32.zip
Handle short branch/tag name for setBranch in CloneCommand
Before, it was not clear from the documentation what kind of branch name was accepted. Users specifying "branch" (instead of "refs/heads/branch") got no error message and ended up with a repository without HEAD and no checkout. With this, CloneCommand now tries "$branch", then "refs/heads/$branch" and then "refs/tags/$branch". C Git only does the last two, but for compatibility we should still allow "refs/heads/branch". Bug: 390994 Change-Id: I4be13144f2a21a6583e0942f0c7c40da32f2247a Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
index 65af216ae8..645d3e7815 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011, Chris Aniszczyk <caniszczyk@gmail.com>
+ * Copyright (C) 2011, 2013 Chris Aniszczyk <caniszczyk@gmail.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -198,12 +198,19 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
throws MissingObjectException, IncorrectObjectTypeException,
IOException, GitAPIException {
- Ref head = result.getAdvertisedRef(branch);
+ Ref head = null;
if (branch.equals(Constants.HEAD)) {
Ref foundBranch = findBranchToCheckout(result);
if (foundBranch != null)
head = foundBranch;
}
+ if (head == null) {
+ head = result.getAdvertisedRef(branch);
+ if (head == null)
+ head = result.getAdvertisedRef(Constants.R_HEADS + branch);
+ if (head == null)
+ head = result.getAdvertisedRef(Constants.R_TAGS + branch);
+ }
if (head == null || head.getObjectId() == null)
return; // throw exception?
@@ -362,7 +369,9 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
/**
* @param branch
- * the initial branch to check out when cloning the repository
+ * the initial branch to check out when cloning the repository.
+ * Can be specified as ref name (<code>refs/heads/master</code>),
+ * branch name (<code>master</code>) or tag name (<code>v1.2.3</code>).
* @return this instance
*/
public CloneCommand setBranch(String branch) {
@@ -409,7 +418,8 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
/**
* @param branchesToClone
* collection of branches to clone. Ignored when allSelected is
- * true.
+ * true. Must be specified as full ref names (e.g.
+ * <code>refs/heads/master</code>).
* @return {@code this}
*/
public CloneCommand setBranchesToClone(Collection<String> branchesToClone) {