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>
Stefan Beller committed
May 26, 2016 at 14:59 UTC
abed000acafd8aa86e02bcbb65fc1a8e4f06b8a0
4 files changed
+75
-4
Documentation/git-submodule.txt
+9
-2
@@ -15,8 +15,9 @@ SYNOPSIS
15
'git submodule' [--quiet] init [--] [<path>...]
16
'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...)
17
'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>...]
21
'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
22
[commit] [--] [<path>...]
23
'git submodule' [--quiet] foreach [--recursive] <command>
@@ -384,6 +385,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
385
clone with a history truncated to the specified number of revisions.
386
See linkgit:git-clone[1]
387
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
+
394
-j <n>::
395
--jobs <n>::
396
This option is only valid for the update command.
builtin/submodule--helper.c
+6
-1
@@ -581,6 +581,7 @@ struct submodule_update_clone {
581
582
/* configuration parameters which are passed on to the children */
583
int quiet;
584
+ int recommend_shallow;
585
const char *reference;
586
const char *depth;
587
const char *recursive_prefix;
@@ -593,7 +594,7 @@ struct submodule_update_clone {
594
unsigned quickstop : 1;
595
};
596
#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, \
598
STRING_LIST_INIT_DUP, 0}
599
600
@@ -698,6 +699,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
699
argv_array_push(&child->args, "--quiet");
700
if (suc->prefix)
701
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");
704
argv_array_pushl(&child->args, "--path", sub->path, NULL);
705
argv_array_pushl(&child->args, "--name", sub->name, NULL);
706
argv_array_pushl(&child->args, "--url", url, NULL);
@@ -780,6 +783,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
783
"specified number of revisions")),
784
OPT_INTEGER('j', "jobs", &max_jobs,
785
N_("parallel jobs")),
786
+ OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
787
+ N_("whether the initial clone should follow the shallow recommendation")),
788
OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
789
OPT_END()
790
};
git-submodule.sh
+8
-1
@@ -9,7 +9,7 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re
9
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
10
or: $dashless [--quiet] init [--] [<path>...]
11
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>...]
13
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
14
or: $dashless [--quiet] foreach [--recursive] <command>
15
or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
@@ -559,6 +559,12 @@ cmd_update()
559
--checkout)
560
update="checkout"
561
;;
562
+ --recommend-shallow)
563
+ recommend_shallow="--recommend-shallow"
564
+ ;;
565
+ --no-recommend-shallow)
566
+ recommend_shallow="--no-recommend-shallow"
567
+ ;;
568
--depth)
569
case "$2" in '') usage ;; esac
570
depth="--depth=$2"
@@ -601,6 +607,7 @@ cmd_update()
607
${update:+--update "$update"} \
608
${reference:+--reference "$reference"} \
609
${depth:+--depth "$depth"} \
610
+ ${recommend_shallow:+"$recommend_shallow"} \
611
${jobs:+$jobs} \
612
"$@" || echo "#unmatched"
613
} | {
t/t5614-clone-submodules.sh
+52
@@ -82,4 +82,56 @@ test_expect_success 'non shallow clone with shallow submodule' '
82
)
83
'
84
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
+
137
test_done