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

Function module_add

builtin/submodule--helper.c:3642–3801  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3640}
3641
3642static int module_add(int argc, const char **argv, const char *prefix,
3643 struct repository *repo UNUSED)
3644{
3645 int force = 0, quiet = 0, progress = 0, dissociate = 0;
3646 struct add_data add_data = ADD_DATA_INIT;
3647 const char *ref_storage_format = NULL;
3648 char *to_free = NULL;
3649 const struct submodule *existing;
3650 struct strbuf buf = STRBUF_INIT;
3651 char *sm_name_to_free = NULL;
3652 struct option options[] = {
3653 OPT_STRING('b', "branch", &add_data.branch, N_("branch"),
3654 N_("branch of repository to add as submodule")),
3655 OPT__FORCE(&force, N_("allow adding an otherwise ignored submodule path"),
3656 PARSE_OPT_NOCOMPLETE),
3657 OPT__QUIET(&quiet, N_("print only error messages")),
3658 OPT_BOOL(0, "progress", &progress, N_("force cloning progress")),
3659 OPT_STRING(0, "reference", &add_data.reference_path, N_("repository"),
3660 N_("reference repository")),
3661 OPT_STRING(0, "ref-format", &ref_storage_format, N_("format"),
3662 N_("specify the reference format to use")),
3663 OPT_BOOL(0, "dissociate", &dissociate, N_("borrow the objects from reference repositories")),
3664 OPT_STRING(0, "name", &add_data.sm_name, N_("name"),
3665 N_("sets the submodule's name to the given string "
3666 "instead of defaulting to its path")),
3667 OPT_INTEGER(0, "depth", &add_data.depth, N_("depth for shallow clones")),
3668 OPT_END()
3669 };
3670 const char *const usage[] = {
3671 N_("git submodule add [<options>] [--] <repository> [<path>]"),
3672 NULL
3673 };
3674 struct strbuf sb = STRBUF_INIT;
3675 int ret = 1;
3676
3677 argc = parse_options(argc, argv, prefix, options, usage, 0);
3678
3679 if (!is_writing_gitmodules_ok())
3680 die(_("please make sure that the .gitmodules file is in the working tree"));
3681
3682 if (prefix && *prefix &&
3683 add_data.reference_path && !is_absolute_path(add_data.reference_path))
3684 add_data.reference_path = xstrfmt("%s%s", prefix, add_data.reference_path);
3685
3686 if (argc == 0 || argc > 2)
3687 usage_with_options(usage, options);
3688
3689 if (ref_storage_format) {
3690 add_data.ref_storage_format = ref_storage_format_by_name(ref_storage_format);
3691 if (add_data.ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
3692 die(_("unknown ref storage format '%s'"), ref_storage_format);
3693 }
3694
3695 add_data.repo = argv[0];
3696 if (argc == 1)
3697 add_data.sm_path = git_url_basename(add_data.repo, 0, 0);
3698 else
3699 add_data.sm_path = xstrdup(argv[1]);

Callers

nothing calls this directly

Calls 15

parse_optionsFunction · 0.85
is_writing_gitmodules_okFunction · 0.85
is_absolute_pathFunction · 0.85
xstrfmtFunction · 0.85
usage_with_optionsFunction · 0.85
git_url_basenameFunction · 0.85
xstrdupFunction · 0.85
starts_with_dot_slashFunction · 0.85
resolve_relative_urlFunction · 0.85
normalize_path_copyFunction · 0.85

Tested by

no test coverage detected