Merge branch 'jc/fix-clone-single-starting-at-a-tag'
authorJunio C Hamano <gitster@pobox.com>
Thu, 10 Jul 2014 18:17:24 +0000 (11:17 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Jul 2014 18:17:24 +0000 (11:17 -0700)
"git clone -b brefs/tags/bar" would have mistakenly thought we were
following a single tag, even though it was a name of the branch,
because it incorrectly used strstr().

* jc/fix-clone-single-starting-at-a-tag:
builtin/clone.c: detect a clone starting at a tag correctly

1  2 
builtin/clone.c
diff --combined builtin/clone.c
index a5b2d9db360eb59d5a73c2e221fed047a94b0615,545105a86fdf07873948f2bbe7d1c4f6e65b1509..e15ca332b5637421fb187ce4db478c60dded958c
@@@ -521,7 -521,7 +521,7 @@@ static void write_followtags(const stru
                if (!has_sha1_file(ref->old_sha1))
                        continue;
                update_ref(msg, ref->name, ref->old_sha1,
 -                         NULL, 0, DIE_ON_ERR);
 +                         NULL, 0, UPDATE_REFS_DIE_ON_ERR);
        }
  }
  
@@@ -584,20 -584,19 +584,20 @@@ static void update_remote_refs(const st
  static void update_head(const struct ref *our, const struct ref *remote,
                        const char *msg)
  {
 -      if (our && starts_with(our->name, "refs/heads/")) {
 +      const char *head;
 +      if (our && skip_prefix(our->name, "refs/heads/", &head)) {
                /* Local default branch link */
                create_symref("HEAD", our->name, NULL);
                if (!option_bare) {
 -                      const char *head = skip_prefix(our->name, "refs/heads/");
 -                      update_ref(msg, "HEAD", our->old_sha1, NULL, 0, DIE_ON_ERR);
 +                      update_ref(msg, "HEAD", our->old_sha1, NULL, 0,
 +                                 UPDATE_REFS_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);
 +                         NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
        } else if (remote) {
                /*
                 * We know remote HEAD points to a non-branch, or
                 * Detach HEAD in all these cases.
                 */
                update_ref(msg, "HEAD", remote->old_sha1,
 -                         NULL, REF_NODEREF, DIE_ON_ERR);
 +                         NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
        }
  }
  
@@@ -696,19 -695,16 +696,19 @@@ static void write_refspec_config(const 
        if (option_mirror || !option_bare) {
                if (option_single_branch && !option_mirror) {
                        if (option_branch) {
-                               if (strstr(our_head_points_at->name, "refs/tags/"))
+                               if (starts_with(our_head_points_at->name, "refs/tags/"))
                                        strbuf_addf(&value, "+%s:%s", our_head_points_at->name,
                                                our_head_points_at->name);
                                else
                                        strbuf_addf(&value, "+%s:%s%s", our_head_points_at->name,
                                                branch_top->buf, option_branch);
                        } else if (remote_head_points_at) {
 +                              const char *head = remote_head_points_at->name;
 +                              if (!skip_prefix(head, "refs/heads/", &head))
 +                                      die("BUG: remote HEAD points at non-head?");
 +
                                strbuf_addf(&value, "+%s:%s%s", remote_head_points_at->name,
 -                                              branch_top->buf,
 -                                              skip_prefix(remote_head_points_at->name, "refs/heads/"));
 +                                              branch_top->buf, head);
                        }
                        /*
                         * otherwise, the next "git fetch" will