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

Function add_submodule

builtin/submodule--helper.c:3404–3501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3402}
3403
3404static int add_submodule(const struct add_data *add_data)
3405{
3406 struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
3407 struct string_list reference = STRING_LIST_INIT_NODUP;
3408 int ret = -1;
3409
3410 /* perhaps the path already exists and is already a git repo, else clone it */
3411 if (is_directory(add_data->sm_path)) {
3412 char *submod_gitdir_path;
3413 struct strbuf sm_path = STRBUF_INIT;
3414 strbuf_addstr(&sm_path, add_data->sm_path);
3415 submod_gitdir_path = xstrfmt("%s/.git", add_data->sm_path);
3416 if (is_nonbare_repository_dir(&sm_path))
3417 printf(_("Adding existing repo at '%s' to the index\n"),
3418 add_data->sm_path);
3419 else
3420 die(_("'%s' already exists and is not a valid git repo"),
3421 add_data->sm_path);
3422 strbuf_release(&sm_path);
3423 free(submod_gitdir_path);
3424 } else {
3425 struct child_process cp = CHILD_PROCESS_INIT;
3426 struct strbuf submod_gitdir = STRBUF_INIT;
3427
3428 submodule_name_to_gitdir(&submod_gitdir, the_repository, add_data->sm_name);
3429
3430 if (is_directory(submod_gitdir.buf)) {
3431 if (!add_data->force) {
3432 struct strbuf msg = STRBUF_INIT;
3433 char *die_msg;
3434
3435 strbuf_addf(&msg, _("A git directory for '%s' is found "
3436 "locally with remote(s):\n"),
3437 add_data->sm_name);
3438
3439 append_fetch_remotes(&msg, submod_gitdir.buf);
3440 strbuf_release(&submod_gitdir);
3441
3442 strbuf_addf(&msg, _("If you want to reuse this local git "
3443 "directory instead of cloning again from\n"
3444 " %s\n"
3445 "use the '--force' option. If the local git "
3446 "directory is not the correct repo\n"
3447 "or you are unsure what this means choose "
3448 "another name with the '--name' option."),
3449 add_data->realrepo);
3450
3451 die_msg = strbuf_detach(&msg, NULL);
3452 die("%s", die_msg);
3453 } else {
3454 printf(_("Reactivating local git directory for "
3455 "submodule '%s'\n"), add_data->sm_name);
3456 }
3457 }
3458 strbuf_release(&submod_gitdir);
3459
3460 clone_data.prefix = add_data->prefix;
3461 clone_data.path = add_data->sm_path;

Callers 1

module_addFunction · 0.85

Calls 15

is_directoryFunction · 0.85
strbuf_addstrFunction · 0.85
xstrfmtFunction · 0.85
strbuf_releaseFunction · 0.85
submodule_name_to_gitdirFunction · 0.85
strbuf_addfFunction · 0.85
append_fetch_remotesFunction · 0.85
strbuf_detachFunction · 0.85
xstrdupFunction · 0.85
clone_submoduleFunction · 0.85

Tested by

no test coverage detected