606
}
607
608
static void update_head(const struct ref *our, const struct ref *remote,
609
- const char *msg)
609
+ const char *unborn, const char *msg)
610
{
611
const char *head;
612
if (our && skip_prefix(our->name, "refs/heads/", &head)) {
632
*/
633
update_ref(msg, "HEAD", &remote->old_oid, NULL, REF_NO_DEREF,
634
UPDATE_REFS_DIE_ON_ERR);
635
+ } else if (unborn && skip_prefix(unborn, "refs/heads/", &head)) {
636
+ /*
637
+ * Unborn head from remote; same as "our" case above except
638
+ * that we have no ref to update.
639
+ */
640
+ if (create_symref("HEAD", unborn, NULL) < 0)
641
+ die(_("unable to update HEAD"));
642
+ if (!option_bare)
643
+ install_branch_config(0, head, remote_name, unborn);
644
}
645
}
646
885
const struct ref *refs, *remote_head;
886
struct ref *remote_head_points_at = NULL;
887
const struct ref *our_head_points_at;
888
+ char *unborn_head = NULL;
889
struct ref *mapped_refs = NULL;
890
const struct ref *ref;
891
struct strbuf key = STRBUF_INIT;
1292
our_head_points_at = NULL;
1293
} else {
1294
const char *branch;
1285
- const char *ref;
1286
- char *ref_free = NULL;
1295
1296
if (!mapped_refs) {
1297
warning(_("You appear to have cloned an empty repository."));
1301
if (transport_ls_refs_options.unborn_head_target &&
1302
skip_prefix(transport_ls_refs_options.unborn_head_target,
1303
"refs/heads/", &branch)) {
1296
- ref = transport_ls_refs_options.unborn_head_target;
1297
- create_symref("HEAD", ref, reflog_msg.buf);
1304
+ unborn_head = xstrdup(transport_ls_refs_options.unborn_head_target);
1305
} else {
1306
branch = git_default_branch_name(0);
1300
- ref_free = xstrfmt("refs/heads/%s", branch);
1301
- ref = ref_free;
1307
+ unborn_head = xstrfmt("refs/heads/%s", branch);
1308
}
1309
1310
/*
1319
* a match.
1320
*/
1321
our_head_points_at = find_remote_branch(mapped_refs, branch);
1316
-
1317
- if (!option_bare && !our_head_points_at)
1318
- install_branch_config(0, branch, remote_name, ref);
1319
- free(ref_free);
1322
}
1323
1324
write_refspec_config(src_ref_prefix, our_head_points_at,
1338
branch_top.buf, reflog_msg.buf, transport,
1339
!is_local);
1340
1339
- update_head(our_head_points_at, remote_head, reflog_msg.buf);
1341
+ update_head(our_head_points_at, remote_head, unborn_head, reflog_msg.buf);
1342
1343
/*
1344
* We want to show progress for recursive submodule clones iff
1365
strbuf_release(&key);
1366
free_refs(mapped_refs);
1367
free_refs(remote_head_points_at);
1368
+ free(unborn_head);
1369
free(dir);
1370
free(path);
1371
UNLEAK(repo);