1434
const char *url;
1435
const char *depth;
1436
struct list_objects_filter_options *filter_options;
1437
- struct string_list reference;
1437
unsigned int quiet: 1;
1438
unsigned int progress: 1;
1439
unsigned int dissociate: 1;
1441
int single_branch;
1442
};
1443
#define MODULE_CLONE_DATA_INIT { \
1445
- .reference = STRING_LIST_INIT_NODUP, \
1444
.single_branch = -1, \
1445
}
1446
1567
return sm_gitdir;
1568
}
1569
1572
-static int clone_submodule(struct module_clone_data *clone_data)
1570
+static int clone_submodule(const struct module_clone_data *clone_data,
1571
+ struct string_list *reference)
1572
{
1573
char *p;
1574
char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name);
1575
char *sm_alternate = NULL, *error_strategy = NULL;
1576
struct child_process cp = CHILD_PROCESS_INIT;
1577
+ const char *clone_data_path;
1578
1579
if (!is_absolute_path(clone_data->path))
1580
- clone_data->path = xstrfmt("%s/%s", get_git_work_tree(),
1581
- clone_data->path);
1580
+ clone_data_path = xstrfmt("%s/%s", get_git_work_tree(),
1581
+ clone_data->path);
1582
else
1583
- clone_data->path = xstrdup(clone_data->path);
1583
+ clone_data_path = xstrdup(clone_data->path);
1584
1585
if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0)
1586
die(_("refusing to create/use '%s' in another submodule's "
1590
if (safe_create_leading_directories_const(sm_gitdir) < 0)
1591
die(_("could not create directory '%s'"), sm_gitdir);
1592
1593
- prepare_possible_alternates(clone_data->name, &clone_data->reference);
1593
+ prepare_possible_alternates(clone_data->name, reference);
1594
1595
strvec_push(&cp.args, "clone");
1596
strvec_push(&cp.args, "--no-checkout");
1600
strvec_push(&cp.args, "--progress");
1601
if (clone_data->depth && *(clone_data->depth))
1602
strvec_pushl(&cp.args, "--depth", clone_data->depth, NULL);
1603
- if (clone_data->reference.nr) {
1603
+ if (reference->nr) {
1604
struct string_list_item *item;
1605
1606
- for_each_string_list_item(item, &clone_data->reference)
1606
+ for_each_string_list_item(item, reference)
1607
strvec_pushl(&cp.args, "--reference",
1608
item->string, NULL);
1609
}
1622
1623
strvec_push(&cp.args, "--");
1624
strvec_push(&cp.args, clone_data->url);
1625
- strvec_push(&cp.args, clone_data->path);
1625
+ strvec_push(&cp.args, clone_data_path);
1626
1627
cp.git_cmd = 1;
1628
prepare_submodule_repo_env(&cp.env);
1630
1631
if(run_command(&cp))
1632
die(_("clone of '%s' into submodule path '%s' failed"),
1633
- clone_data->url, clone_data->path);
1633
+ clone_data->url, clone_data_path);
1634
} else {
1635
char *path;
1636
1637
- if (clone_data->require_init && !access(clone_data->path, X_OK) &&
1638
- !is_empty_dir(clone_data->path))
1639
- die(_("directory not empty: '%s'"), clone_data->path);
1640
- if (safe_create_leading_directories_const(clone_data->path) < 0)
1641
- die(_("could not create directory '%s'"), clone_data->path);
1637
+ if (clone_data->require_init && !access(clone_data_path, X_OK) &&
1638
+ !is_empty_dir(clone_data_path))
1639
+ die(_("directory not empty: '%s'"), clone_data_path);
1640
+ if (safe_create_leading_directories_const(clone_data_path) < 0)
1641
+ die(_("could not create directory '%s'"), clone_data_path);
1642
path = xstrfmt("%s/index", sm_gitdir);
1643
unlink_or_warn(path);
1644
free(path);
1645
}
1646
1647
- connect_work_tree_and_git_dir(clone_data->path, sm_gitdir, 0);
1647
+ connect_work_tree_and_git_dir(clone_data_path, sm_gitdir, 0);
1648
1649
- p = git_pathdup_submodule(clone_data->path, "config");
1649
+ p = git_pathdup_submodule(clone_data_path, "config");
1650
if (!p)
1651
- die(_("could not get submodule directory for '%s'"), clone_data->path);
1651
+ die(_("could not get submodule directory for '%s'"), clone_data_path);
1652
1653
/* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */
1654
git_config_get_string("submodule.alternateLocation", &sm_alternate);
1673
int dissociate = 0, quiet = 0, progress = 0, require_init = 0;
1674
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
1675
struct list_objects_filter_options filter_options = { 0 };
1676
+ struct string_list reference = STRING_LIST_INIT_NODUP;
1677
struct option module_clone_options[] = {
1678
OPT_STRING(0, "prefix", &clone_data.prefix,
1679
N_("path"),
1687
OPT_STRING(0, "url", &clone_data.url,
1688
N_("string"),
1689
N_("url where to clone the submodule from")),
1689
- OPT_STRING_LIST(0, "reference", &clone_data.reference,
1690
+ OPT_STRING_LIST(0, "reference", &reference,
1691
N_("repo"),
1692
N_("reference repository")),
1693
OPT_BOOL(0, "dissociate", &dissociate,
1726
usage_with_options(git_submodule_helper_usage,
1727
module_clone_options);
1728
1728
- clone_submodule(&clone_data);
1729
+ clone_submodule(&clone_data, &reference);
1730
list_objects_filter_release(&filter_options);
1731
return 0;
1732
}
2914
{
2915
char *submod_gitdir_path;
2916
struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT;
2917
+ struct string_list reference = STRING_LIST_INIT_NODUP;
2918
2919
/* perhaps the path already exists and is already a git repo, else clone it */
2920
if (is_directory(add_data->sm_path)) {
2931
free(submod_gitdir_path);
2932
} else {
2933
struct child_process cp = CHILD_PROCESS_INIT;
2934
+
2935
submod_gitdir_path = xstrfmt(".git/modules/%s", add_data->sm_name);
2936
2937
if (is_directory(submod_gitdir_path)) {
2971
clone_data.quiet = add_data->quiet;
2972
clone_data.progress = add_data->progress;
2973
if (add_data->reference_path)
2971
- string_list_append(&clone_data.reference,
2974
+ string_list_append(&reference,
2975
xstrdup(add_data->reference_path));
2976
clone_data.dissociate = add_data->dissociate;
2977
if (add_data->depth >= 0)
2978
clone_data.depth = xstrfmt("%d", add_data->depth);
2979
2977
- if (clone_submodule(&clone_data))
2980
+ if (clone_submodule(&clone_data, &reference))
2981
return -1;
2982
2983
prepare_submodule_repo_env(&cp.env);