Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- Sorry, my previous patch was broken in so many ways. This one is better, promise. BTW this incidentally fixes the branch.<branch>.{remote,merge} setup: it used to strip all up-to and including a slash from the ref name. This just _happened_ to work, because commonly HEAD is at "refs/heads/master". However, if it is at "refs/heads/a/b", it would fail. builtin-clone.c | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-) diff --git a/builtin-clone.c b/builtin-clone.c index 056e8a3..f27d205 100644 --- a/builtin-clone.c +++ b/builtin-clone.c @@ -523,33 +523,38 @@ int cmd_clone(int argc, const char **argv, const char *prefix) git_config_set_multivar(key, value, "^$", 0); } + if (head_points_at) + /* Local default branch */ + create_symref("HEAD", head_points_at->name, NULL); + if (option_bare) { - if (head_points_at) { - /* Local default branch */ - create_symref("HEAD", head_points_at->name, NULL); - } junk_work_tree = NULL; junk_git_dir = NULL; return 0; } if (head_points_at) { - if (strrchr(head_points_at->name, '/')) - head = strrchr(head_points_at->name, '/') + 1; - else - head = head_points_at->name; + struct strbuf head_ref, real_ref; - /* Local default branch */ - create_symref("HEAD", head_points_at->name, NULL); + head = head_points_at->name; + if (!prefixcmp(head, "refs/heads/")) + head += 11; /* Tracking branch for the primary branch at the remote. */ update_ref(NULL, "HEAD", head_points_at->old_sha1, NULL, 0, DIE_ON_ERR); - /* - rm -f "refs/remotes/$origin/HEAD" - git symbolic-ref "refs/remotes/$origin/HEAD" \ - "refs/remotes/$origin/$head_points_at" && - */ + + strbuf_init(&head_ref, 0); + strbuf_addstr(&head_ref, branch_top); + strbuf_addstr(&head_ref, "/HEAD"); + delete_ref(head_ref.buf, head_points_at->old_sha1); + strbuf_init(&real_ref, 0); + strbuf_addstr(&real_ref, branch_top); + strbuf_addch(&real_ref, '/'); + strbuf_addstr(&real_ref, head); + create_symref(head_ref.buf, real_ref.buf, reflog_msg.buf); + strbuf_release(&head_ref); + strbuf_release(&real_ref); snprintf(key, sizeof key, "branch.%s.remote", head); git_config_set(key, option_origin); -- 1.5.4.3.446.gbe8932 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html