Merge branch 'jc/checkout-reflog-fix'
authorJunio C Hamano <gitster@pobox.com>
Fri, 22 Jul 2011 21:43:03 +0000 (14:43 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 Jul 2011 21:43:03 +0000 (14:43 -0700)
* jc/checkout-reflog-fix:
checkout: do not write bogus reflog entry out

1  2 
builtin/checkout.c
diff --combined builtin/checkout.c
index f152adf9ab71287e02e9e85c0b84aae096e5bec7,48de146b734af3dfe0a77bb285bb19bd47061993..d647a313036df65d928d028463564b5390756901
@@@ -657,25 -657,24 +657,25 @@@ static void suggest_reattach(struct com
                "Warning: you are leaving %d commit behind, "
                "not connected to\n"
                "any of your branches:\n\n"
 -              "%s\n"
 -              "If you want to keep it by creating a new branch, "
 -              "this may be a good time\nto do so with:\n\n"
 -              " git branch new_branch_name %s\n\n",
 +              "%s\n",
                /* The plural version */
                "Warning: you are leaving %d commits behind, "
                "not connected to\n"
                "any of your branches:\n\n"
 -              "%s\n"
 -              "If you want to keep them by creating a new branch, "
 -              "this may be a good time\nto do so with:\n\n"
 -              " git branch new_branch_name %s\n\n",
 +              "%s\n",
                /* Give ngettext() the count */
                lost),
                lost,
 -              sb.buf,
 -              sha1_to_hex(commit->object.sha1));
 +              sb.buf);
        strbuf_release(&sb);
 +
 +      if (advice_detached_head)
 +              fprintf(stderr,
 +                      _(
 +                      "If you want to keep them by creating a new branch, "
 +                      "this may be a good time\nto do so with:\n\n"
 +                      " git branch new_branch_name %s\n\n"),
 +                      sha1_to_hex(commit->object.sha1));
  }
  
  /*
@@@ -716,10 -715,12 +716,12 @@@ static int switch_branches(struct check
        unsigned char rev[20];
        int flag;
        memset(&old, 0, sizeof(old));
-       old.path = resolve_ref("HEAD", rev, 0, &flag);
+       old.path = xstrdup(resolve_ref("HEAD", rev, 0, &flag));
        old.commit = lookup_commit_reference_gently(rev, 1);
-       if (!(flag & REF_ISSYMREF))
+       if (!(flag & REF_ISSYMREF)) {
+               free((char *)old.path);
                old.path = NULL;
+       }
  
        if (old.path && !prefixcmp(old.path, "refs/heads/"))
                old.name = old.path + strlen("refs/heads/");
        update_refs_for_switch(opts, &old, new);
  
        ret = post_checkout_hook(old.commit, new->commit, 1);
+       free((char *)old.path);
        return ret || opts->writeout_error;
  }
  
@@@ -1072,7 -1074,7 +1075,7 @@@ int cmd_checkout(int argc, const char *
                if (strbuf_check_branch_ref(&buf, opts.new_branch))
                        die(_("git checkout: we do not like '%s' as a branch name."),
                            opts.new_branch);
 -              if (!get_sha1(buf.buf, rev)) {
 +              if (ref_exists(buf.buf)) {
                        opts.branch_exists = 1;
                        if (!opts.new_branch_force)
                                die(_("git checkout: branch %s already exists"),