Skip to content

Commit abed000

Browse files
stefanbellergitster
authored andcommitted
submodule update: learn --[no-]recommend-shallow option
Sometimes the history of a submodule is not considered important by the projects upstream. To make it easier for downstream users, allow a boolean field 'submodule.<name>.shallow' in .gitmodules, which can be used to recommend whether upstream considers the history important. This field is honored in the initial clone by default, it can be ignored by giving the `--no-recommend-shallow` option. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 37f52e9 commit abed000

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

Documentation/git-submodule.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ SYNOPSIS
1515
'git submodule' [--quiet] init [--] [<path>...]
1616
'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...)
1717
'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
18-
[-f|--force] [--rebase|--merge] [--reference <repository>]
19-
[--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]
18+
[--[no-]recommend-shallow] [-f|--force] [--rebase|--merge]
19+
[--reference <repository>] [--depth <depth>] [--recursive]
20+
[--jobs <n>] [--] [<path>...]
2021
'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
2122
[commit] [--] [<path>...]
2223
'git submodule' [--quiet] foreach [--recursive] <command>
@@ -384,6 +385,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
384385
clone with a history truncated to the specified number of revisions.
385386
See linkgit:git-clone[1]
386387

388+
--[no-]recommend-shallow::
389+
This option is only valid for the update command.
390+
The initial clone of a submodule will use the recommended
391+
`submodule.<name>.shallow` as provided by the .gitmodules file
392+
by default. To ignore the suggestions use `--no-recommend-shallow`.
393+
387394
-j <n>::
388395
--jobs <n>::
389396
This option is only valid for the update command.

builtin/submodule--helper.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ struct submodule_update_clone {
581581

582582
/* configuration parameters which are passed on to the children */
583583
int quiet;
584+
int recommend_shallow;
584585
const char *reference;
585586
const char *depth;
586587
const char *recursive_prefix;
@@ -593,7 +594,7 @@ struct submodule_update_clone {
593594
unsigned quickstop : 1;
594595
};
595596
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
596-
SUBMODULE_UPDATE_STRATEGY_INIT, 0, NULL, NULL, NULL, NULL, \
597+
SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, NULL, NULL, NULL, NULL, \
597598
STRING_LIST_INIT_DUP, 0}
598599

599600

@@ -698,6 +699,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
698699
argv_array_push(&child->args, "--quiet");
699700
if (suc->prefix)
700701
argv_array_pushl(&child->args, "--prefix", suc->prefix, NULL);
702+
if (suc->recommend_shallow && sub->recommend_shallow == 1)
703+
argv_array_push(&child->args, "--depth=1");
701704
argv_array_pushl(&child->args, "--path", sub->path, NULL);
702705
argv_array_pushl(&child->args, "--name", sub->name, NULL);
703706
argv_array_pushl(&child->args, "--url", url, NULL);
@@ -780,6 +783,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
780783
"specified number of revisions")),
781784
OPT_INTEGER('j', "jobs", &max_jobs,
782785
N_("parallel jobs")),
786+
OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
787+
N_("whether the initial clone should follow the shallow recommendation")),
783788
OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
784789
OPT_END()
785790
};

git-submodule.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re
99
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
1010
or: $dashless [--quiet] init [--] [<path>...]
1111
or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
12-
or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...]
12+
or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
1313
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
1414
or: $dashless [--quiet] foreach [--recursive] <command>
1515
or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
@@ -559,6 +559,12 @@ cmd_update()
559559
--checkout)
560560
update="checkout"
561561
;;
562+
--recommend-shallow)
563+
recommend_shallow="--recommend-shallow"
564+
;;
565+
--no-recommend-shallow)
566+
recommend_shallow="--no-recommend-shallow"
567+
;;
562568
--depth)
563569
case "$2" in '') usage ;; esac
564570
depth="--depth=$2"
@@ -601,6 +607,7 @@ cmd_update()
601607
${update:+--update "$update"} \
602608
${reference:+--reference "$reference"} \
603609
${depth:+--depth "$depth"} \
610+
${recommend_shallow:+"$recommend_shallow"} \
604611
${jobs:+$jobs} \
605612
"$@" || echo "#unmatched"
606613
} | {

t/t5614-clone-submodules.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,56 @@ test_expect_success 'non shallow clone with shallow submodule' '
8282
)
8383
'
8484

85+
test_expect_success 'clone follows shallow recommendation' '
86+
test_when_finished "rm -rf super_clone" &&
87+
git config -f .gitmodules submodule.sub.shallow true &&
88+
git add .gitmodules &&
89+
git commit -m "recommed shallow for sub" &&
90+
git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
91+
(
92+
cd super_clone &&
93+
git log --oneline >lines &&
94+
test_line_count = 4 lines
95+
) &&
96+
(
97+
cd super_clone/sub &&
98+
git log --oneline >lines &&
99+
test_line_count = 1 lines
100+
)
101+
'
102+
103+
test_expect_success 'get unshallow recommended shallow submodule' '
104+
test_when_finished "rm -rf super_clone" &&
105+
git clone --no-local "file://$pwd/." super_clone &&
106+
(
107+
cd super_clone &&
108+
git submodule update --init --no-recommend-shallow &&
109+
git log --oneline >lines &&
110+
test_line_count = 4 lines
111+
) &&
112+
(
113+
cd super_clone/sub &&
114+
git log --oneline >lines &&
115+
test_line_count = 3 lines
116+
)
117+
'
118+
119+
test_expect_success 'clone follows non shallow recommendation' '
120+
test_when_finished "rm -rf super_clone" &&
121+
git config -f .gitmodules submodule.sub.shallow false &&
122+
git add .gitmodules &&
123+
git commit -m "recommed non shallow for sub" &&
124+
git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
125+
(
126+
cd super_clone &&
127+
git log --oneline >lines &&
128+
test_line_count = 5 lines
129+
) &&
130+
(
131+
cd super_clone/sub &&
132+
git log --oneline >lines &&
133+
test_line_count = 3 lines
134+
)
135+
'
136+
85137
test_done

0 commit comments

Comments
 (0)