clone: --branch=<branch> always means refs/heads/<branch>
It does not make sense to look outside refs/heads for HEAD's target (src_ref_prefix can be set to "refs/" if --mirror is used) because ref code only allows symref in form refs/heads/... Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Jan 16, 2012 at 16:46 UTC
9e5850460164f49dc9ae47569838084f5572846d
1 file changed
+16
-14
builtin/clone.c
+16
-14
@@ -48,7 +48,6 @@ static int option_verbosity;
48
static int option_progress;
49
static struct string_list option_config;
50
static struct string_list option_reference;
51
-static const char *src_ref_prefix = "refs/heads/";
51
52
static int opt_parse_reference(const struct option *opt, const char *arg, int unset)
53
{
@@ -413,6 +412,17 @@ static void remove_junk_on_signal(int signo)
412
raise(signo);
413
}
414
415
+static struct ref *find_remote_branch(const struct ref *refs, const char *branch)
416
+{
417
+ struct ref *ref;
418
+ struct strbuf head = STRBUF_INIT;
419
+ strbuf_addstr(&head, "refs/heads/");
420
+ strbuf_addstr(&head, branch);
421
+ ref = find_ref_by_name(refs, head.buf);
422
+ strbuf_release(&head);
423
+ return ref;
424
+}
425
+
426
static struct ref *wanted_peer_refs(const struct ref *refs,
427
struct refspec *refspec)
428
{
@@ -425,13 +435,8 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
435
436
if (!option_branch)
437
remote_head = guess_remote_head(head, refs, 0);
428
- else {
429
- struct strbuf sb = STRBUF_INIT;
430
- strbuf_addstr(&sb, src_ref_prefix);
431
- strbuf_addstr(&sb, option_branch);
432
- remote_head = find_ref_by_name(refs, sb.buf);
433
- strbuf_release(&sb);
434
- }
438
+ else
439
+ remote_head = find_remote_branch(refs, option_branch);
440
441
if (!remote_head && option_branch)
442
warning(_("Could not find remote branch %s to clone."),
@@ -502,7 +507,7 @@ static void update_remote_refs(const struct ref *refs,
507
static void update_head(const struct ref *our, const struct ref *remote,
508
const char *msg)
509
{
505
- if (our) {
510
+ if (our && !prefixcmp(our->name, "refs/heads/")) {
511
/* Local default branch link */
512
create_symref("HEAD", our->name, NULL);
513
if (!option_bare) {
@@ -609,6 +614,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
614
struct strbuf key = STRBUF_INIT, value = STRBUF_INIT;
615
struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
616
struct transport *transport = NULL;
617
+ const char *src_ref_prefix = "refs/heads/";
618
struct remote *remote;
619
int err = 0;
620
@@ -807,12 +813,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
813
guess_remote_head(remote_head, mapped_refs, 0);
814
815
if (option_branch) {
810
- struct strbuf head = STRBUF_INIT;
811
- strbuf_addstr(&head, src_ref_prefix);
812
- strbuf_addstr(&head, option_branch);
816
our_head_points_at =
814
- find_ref_by_name(mapped_refs, head.buf);
815
- strbuf_release(&head);
817
+ find_remote_branch(mapped_refs, option_branch);
818
819
if (!our_head_points_at) {
820
warning(_("Remote branch %s not found in "