submodule: add --dissociate option to add/update commands
Add --dissociate option to add and update commands, both clone helper commands that already have the --reference option --dissociate pairs with. Signed-off-by: Casey Fitzpatrick <kcghost@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Casey Fitzpatrick committed
May 3, 2018 at 06:53 UTC
a0ef29341accafa51345e90225d87f6a0d297b7b
4 files changed
+48
-5
Documentation/git-submodule.txt
+9
-1
@@ -369,7 +369,15 @@ the submodule itself.
369
this option will be passed to the linkgit:git-clone[1] command.
370
+
371
*NOTE*: Do *not* use this option unless you have read the note
372
-for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
372
+for linkgit:git-clone[1]'s `--reference`, `--shared`, and `--dissociate`
373
+options carefully.
374
+
375
+--dissociate::
376
+ This option is only valid for add and update commands. These
377
+ commands sometimes need to clone a remote repository. In this case,
378
+ this option will be passed to the linkgit:git-clone[1] command.
379
++
380
+*NOTE*: see the NOTE for the `--reference` option.
381
382
--recursive::
383
This option is only valid for foreach, update, status and sync commands.
builtin/submodule--helper.c
+13
-3
@@ -1056,7 +1056,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix)
1056
}
1057
1058
static int clone_submodule(const char *path, const char *gitdir, const char *url,
1059
- const char *depth, struct string_list *reference,
1059
+ const char *depth, struct string_list *reference, int dissociate,
1060
int quiet, int progress)
1061
{
1062
struct child_process cp = CHILD_PROCESS_INIT;
@@ -1075,6 +1075,8 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
1075
argv_array_pushl(&cp.args, "--reference",
1076
item->string, NULL);
1077
}
1078
+ if (dissociate)
1079
+ argv_array_push(&cp.args, "--dissociate");
1080
if (gitdir && *gitdir)
1081
argv_array_pushl(&cp.args, "--separate-git-dir", gitdir, NULL);
1082
@@ -1190,6 +1192,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1192
char *p, *path = NULL, *sm_gitdir;
1193
struct strbuf sb = STRBUF_INIT;
1194
struct string_list reference = STRING_LIST_INIT_NODUP;
1195
+ int dissociate = 0;
1196
char *sm_alternate = NULL, *error_strategy = NULL;
1197
1198
struct option module_clone_options[] = {
@@ -1208,6 +1211,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1211
OPT_STRING_LIST(0, "reference", &reference,
1212
N_("repo"),
1213
N_("reference repository")),
1214
+ OPT_BOOL(0, "dissociate", &dissociate,
1215
+ N_("use --reference only while cloning")),
1216
OPT_STRING(0, "depth", &depth,
1217
N_("string"),
1218
N_("depth for shallow clones")),
@@ -1247,7 +1252,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1252
1253
prepare_possible_alternates(name, &reference);
1254
1250
- if (clone_submodule(path, sm_gitdir, url, depth, &reference,
1255
+ if (clone_submodule(path, sm_gitdir, url, depth, &reference, dissociate,
1256
quiet, progress))
1257
die(_("clone of '%s' into submodule path '%s' failed"),
1258
url, path);
@@ -1300,6 +1305,7 @@ struct submodule_update_clone {
1305
int quiet;
1306
int recommend_shallow;
1307
struct string_list references;
1308
+ int dissociate;
1309
const char *depth;
1310
const char *recursive_prefix;
1311
const char *prefix;
@@ -1315,7 +1321,7 @@ struct submodule_update_clone {
1321
int failed_clones_nr, failed_clones_alloc;
1322
};
1323
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
1318
- SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, \
1324
+ SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
1325
NULL, NULL, NULL, \
1326
STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
1327
@@ -1442,6 +1448,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
1448
for_each_string_list_item(item, &suc->references)
1449
argv_array_pushl(&child->args, "--reference", item->string, NULL);
1450
}
1451
+ if (suc->dissociate)
1452
+ argv_array_push(&child->args, "--dissociate");
1453
if (suc->depth)
1454
argv_array_push(&child->args, suc->depth);
1455
@@ -1575,6 +1583,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1583
N_("rebase, merge, checkout or none")),
1584
OPT_STRING_LIST(0, "reference", &suc.references, N_("repo"),
1585
N_("reference repository")),
1586
+ OPT_BOOL(0, "dissociate", &suc.dissociate,
1587
+ N_("use --reference only while cloning")),
1588
OPT_STRING(0, "depth", &suc.depth, "<depth>",
1589
N_("Create a shallow clone truncated to the "
1590
"specified number of revisions")),
git-submodule.sh
+9
-1
@@ -42,6 +42,7 @@ prefix=
42
custom_name=
43
depth=
44
progress=
45
+dissociate=
46
47
die_if_unmatched ()
48
{
@@ -128,6 +129,9 @@ cmd_add()
129
--reference=*)
130
reference_path="${1#--reference=}"
131
;;
132
+ --dissociate)
133
+ dissociate=1
134
+ ;;
135
--name)
136
case "$2" in '') usage ;; esac
137
custom_name=$2
@@ -258,7 +262,7 @@ or you are unsure what this means choose another name with the '--name' option."
262
eval_gettextln "Reactivating local git directory for submodule '\$sm_name'."
263
fi
264
fi
261
- git submodule--helper clone ${GIT_QUIET:+--quiet} ${progress:+"--progress"} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${depth:+"$depth"} || exit
265
+ git submodule--helper clone ${GIT_QUIET:+--quiet} ${progress:+"--progress"} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${dissociate:+"--dissociate"} ${depth:+"$depth"} || exit
266
(
267
sanitize_submodule_env
268
cd "$sm_path" &&
@@ -493,6 +497,9 @@ cmd_update()
497
--reference=*)
498
reference="$1"
499
;;
500
+ --dissociate)
501
+ dissociate=1
502
+ ;;
503
-m|--merge)
504
update="merge"
505
;;
@@ -550,6 +557,7 @@ cmd_update()
557
${prefix:+--recursive-prefix "$prefix"} \
558
${update:+--update "$update"} \
559
${reference:+"$reference"} \
560
+ ${dissociate:+"--dissociate"} \
561
${depth:+--depth "$depth"} \
562
$recommend_shallow \
563
$jobs \
t/t7408-submodule-reference.sh
+17
@@ -59,6 +59,16 @@ test_expect_success 'submodule add --reference uses alternates' '
59
test_alternate_is_used super/.git/modules/sub/objects/info/alternates super/sub
60
'
61
62
+test_expect_success 'submodule add --reference with --dissociate does not use alternates' '
63
+ (
64
+ cd super &&
65
+ git submodule add --reference ../B --dissociate "file://$base_dir/A" sub-dissociate &&
66
+ git commit -m B-super-added &&
67
+ git repack -ad
68
+ ) &&
69
+ test_path_is_missing super/.git/modules/sub-dissociate/objects/info/alternates
70
+'
71
+
72
test_expect_success 'that reference gets used with add' '
73
(
74
cd super/sub &&
@@ -82,6 +92,13 @@ test_expect_success 'updating superproject keeps alternates' '
92
test_alternate_is_used super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
93
'
94
95
+test_expect_success 'updating superproject with --dissociate does not keep alternates' '
96
+ test_when_finished "rm -rf super-clone" &&
97
+ git clone super super-clone &&
98
+ git -C super-clone submodule update --init --reference ../B --dissociate &&
99
+ test_path_is_missing super-clone/.git/modules/sub/objects/info/alternates
100
+'
101
+
102
test_expect_success 'submodules use alternates when cloning a superproject' '
103
test_when_finished "rm -rf super-clone" &&
104
git clone --reference super --recursive super super-clone &&