MCPcopy Create free account
hub / github.com/git/git / configure_added_submodule

Function configure_added_submodule

builtin/submodule--helper.c:3518–3590  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3516}
3517
3518static void configure_added_submodule(struct add_data *add_data)
3519{
3520 char *key;
3521 struct child_process add_submod = CHILD_PROCESS_INIT;
3522 struct child_process add_gitmodules = CHILD_PROCESS_INIT;
3523 const struct string_list *values;
3524 int matched = 0;
3525
3526 key = xstrfmt("submodule.%s.url", add_data->sm_name);
3527 repo_config_set_gently(the_repository, key, add_data->realrepo);
3528 free(key);
3529
3530 add_submod.git_cmd = 1;
3531 strvec_pushl(&add_submod.args, "add",
3532 "--no-warn-embedded-repo", NULL);
3533 if (add_data->force)
3534 strvec_push(&add_submod.args, "--force");
3535 strvec_pushl(&add_submod.args, "--", add_data->sm_path, NULL);
3536
3537 if (run_command(&add_submod))
3538 die(_("Failed to add submodule '%s'"), add_data->sm_path);
3539
3540 if (config_submodule_in_gitmodules(add_data->sm_name, "path", add_data->sm_path) ||
3541 config_submodule_in_gitmodules(add_data->sm_name, "url", add_data->repo))
3542 die(_("Failed to register submodule '%s'"), add_data->sm_path);
3543
3544 if (add_data->branch) {
3545 if (config_submodule_in_gitmodules(add_data->sm_name,
3546 "branch", add_data->branch))
3547 die(_("Failed to register submodule '%s'"), add_data->sm_path);
3548 }
3549
3550 add_gitmodules.git_cmd = 1;
3551 strvec_pushl(&add_gitmodules.args,
3552 "add", "--force", "--", ".gitmodules", NULL);
3553
3554 if (run_command(&add_gitmodules))
3555 die(_("Failed to register submodule '%s'"), add_data->sm_path);
3556
3557 /*
3558 * NEEDSWORK: In a multi-working-tree world this needs to be
3559 * set in the per-worktree config.
3560 */
3561 /*
3562 * NEEDSWORK: In the longer run, we need to get rid of this
3563 * pattern of querying "submodule.active" before calling
3564 * is_submodule_active(), since that function needs to find
3565 * out the value of "submodule.active" again anyway.
3566 */
3567 if (repo_config_get(the_repository, "submodule.active") || /* key absent */
3568 repo_config_get_string_multi(the_repository, "submodule.active", &values)) {
3569 /*
3570 * If the submodule being added isn't already covered by the
3571 * current configured pathspec, set the submodule's active flag
3572 */
3573 key = xstrfmt("submodule.%s.active", add_data->sm_name);
3574 repo_config_set_gently(the_repository, key, "true");
3575 free(key);

Callers 1

module_addFunction · 0.85

Calls 10

xstrfmtFunction · 0.85
repo_config_set_gentlyFunction · 0.85
strvec_pushlFunction · 0.85
strvec_pushFunction · 0.85
run_commandFunction · 0.85
repo_config_getFunction · 0.85
wildmatchFunction · 0.85
dieFunction · 0.50

Tested by

no test coverage detected