Skip to content

Commit a0ef293

Browse files
kcghostgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6d33e1c commit a0ef293

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

Documentation/git-submodule.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,15 @@ the submodule itself.
369369
this option will be passed to the linkgit:git-clone[1] command.
370370
+
371371
*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.
373381

374382
--recursive::
375383
This option is only valid for foreach, update, status and sync commands.

builtin/submodule--helper.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix)
10561056
}
10571057

10581058
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,
10601060
int quiet, int progress)
10611061
{
10621062
struct child_process cp = CHILD_PROCESS_INIT;
@@ -1075,6 +1075,8 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
10751075
argv_array_pushl(&cp.args, "--reference",
10761076
item->string, NULL);
10771077
}
1078+
if (dissociate)
1079+
argv_array_push(&cp.args, "--dissociate");
10781080
if (gitdir && *gitdir)
10791081
argv_array_pushl(&cp.args, "--separate-git-dir", gitdir, NULL);
10801082

@@ -1190,6 +1192,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
11901192
char *p, *path = NULL, *sm_gitdir;
11911193
struct strbuf sb = STRBUF_INIT;
11921194
struct string_list reference = STRING_LIST_INIT_NODUP;
1195+
int dissociate = 0;
11931196
char *sm_alternate = NULL, *error_strategy = NULL;
11941197

11951198
struct option module_clone_options[] = {
@@ -1208,6 +1211,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
12081211
OPT_STRING_LIST(0, "reference", &reference,
12091212
N_("repo"),
12101213
N_("reference repository")),
1214+
OPT_BOOL(0, "dissociate", &dissociate,
1215+
N_("use --reference only while cloning")),
12111216
OPT_STRING(0, "depth", &depth,
12121217
N_("string"),
12131218
N_("depth for shallow clones")),
@@ -1247,7 +1252,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
12471252

12481253
prepare_possible_alternates(name, &reference);
12491254

1250-
if (clone_submodule(path, sm_gitdir, url, depth, &reference,
1255+
if (clone_submodule(path, sm_gitdir, url, depth, &reference, dissociate,
12511256
quiet, progress))
12521257
die(_("clone of '%s' into submodule path '%s' failed"),
12531258
url, path);
@@ -1300,6 +1305,7 @@ struct submodule_update_clone {
13001305
int quiet;
13011306
int recommend_shallow;
13021307
struct string_list references;
1308+
int dissociate;
13031309
const char *depth;
13041310
const char *recursive_prefix;
13051311
const char *prefix;
@@ -1315,7 +1321,7 @@ struct submodule_update_clone {
13151321
int failed_clones_nr, failed_clones_alloc;
13161322
};
13171323
#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, \
13191325
NULL, NULL, NULL, \
13201326
STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
13211327

@@ -1442,6 +1448,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
14421448
for_each_string_list_item(item, &suc->references)
14431449
argv_array_pushl(&child->args, "--reference", item->string, NULL);
14441450
}
1451+
if (suc->dissociate)
1452+
argv_array_push(&child->args, "--dissociate");
14451453
if (suc->depth)
14461454
argv_array_push(&child->args, suc->depth);
14471455

@@ -1575,6 +1583,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
15751583
N_("rebase, merge, checkout or none")),
15761584
OPT_STRING_LIST(0, "reference", &suc.references, N_("repo"),
15771585
N_("reference repository")),
1586+
OPT_BOOL(0, "dissociate", &suc.dissociate,
1587+
N_("use --reference only while cloning")),
15781588
OPT_STRING(0, "depth", &suc.depth, "<depth>",
15791589
N_("Create a shallow clone truncated to the "
15801590
"specified number of revisions")),

git-submodule.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ prefix=
4242
custom_name=
4343
depth=
4444
progress=
45+
dissociate=
4546

4647
die_if_unmatched ()
4748
{
@@ -128,6 +129,9 @@ cmd_add()
128129
--reference=*)
129130
reference_path="${1#--reference=}"
130131
;;
132+
--dissociate)
133+
dissociate=1
134+
;;
131135
--name)
132136
case "$2" in '') usage ;; esac
133137
custom_name=$2
@@ -258,7 +262,7 @@ or you are unsure what this means choose another name with the '--name' option."
258262
eval_gettextln "Reactivating local git directory for submodule '\$sm_name'."
259263
fi
260264
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
262266
(
263267
sanitize_submodule_env
264268
cd "$sm_path" &&
@@ -493,6 +497,9 @@ cmd_update()
493497
--reference=*)
494498
reference="$1"
495499
;;
500+
--dissociate)
501+
dissociate=1
502+
;;
496503
-m|--merge)
497504
update="merge"
498505
;;
@@ -550,6 +557,7 @@ cmd_update()
550557
${prefix:+--recursive-prefix "$prefix"} \
551558
${update:+--update "$update"} \
552559
${reference:+"$reference"} \
560+
${dissociate:+"--dissociate"} \
553561
${depth:+--depth "$depth"} \
554562
$recommend_shallow \
555563
$jobs \

t/t7408-submodule-reference.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ test_expect_success 'submodule add --reference uses alternates' '
5959
test_alternate_is_used super/.git/modules/sub/objects/info/alternates super/sub
6060
'
6161

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+
6272
test_expect_success 'that reference gets used with add' '
6373
(
6474
cd super/sub &&
@@ -82,6 +92,13 @@ test_expect_success 'updating superproject keeps alternates' '
8292
test_alternate_is_used super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
8393
'
8494

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+
85102
test_expect_success 'submodules use alternates when cloning a superproject' '
86103
test_when_finished "rm -rf super-clone" &&
87104
git clone --reference super --recursive super super-clone &&

0 commit comments

Comments
 (0)