| 570 | } |
| 571 | |
| 572 | static void update_head(struct clone_opts *opts, const struct ref *our, const struct ref *remote, |
| 573 | const char *unborn, const char *msg) |
| 574 | { |
| 575 | const char *head; |
| 576 | if (our && !opts->detach && skip_prefix(our->name, "refs/heads/", &head)) { |
| 577 | /* Local default branch link */ |
| 578 | if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", our->name, NULL) < 0) |
| 579 | die(_("unable to update HEAD")); |
| 580 | if (!option_bare) { |
| 581 | refs_update_ref(get_main_ref_store(the_repository), |
| 582 | msg, "HEAD", &our->old_oid, NULL, 0, |
| 583 | UPDATE_REFS_DIE_ON_ERR); |
| 584 | install_branch_config(0, head, remote_name, our->name); |
| 585 | } |
| 586 | } else if (our) { |
| 587 | struct commit *c = lookup_commit_or_die(&our->old_oid, |
| 588 | our->name); |
| 589 | |
| 590 | /* --branch specifies a non-branch (i.e. tags), detach HEAD */ |
| 591 | refs_update_ref(get_main_ref_store(the_repository), msg, |
| 592 | "HEAD", &c->object.oid, NULL, REF_NO_DEREF, |
| 593 | UPDATE_REFS_DIE_ON_ERR); |
| 594 | } else if (remote) { |
| 595 | /* |
| 596 | * We know remote HEAD points to a non-branch, or |
| 597 | * HEAD points to a branch but we don't know which one. |
| 598 | * Detach HEAD in all these cases. |
| 599 | */ |
| 600 | refs_update_ref(get_main_ref_store(the_repository), msg, |
| 601 | "HEAD", &remote->old_oid, NULL, REF_NO_DEREF, |
| 602 | UPDATE_REFS_DIE_ON_ERR); |
| 603 | } else if (unborn && skip_prefix(unborn, "refs/heads/", &head)) { |
| 604 | /* |
| 605 | * Unborn head from remote; same as "our" case above except |
| 606 | * that we have no ref to update. |
| 607 | */ |
| 608 | if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", unborn, NULL) < 0) |
| 609 | die(_("unable to update HEAD")); |
| 610 | if (!option_bare) |
| 611 | install_branch_config(0, head, remote_name, unborn); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | static int git_sparse_checkout_init(const char *repo) |
| 616 | { |
no test coverage detected