aboutsummaryrefslogtreecommitdiff
path: root/builtin/clone.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2012-01-16 16:46:15 +0700
committerJunio C Hamano <gitster@pobox.com>2012-01-16 16:26:26 -0800
commit5a7d5b683f869d3e3884a89775241afa515da9e7 (patch)
treecf3930dd84c09d9bacdda4c993aab526e7bd493e /builtin/clone.c
parent920b691fe4da8115f9b79901411c0cc5fff17efe (diff)
downloadgit-5a7d5b683f869d3e3884a89775241afa515da9e7.tar.gz
git-5a7d5b683f869d3e3884a89775241afa515da9e7.tar.xz
clone: allow --branch to take a tag
Because a tag ref cannot be put to HEAD, HEAD will become detached. This is consistent with "git checkout <tag>". This is mostly useful in shallow clone, where it allows you to clone a tag in addtion to branches. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/clone.c')
-rw-r--r--builtin/clone.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index 3cfedb3a9..651b4cc20 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -420,6 +420,15 @@ static struct ref *find_remote_branch(const struct ref *refs, const char *branch
strbuf_addstr(&head, branch);
ref = find_ref_by_name(refs, head.buf);
strbuf_release(&head);
+
+ if (ref)
+ return ref;
+
+ strbuf_addstr(&head, "refs/tags/");
+ strbuf_addstr(&head, branch);
+ ref = find_ref_by_name(refs, head.buf);
+ strbuf_release(&head);
+
return ref;
}
@@ -441,8 +450,12 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
if (!remote_head && option_branch)
warning(_("Could not find remote branch %s to clone."),
option_branch);
- else
+ else {
get_fetch_map(remote_head, refspec, &tail, 0);
+
+ /* if --branch=tag, pull the requested tag explicitly */
+ get_fetch_map(remote_head, tag_refspec, &tail, 0);
+ }
} else
get_fetch_map(refs, refspec, &tail, 0);
@@ -515,6 +528,11 @@ static void update_head(const struct ref *our, const struct ref *remote,
update_ref(msg, "HEAD", our->old_sha1, NULL, 0, DIE_ON_ERR);
install_branch_config(0, head, option_origin, our->name);
}
+ } else if (our) {
+ struct commit *c = lookup_commit_reference(our->old_sha1);
+ /* --branch specifies a non-branch (i.e. tags), detach HEAD */
+ update_ref(msg, "HEAD", c->object.sha1,
+ NULL, REF_NODEREF, DIE_ON_ERR);
} else if (remote) {
/*
* We know remote HEAD points to a non-branch, or