| 571 | } |
| 572 | |
| 573 | static void init_submodule(const char *path, const char *prefix, |
| 574 | const char *super_prefix, |
| 575 | unsigned int flags) |
| 576 | { |
| 577 | const struct submodule *sub; |
| 578 | struct strbuf sb = STRBUF_INIT; |
| 579 | const char *upd; |
| 580 | char *url = NULL, *displaypath; |
| 581 | |
| 582 | displaypath = get_submodule_displaypath(path, prefix, super_prefix); |
| 583 | |
| 584 | sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path); |
| 585 | |
| 586 | if (!sub) |
| 587 | die(_("No url found for submodule path '%s' in .gitmodules"), |
| 588 | displaypath); |
| 589 | |
| 590 | /* |
| 591 | * NEEDSWORK: In a multi-working-tree world, this needs to be |
| 592 | * set in the per-worktree config. |
| 593 | * |
| 594 | * Set active flag for the submodule being initialized |
| 595 | */ |
| 596 | if (!is_submodule_active(the_repository, path)) { |
| 597 | strbuf_addf(&sb, "submodule.%s.active", sub->name); |
| 598 | repo_config_set_gently(the_repository, sb.buf, "true"); |
| 599 | strbuf_reset(&sb); |
| 600 | } |
| 601 | |
| 602 | /* |
| 603 | * Copy url setting when it is not set yet. |
| 604 | * To look up the url in .git/config, we must not fall back to |
| 605 | * .gitmodules, so look it up directly. |
| 606 | */ |
| 607 | strbuf_addf(&sb, "submodule.%s.url", sub->name); |
| 608 | if (repo_config_get_string(the_repository, sb.buf, &url)) { |
| 609 | if (!sub->url) |
| 610 | die(_("No url found for submodule path '%s' in .gitmodules"), |
| 611 | displaypath); |
| 612 | |
| 613 | url = xstrdup(sub->url); |
| 614 | |
| 615 | /* Possibly a url relative to parent */ |
| 616 | if (starts_with_dot_dot_slash(url) || |
| 617 | starts_with_dot_slash(url)) { |
| 618 | char *oldurl = url; |
| 619 | |
| 620 | url = resolve_relative_url(oldurl, NULL, 0); |
| 621 | free(oldurl); |
| 622 | } |
| 623 | |
| 624 | if (repo_config_set_gently(the_repository, sb.buf, url)) |
| 625 | die(_("Failed to register url for submodule path '%s'"), |
| 626 | displaypath); |
| 627 | if (!(flags & OPT_QUIET)) |
| 628 | fprintf(stderr, |
| 629 | _("Submodule '%s' (%s) registered for path '%s'\n"), |
| 630 | sub->name, url, displaypath); |
no test coverage detected