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

Function clone_submodule

builtin/submodule--helper.c:1899–2031  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1897}
1898
1899static int clone_submodule(const struct module_clone_data *clone_data,
1900 struct string_list *reference)
1901{
1902 char *p;
1903 char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name);
1904 char *sm_alternate = NULL, *error_strategy = NULL;
1905 struct stat st;
1906 struct child_process cp = CHILD_PROCESS_INIT;
1907 const char *clone_data_path = clone_data->path;
1908 char *to_free = NULL;
1909
1910 if (validate_submodule_path(clone_data_path) < 0)
1911 die(NULL);
1912
1913 if (!is_absolute_path(clone_data->path))
1914 clone_data_path = to_free = xstrfmt("%s/%s", repo_get_work_tree(the_repository),
1915 clone_data->path);
1916
1917 if (!file_exists(sm_gitdir)) {
1918 if (clone_data->require_init && !stat(clone_data_path, &st) &&
1919 !is_empty_dir(clone_data_path))
1920 die(_("directory not empty: '%s'"), clone_data_path);
1921
1922 if (safe_create_leading_directories_const(the_repository, sm_gitdir) < 0)
1923 die(_("could not create directory '%s'"), sm_gitdir);
1924
1925 prepare_possible_alternates(clone_data->name, reference);
1926
1927 strvec_push(&cp.args, "clone");
1928 strvec_push(&cp.args, "--no-checkout");
1929 if (clone_data->quiet)
1930 strvec_push(&cp.args, "--quiet");
1931 if (clone_data->progress)
1932 strvec_push(&cp.args, "--progress");
1933 if (clone_data->depth > 0)
1934 strvec_pushf(&cp.args, "--depth=%d", clone_data->depth);
1935 if (reference->nr) {
1936 struct string_list_item *item;
1937
1938 for_each_string_list_item(item, reference)
1939 strvec_pushl(&cp.args, "--reference",
1940 item->string, NULL);
1941 }
1942 if (clone_data->ref_storage_format != REF_STORAGE_FORMAT_UNKNOWN)
1943 strvec_pushf(&cp.args, "--ref-format=%s",
1944 ref_storage_format_to_name(clone_data->ref_storage_format));
1945 if (clone_data->dissociate)
1946 strvec_push(&cp.args, "--dissociate");
1947 if (sm_gitdir && *sm_gitdir)
1948 strvec_pushl(&cp.args, "--separate-git-dir", sm_gitdir, NULL);
1949 if (clone_data->filter_options && clone_data->filter_options->choice)
1950 strvec_pushf(&cp.args, "--filter=%s",
1951 expand_list_objects_filter_spec(
1952 clone_data->filter_options));
1953 if (clone_data->single_branch >= 0)
1954 strvec_push(&cp.args, clone_data->single_branch ?
1955 "--single-branch" :
1956 "--no-single-branch");

Callers 2

module_cloneFunction · 0.85
add_submoduleFunction · 0.85

Calls 15

validate_submodule_pathFunction · 0.85
is_absolute_pathFunction · 0.85
xstrfmtFunction · 0.85
repo_get_work_treeFunction · 0.85
file_existsFunction · 0.85
is_empty_dirFunction · 0.85
strvec_pushFunction · 0.85
strvec_pushfFunction · 0.85
strvec_pushlFunction · 0.85

Tested by

no test coverage detected