Skip to content

Commit 2a98a87

Browse files
committed
Merge branch 'cf/submodule-progress-dissociate'
"git submodule update" and "git submodule add" supported the "--reference" option to borrow objects from a neighbouring local repository like "git clone" does, but lacked the more recent invention "--dissociate". Also "git submodule add" has been taught to take the "--progress" option. * cf/submodule-progress-dissociate: submodule: add --dissociate option to add/update commands submodule: add --progress option to add command submodule: clean up substitutions in script
2 parents 4ce7218 + a0ef293 commit 2a98a87

File tree

5 files changed

+78
-9
lines changed

5 files changed

+78
-9
lines changed

Documentation/git-submodule.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ OPTIONS
239239
--quiet::
240240
Only print error messages.
241241

242+
--progress::
243+
This option is only valid for add and update commands.
244+
Progress status is reported on the standard error stream
245+
by default when it is attached to a terminal, unless -q
246+
is specified. This flag forces progress status even if the
247+
standard error stream is not directed to a terminal.
248+
242249
--all::
243250
This option is only valid for the deinit command. Unregister all
244251
submodules in the working tree.
@@ -362,7 +369,15 @@ the submodule itself.
362369
this option will be passed to the linkgit:git-clone[1] command.
363370
+
364371
*NOTE*: Do *not* use this option unless you have read the note
365-
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.
366381

367382
--recursive::
368383
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
@@ -1065,7 +1065,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix)
10651065
}
10661066

10671067
static int clone_submodule(const char *path, const char *gitdir, const char *url,
1068-
const char *depth, struct string_list *reference,
1068+
const char *depth, struct string_list *reference, int dissociate,
10691069
int quiet, int progress)
10701070
{
10711071
struct child_process cp = CHILD_PROCESS_INIT;
@@ -1084,6 +1084,8 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url
10841084
argv_array_pushl(&cp.args, "--reference",
10851085
item->string, NULL);
10861086
}
1087+
if (dissociate)
1088+
argv_array_push(&cp.args, "--dissociate");
10871089
if (gitdir && *gitdir)
10881090
argv_array_pushl(&cp.args, "--separate-git-dir", gitdir, NULL);
10891091

@@ -1199,6 +1201,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
11991201
char *p, *path = NULL, *sm_gitdir;
12001202
struct strbuf sb = STRBUF_INIT;
12011203
struct string_list reference = STRING_LIST_INIT_NODUP;
1204+
int dissociate = 0;
12021205
char *sm_alternate = NULL, *error_strategy = NULL;
12031206

12041207
struct option module_clone_options[] = {
@@ -1217,6 +1220,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
12171220
OPT_STRING_LIST(0, "reference", &reference,
12181221
N_("repo"),
12191222
N_("reference repository")),
1223+
OPT_BOOL(0, "dissociate", &dissociate,
1224+
N_("use --reference only while cloning")),
12201225
OPT_STRING(0, "depth", &depth,
12211226
N_("string"),
12221227
N_("depth for shallow clones")),
@@ -1256,7 +1261,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
12561261

12571262
prepare_possible_alternates(name, &reference);
12581263

1259-
if (clone_submodule(path, sm_gitdir, url, depth, &reference,
1264+
if (clone_submodule(path, sm_gitdir, url, depth, &reference, dissociate,
12601265
quiet, progress))
12611266
die(_("clone of '%s' into submodule path '%s' failed"),
12621267
url, path);
@@ -1308,6 +1313,7 @@ struct submodule_update_clone {
13081313
int quiet;
13091314
int recommend_shallow;
13101315
struct string_list references;
1316+
int dissociate;
13111317
const char *depth;
13121318
const char *recursive_prefix;
13131319
const char *prefix;
@@ -1323,7 +1329,7 @@ struct submodule_update_clone {
13231329
int failed_clones_nr, failed_clones_alloc;
13241330
};
13251331
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
1326-
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, \
1332+
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
13271333
NULL, NULL, NULL, \
13281334
STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
13291335

@@ -1450,6 +1456,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
14501456
for_each_string_list_item(item, &suc->references)
14511457
argv_array_pushl(&child->args, "--reference", item->string, NULL);
14521458
}
1459+
if (suc->dissociate)
1460+
argv_array_push(&child->args, "--dissociate");
14531461
if (suc->depth)
14541462
argv_array_push(&child->args, suc->depth);
14551463

@@ -1583,6 +1591,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
15831591
N_("rebase, merge, checkout or none")),
15841592
OPT_STRING_LIST(0, "reference", &suc.references, N_("repo"),
15851593
N_("reference repository")),
1594+
OPT_BOOL(0, "dissociate", &suc.dissociate,
1595+
N_("use --reference only while cloning")),
15861596
OPT_STRING(0, "depth", &suc.depth, "<depth>",
15871597
N_("Create a shallow clone truncated to the "
15881598
"specified number of revisions")),

git-submodule.sh

Lines changed: 16 additions & 5 deletions
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
{
@@ -117,6 +118,9 @@ cmd_add()
117118
-q|--quiet)
118119
GIT_QUIET=1
119120
;;
121+
--progress)
122+
progress=1
123+
;;
120124
--reference)
121125
case "$2" in '') usage ;; esac
122126
reference_path=$2
@@ -125,6 +129,9 @@ cmd_add()
125129
--reference=*)
126130
reference_path="${1#--reference=}"
127131
;;
132+
--dissociate)
133+
dissociate=1
134+
;;
128135
--name)
129136
case "$2" in '') usage ;; esac
130137
custom_name=$2
@@ -260,7 +267,7 @@ or you are unsure what this means choose another name with the '--name' option."
260267
eval_gettextln "Reactivating local git directory for submodule '\$sm_name'."
261268
fi
262269
fi
263-
git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${depth:+"$depth"} || exit
270+
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
264271
(
265272
sanitize_submodule_env
266273
cd "$sm_path" &&
@@ -470,7 +477,7 @@ cmd_update()
470477
GIT_QUIET=1
471478
;;
472479
--progress)
473-
progress="--progress"
480+
progress=1
474481
;;
475482
-i|--init)
476483
init=1
@@ -495,6 +502,9 @@ cmd_update()
495502
--reference=*)
496503
reference="$1"
497504
;;
505+
--dissociate)
506+
dissociate=1
507+
;;
498508
-m|--merge)
499509
update="merge"
500510
;;
@@ -547,14 +557,15 @@ cmd_update()
547557

548558
{
549559
git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
550-
${progress:+"$progress"} \
560+
${progress:+"--progress"} \
551561
${wt_prefix:+--prefix "$wt_prefix"} \
552562
${prefix:+--recursive-prefix "$prefix"} \
553563
${update:+--update "$update"} \
554564
${reference:+"$reference"} \
565+
${dissociate:+"--dissociate"} \
555566
${depth:+--depth "$depth"} \
556-
${recommend_shallow:+"$recommend_shallow"} \
557-
${jobs:+$jobs} \
567+
$recommend_shallow \
568+
$jobs \
558569
"$@" || echo "#unmatched" $?
559570
} | {
560571
err=

t/t7400-submodule-basic.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ test_expect_success 'submodule add' '
126126
test_cmp empty untracked
127127
'
128128

129+
test_create_repo parent &&
130+
test_commit -C parent one
131+
132+
test_expect_success 'redirected submodule add does not show progress' '
133+
git -C addtest submodule add "file://$submodurl/parent" submod-redirected \
134+
2>err &&
135+
! grep % err &&
136+
test_i18ngrep ! "Checking connectivity" err
137+
'
138+
139+
test_expect_success 'redirected submodule add --progress does show progress' '
140+
git -C addtest submodule add --progress "file://$submodurl/parent" \
141+
submod-redirected-progress 2>err && \
142+
grep % err
143+
'
144+
129145
test_expect_success 'submodule add to .gitignored path fails' '
130146
(
131147
cd addtest-ignore &&

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)