39
};
40
41
static int option_no_checkout, option_bare, option_mirror, option_single_branch = -1;
42
-static int option_local = -1, option_no_hardlinks, option_shared, option_recursive;
42
+static int option_local = -1, option_no_hardlinks, option_shared;
43
static int option_shallow_submodules;
44
static int deepen;
45
static char *option_template, *option_depth, *option_since;
56
static struct string_list option_optional_reference = STRING_LIST_INIT_NODUP;
57
static int option_dissociate;
58
static int max_jobs = -1;
59
+static struct string_list option_recurse_submodules = STRING_LIST_INIT_NODUP;
60
+
61
+static int recurse_submodules_cb(const struct option *opt,
62
+ const char *arg, int unset)
63
+{
64
+ if (unset)
65
+ string_list_clear((struct string_list *)opt->value, 0);
66
+ else if (arg)
67
+ string_list_append((struct string_list *)opt->value, arg);
68
+ else
69
+ string_list_append((struct string_list *)opt->value,
70
+ (const char *)opt->defval);
71
+
72
+ return 0;
73
+}
74
75
static struct option builtin_clone_options[] = {
76
OPT__VERBOSITY(&option_verbosity),
89
N_("don't use local hardlinks, always copy")),
90
OPT_BOOL('s', "shared", &option_shared,
91
N_("setup as shared repository")),
77
- OPT_BOOL(0, "recursive", &option_recursive,
78
- N_("initialize submodules in the clone")),
79
- OPT_BOOL(0, "recurse-submodules", &option_recursive,
80
- N_("initialize submodules in the clone")),
92
+ { OPTION_CALLBACK, 0, "recursive", &option_recurse_submodules,
93
+ N_("pathspec"), N_("initialize submodules in the clone"),
94
+ PARSE_OPT_OPTARG | PARSE_OPT_HIDDEN, recurse_submodules_cb,
95
+ (intptr_t)"." },
96
+ { OPTION_CALLBACK, 0, "recurse-submodules", &option_recurse_submodules,
97
+ N_("pathspec"), N_("initialize submodules in the clone"),
98
+ PARSE_OPT_OPTARG, recurse_submodules_cb, (intptr_t)"." },
99
OPT_INTEGER('j', "jobs", &max_jobs,
100
N_("number of submodules cloned in parallel")),
101
OPT_STRING(0, "template", &option_template, N_("template-directory"),
751
err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
752
sha1_to_hex(sha1), "1", NULL);
753
736
- if (!err && option_recursive) {
754
+ if (!err && (option_recurse_submodules.nr > 0)) {
755
struct argv_array args = ARGV_ARRAY_INIT;
756
argv_array_pushl(&args, "submodule", "update", "--init", "--recursive", NULL);
757
975
fprintf(stderr, _("Cloning into '%s'...\n"), dir);
976
}
977
960
- if (option_recursive) {
978
+ if (option_recurse_submodules.nr > 0) {
979
+ struct string_list_item *item;
980
+ struct strbuf sb = STRBUF_INIT;
981
+
982
+ /* remove duplicates */
983
+ string_list_sort(&option_recurse_submodules);
984
+ string_list_remove_duplicates(&option_recurse_submodules, 0);
985
+
986
+ /*
987
+ * NEEDSWORK: In a multi-working-tree world, this needs to be
988
+ * set in the per-worktree config.
989
+ */
990
+ for_each_string_list_item(item, &option_recurse_submodules) {
991
+ strbuf_addf(&sb, "submodule.active=%s",
992
+ item->string);
993
+ string_list_append(&option_config,
994
+ strbuf_detach(&sb, NULL));
995
+ }
996
+
997
if (option_required_reference.nr &&
998
option_optional_reference.nr)
999
die(_("clone --recursive is not compatible with "