]>
Commit | Line | Data |
---|---|---|
70c7ac22 LH |
1 | #!/bin/sh |
2 | # | |
4c8a9db6 | 3 | # git-submodule.sh: add, init, update or list git submodules |
70c7ac22 LH |
4 | # |
5 | # Copyright (c) 2007 Lars Hjemli | |
6 | ||
1d5bec8b | 7 | dashless=$(basename "$0" | sed -e 's/-/ /') |
68cabbfd DL |
8 | USAGE="[--quiet] [--cached] |
9 | or: $dashless [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>] | |
64b19ffe | 10 | or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...] |
1d5bec8b | 11 | or: $dashless [--quiet] init [--] [<path>...] |
f6a52799 | 12 | or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...) |
132f600b | 13 | or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...] |
b57e8119 | 14 | or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path> |
26b06100 | 15 | or: $dashless [--quiet] set-url [--] <path> <newurl> |
adc54235 | 16 | or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] |
15fc56a8 | 17 | or: $dashless [--quiet] foreach [--recursive] <command> |
c32eaa8a SB |
18 | or: $dashless [--quiet] sync [--recursive] [--] [<path>...] |
19 | or: $dashless [--quiet] absorbgitdirs [--] [<path>...]" | |
8f321a39 | 20 | OPTIONS_SPEC= |
091a6eb0 | 21 | SUBDIRECTORY_OK=Yes |
70c7ac22 LH |
22 | . git-sh-setup |
23 | require_work_tree | |
091a6eb0 JK |
24 | wt_prefix=$(git rev-parse --show-prefix) |
25 | cd_to_toplevel | |
70c7ac22 | 26 | |
f1762d77 BW |
27 | # Tell the rest of git that any URLs we get don't come |
28 | # directly from the user, so it can apply policy as appropriate. | |
29 | GIT_PROTOCOL_FROM_USER=0 | |
30 | export GIT_PROTOCOL_FROM_USER | |
33cfccbb | 31 | |
5c08dbbd | 32 | command= |
ecda0723 | 33 | branch= |
d27b876b | 34 | force= |
d92a3959 | 35 | reference= |
70c7ac22 | 36 | cached= |
48bb3033 GP |
37 | recursive= |
38 | init= | |
0060fd15 | 39 | require_init= |
1c244f6e | 40 | files= |
06b1abb5 | 41 | remote= |
31ca3ac3 | 42 | nofetch= |
32948425 | 43 | update= |
15fc56a8 | 44 | prefix= |
73b0898d | 45 | custom_name= |
275cd184 | 46 | depth= |
72c5f883 | 47 | progress= |
a0ef2934 | 48 | dissociate= |
132f600b | 49 | single_branch= |
65d100c4 LX |
50 | jobs= |
51 | recommend_shallow= | |
70c7ac22 | 52 | |
be9d0a3a HV |
53 | die_if_unmatched () |
54 | { | |
55 | if test "$1" = "#unmatched" | |
56 | then | |
c4c02bf1 | 57 | exit ${2:-1} |
be9d0a3a HV |
58 | fi |
59 | } | |
60 | ||
862ae6cd RS |
61 | isnumber() |
62 | { | |
63 | n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" | |
64 | } | |
65 | ||
14111fc4 JK |
66 | # Sanitize the local git environment for use within a submodule. We |
67 | # can't simply use clear_local_git_env since we want to preserve some | |
68 | # of the settings from GIT_CONFIG_PARAMETERS. | |
69 | sanitize_submodule_env() | |
70 | { | |
89044baa | 71 | save_config=$GIT_CONFIG_PARAMETERS |
14111fc4 | 72 | clear_local_git_env |
89044baa | 73 | GIT_CONFIG_PARAMETERS=$save_config |
860cba61 | 74 | export GIT_CONFIG_PARAMETERS |
14111fc4 JK |
75 | } |
76 | ||
ecda0723 SV |
77 | # |
78 | # Add a new submodule to the working tree, .gitmodules and the index | |
79 | # | |
ec05df35 | 80 | # $@ = repo path |
ecda0723 SV |
81 | # |
82 | # optional branch is stored in global branch variable | |
83 | # | |
23a485e3 | 84 | cmd_add() |
ecda0723 | 85 | { |
5c08dbbd | 86 | # parse $args after "submodule ... add". |
091a6eb0 | 87 | reference_path= |
5c08dbbd JH |
88 | while test $# -ne 0 |
89 | do | |
90 | case "$1" in | |
91 | -b | --branch) | |
92 | case "$2" in '') usage ;; esac | |
93 | branch=$2 | |
94 | shift | |
95 | ;; | |
d27b876b JL |
96 | -f | --force) |
97 | force=$1 | |
98 | ;; | |
5c08dbbd | 99 | -q|--quiet) |
2e6a30ef | 100 | GIT_QUIET=1 |
5c08dbbd | 101 | ;; |
6d33e1c2 CF |
102 | --progress) |
103 | progress=1 | |
104 | ;; | |
d92a3959 MT |
105 | --reference) |
106 | case "$2" in '') usage ;; esac | |
091a6eb0 | 107 | reference_path=$2 |
d92a3959 MT |
108 | shift |
109 | ;; | |
110 | --reference=*) | |
091a6eb0 | 111 | reference_path="${1#--reference=}" |
d92a3959 | 112 | ;; |
a0ef2934 CF |
113 | --dissociate) |
114 | dissociate=1 | |
115 | ;; | |
73b0898d JL |
116 | --name) |
117 | case "$2" in '') usage ;; esac | |
118 | custom_name=$2 | |
119 | shift | |
120 | ;; | |
275cd184 FG |
121 | --depth) |
122 | case "$2" in '') usage ;; esac | |
123 | depth="--depth=$2" | |
124 | shift | |
125 | ;; | |
126 | --depth=*) | |
127 | depth=$1 | |
128 | ;; | |
5c08dbbd JH |
129 | --) |
130 | shift | |
131 | break | |
132 | ;; | |
133 | -*) | |
134 | usage | |
135 | ;; | |
136 | *) | |
137 | break | |
138 | ;; | |
139 | esac | |
140 | shift | |
141 | done | |
142 | ||
a6226fd7 | 143 | if test -z "$1" |
76e9bdc4 | 144 | then |
ecda0723 SV |
145 | usage |
146 | fi | |
147 | ||
a6226fd7 | 148 | git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" |
ecda0723 SV |
149 | } |
150 | ||
19a31f9c ML |
151 | # |
152 | # Execute an arbitrary command sequence in each checked out | |
153 | # submodule | |
154 | # | |
155 | # $@ = command to execute | |
156 | # | |
157 | cmd_foreach() | |
158 | { | |
1d5bec8b JH |
159 | # parse $args after "submodule ... foreach". |
160 | while test $# -ne 0 | |
161 | do | |
162 | case "$1" in | |
163 | -q|--quiet) | |
164 | GIT_QUIET=1 | |
165 | ;; | |
15fc56a8 JH |
166 | --recursive) |
167 | recursive=1 | |
168 | ;; | |
1d5bec8b JH |
169 | -*) |
170 | usage | |
171 | ;; | |
172 | *) | |
173 | break | |
174 | ;; | |
175 | esac | |
176 | shift | |
177 | done | |
178 | ||
1cf823d8 | 179 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" |
19a31f9c ML |
180 | } |
181 | ||
70c7ac22 | 182 | # |
211b7f19 | 183 | # Register submodules in .git/config |
70c7ac22 LH |
184 | # |
185 | # $@ = requested paths (default to all) | |
186 | # | |
23a485e3 | 187 | cmd_init() |
70c7ac22 | 188 | { |
5c08dbbd JH |
189 | # parse $args after "submodule ... init". |
190 | while test $# -ne 0 | |
191 | do | |
192 | case "$1" in | |
193 | -q|--quiet) | |
2e6a30ef | 194 | GIT_QUIET=1 |
5c08dbbd JH |
195 | ;; |
196 | --) | |
197 | shift | |
198 | break | |
199 | ;; | |
200 | -*) | |
201 | usage | |
202 | ;; | |
203 | *) | |
204 | break | |
205 | ;; | |
206 | esac | |
207 | shift | |
208 | done | |
209 | ||
a282f5a9 | 210 | git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" |
70c7ac22 LH |
211 | } |
212 | ||
cf419828 JL |
213 | # |
214 | # Unregister submodules from .git/config and remove their work tree | |
215 | # | |
cf419828 JL |
216 | cmd_deinit() |
217 | { | |
218 | # parse $args after "submodule ... deinit". | |
f6a52799 | 219 | deinit_all= |
cf419828 JL |
220 | while test $# -ne 0 |
221 | do | |
222 | case "$1" in | |
223 | -f|--force) | |
224 | force=$1 | |
225 | ;; | |
226 | -q|--quiet) | |
227 | GIT_QUIET=1 | |
228 | ;; | |
f6a52799 SB |
229 | --all) |
230 | deinit_all=t | |
231 | ;; | |
cf419828 JL |
232 | --) |
233 | shift | |
234 | break | |
235 | ;; | |
236 | -*) | |
237 | usage | |
238 | ;; | |
239 | *) | |
240 | break | |
241 | ;; | |
242 | esac | |
243 | shift | |
244 | done | |
245 | ||
1cf823d8 | 246 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" |
cf419828 JL |
247 | } |
248 | ||
66d36b94 JK |
249 | # usage: fetch_in_submodule <module_path> [<depth>] [<sha1>] |
250 | # Because arguments are positional, use an empty string to omit <depth> | |
251 | # but include <sha1>. | |
fb43e31f | 252 | fetch_in_submodule () ( |
01e1d544 | 253 | sanitize_submodule_env && |
fb43e31f | 254 | cd "$1" && |
1c151807 ÆAB |
255 | if test $# -eq 3 |
256 | then | |
62af4bdd | 257 | echo "$3" | git fetch ${GIT_QUIET:+--quiet} --stdin ${2:+"$2"} |
1c151807 | 258 | else |
62af4bdd | 259 | git fetch ${GIT_QUIET:+--quiet} ${2:+"$2"} |
1c151807 | 260 | fi |
fb43e31f SB |
261 | ) |
262 | ||
70c7ac22 | 263 | # |
211b7f19 | 264 | # Update each submodule path to correct revision, using clone and checkout as needed |
70c7ac22 LH |
265 | # |
266 | # $@ = requested paths (default to all) | |
267 | # | |
23a485e3 | 268 | cmd_update() |
70c7ac22 | 269 | { |
5c08dbbd JH |
270 | # parse $args after "submodule ... update". |
271 | while test $# -ne 0 | |
272 | do | |
273 | case "$1" in | |
274 | -q|--quiet) | |
2e6a30ef | 275 | GIT_QUIET=1 |
5c08dbbd | 276 | ;; |
e84c3cf3 | 277 | -v) |
3ad0401e | 278 | unset GIT_QUIET |
e84c3cf3 | 279 | ;; |
72c5f883 | 280 | --progress) |
c7199e3a | 281 | progress=1 |
72c5f883 | 282 | ;; |
be4d2c83 | 283 | -i|--init) |
d92a3959 | 284 | init=1 |
be4d2c83 | 285 | ;; |
0060fd15 JS |
286 | --require-init) |
287 | init=1 | |
288 | require_init=1 | |
289 | ;; | |
06b1abb5 TK |
290 | --remote) |
291 | remote=1 | |
292 | ;; | |
31ca3ac3 | 293 | -N|--no-fetch) |
31ca3ac3 FF |
294 | nofetch=1 |
295 | ;; | |
9db31bdf NMC |
296 | -f|--force) |
297 | force=$1 | |
298 | ;; | |
ca2cedba | 299 | -r|--rebase) |
32948425 | 300 | update="rebase" |
ca2cedba | 301 | ;; |
d92a3959 MT |
302 | --reference) |
303 | case "$2" in '') usage ;; esac | |
304 | reference="--reference=$2" | |
98dbe63d | 305 | shift |
d92a3959 MT |
306 | ;; |
307 | --reference=*) | |
308 | reference="$1" | |
d92a3959 | 309 | ;; |
a0ef2934 CF |
310 | --dissociate) |
311 | dissociate=1 | |
312 | ;; | |
42b49178 | 313 | -m|--merge) |
42b49178 JH |
314 | update="merge" |
315 | ;; | |
b13fd5c1 | 316 | --recursive) |
b13fd5c1 JH |
317 | recursive=1 |
318 | ;; | |
efc5fb6a JH |
319 | --checkout) |
320 | update="checkout" | |
321 | ;; | |
abed000a SB |
322 | --recommend-shallow) |
323 | recommend_shallow="--recommend-shallow" | |
324 | ;; | |
325 | --no-recommend-shallow) | |
326 | recommend_shallow="--no-recommend-shallow" | |
327 | ;; | |
275cd184 FG |
328 | --depth) |
329 | case "$2" in '') usage ;; esac | |
330 | depth="--depth=$2" | |
331 | shift | |
332 | ;; | |
333 | --depth=*) | |
334 | depth=$1 | |
335 | ;; | |
2335b870 SB |
336 | -j|--jobs) |
337 | case "$2" in '') usage ;; esac | |
338 | jobs="--jobs=$2" | |
339 | shift | |
340 | ;; | |
341 | --jobs=*) | |
342 | jobs=$1 | |
343 | ;; | |
132f600b ES |
344 | --single-branch) |
345 | single_branch="--single-branch" | |
346 | ;; | |
347 | --no-single-branch) | |
348 | single_branch="--no-single-branch" | |
349 | ;; | |
5c08dbbd JH |
350 | --) |
351 | shift | |
352 | break | |
353 | ;; | |
354 | -*) | |
355 | usage | |
356 | ;; | |
357 | *) | |
358 | break | |
359 | ;; | |
360 | esac | |
98dbe63d | 361 | shift |
5c08dbbd JH |
362 | done |
363 | ||
d92a3959 MT |
364 | if test -n "$init" |
365 | then | |
366 | cmd_init "--" "$@" || return | |
367 | fi | |
368 | ||
48308681 SB |
369 | { |
370 | git submodule--helper update-clone ${GIT_QUIET:+--quiet} \ | |
c7199e3a | 371 | ${progress:+"--progress"} \ |
48308681 SB |
372 | ${wt_prefix:+--prefix "$wt_prefix"} \ |
373 | ${prefix:+--recursive-prefix "$prefix"} \ | |
374 | ${update:+--update "$update"} \ | |
5f50f33e | 375 | ${reference:+"$reference"} \ |
a0ef2934 | 376 | ${dissociate:+"--dissociate"} \ |
48308681 | 377 | ${depth:+--depth "$depth"} \ |
0060fd15 | 378 | ${require_init:+--require-init} \ |
132f600b | 379 | $single_branch \ |
c7199e3a CF |
380 | $recommend_shallow \ |
381 | $jobs \ | |
a282f5a9 | 382 | -- \ |
c4c02bf1 | 383 | "$@" || echo "#unmatched" $? |
48308681 | 384 | } | { |
15ffb7cd | 385 | err= |
9eca701f | 386 | while read -r quickabort sha1 just_cloned sm_path |
70c7ac22 | 387 | do |
9eca701f | 388 | die_if_unmatched "$quickabort" "$sha1" |
48308681 | 389 | |
5d124f41 | 390 | git submodule--helper ensure-core-worktree "$sm_path" || exit 1 |
74d4731d | 391 | |
44431df0 | 392 | displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") |
091a6eb0 | 393 | |
48308681 | 394 | if test $just_cloned -eq 1 |
d851ffb9 | 395 | then |
bf2d8246 LH |
396 | subsha1= |
397 | else | |
c51f8f94 | 398 | just_cloned= |
14111fc4 | 399 | subsha1=$(sanitize_submodule_env; cd "$sm_path" && |
5be60078 | 400 | git rev-parse --verify HEAD) || |
0008d122 | 401 | die "fatal: $(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")" |
70c7ac22 | 402 | fi |
211b7f19 | 403 | |
06b1abb5 TK |
404 | if test -n "$remote" |
405 | then | |
92bbe7cc | 406 | branch=$(git submodule--helper remote-branch "$sm_path") |
06b1abb5 TK |
407 | if test -z "$nofetch" |
408 | then | |
409 | # Fetch remote before determining tracking $sha1 | |
6cbf454a | 410 | fetch_in_submodule "$sm_path" $depth || |
0008d122 | 411 | die "fatal: $(eval_gettext "Unable to fetch in submodule path '\$sm_path'")" |
06b1abb5 | 412 | fi |
e63f7b0a | 413 | remote_name=$(sanitize_submodule_env; cd "$sm_path" && git submodule--helper print-default-remote) |
14111fc4 | 414 | sha1=$(sanitize_submodule_env; cd "$sm_path" && |
06b1abb5 | 415 | git rev-parse --verify "${remote_name}/${branch}") || |
0008d122 | 416 | die "fatal: $(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")" |
06b1abb5 TK |
417 | fi |
418 | ||
c51f8f94 AR |
419 | out=$(git submodule--helper run-update-procedure \ |
420 | ${wt_prefix:+--prefix "$wt_prefix"} \ | |
421 | ${GIT_QUIET:+--quiet} \ | |
422 | ${force:+--force} \ | |
423 | ${just_cloned:+--just-cloned} \ | |
424 | ${nofetch:+--no-fetch} \ | |
425 | ${depth:+"$depth"} \ | |
426 | ${update:+--update "$update"} \ | |
427 | ${prefix:+--recursive-prefix "$prefix"} \ | |
428 | ${sha1:+--oid "$sha1"} \ | |
429 | ${subsha1:+--suboid "$subsha1"} \ | |
430 | "--" \ | |
431 | "$sm_path") | |
432 | ||
433 | # exit codes for run-update-procedure: | |
434 | # 0: update was successful, say command output | |
435 | # 1: update procedure failed, but should not die | |
436 | # 2 or 128: subcommand died during execution | |
437 | # 3: no update procedure was run | |
438 | res="$?" | |
439 | case $res in | |
440 | 0) | |
441 | say "$out" | |
442 | ;; | |
443 | 1) | |
444 | err="${err};fatal: $out" | |
445 | continue | |
446 | ;; | |
447 | 2|128) | |
448 | die_with_status $res "fatal: $out" | |
449 | ;; | |
450 | esac | |
b13fd5c1 JH |
451 | |
452 | if test -n "$recursive" | |
453 | then | |
75bf5e60 | 454 | ( |
44431df0 | 455 | prefix=$(git submodule--helper relative-path "$prefix$sm_path/" "$wt_prefix") |
3604242f | 456 | wt_prefix= |
14111fc4 | 457 | sanitize_submodule_env |
75bf5e60 | 458 | cd "$sm_path" && |
36141282 | 459 | eval cmd_update |
75bf5e60 | 460 | ) |
15ffb7cd FG |
461 | res=$? |
462 | if test $res -gt 0 | |
463 | then | |
0008d122 | 464 | die_msg="fatal: $(eval_gettext "Failed to recurse into submodule path '\$displaypath'")" |
bb9d91b4 | 465 | if test $res -ne 2 |
15ffb7cd | 466 | then |
ff968f03 | 467 | err="${err};$die_msg" |
15ffb7cd FG |
468 | continue |
469 | else | |
ff968f03 | 470 | die_with_status $res "$die_msg" |
15ffb7cd FG |
471 | fi |
472 | fi | |
b13fd5c1 | 473 | fi |
70c7ac22 | 474 | done |
15ffb7cd FG |
475 | |
476 | if test -n "$err" | |
477 | then | |
478 | OIFS=$IFS | |
479 | IFS=';' | |
480 | for e in $err | |
481 | do | |
482 | if test -n "$e" | |
483 | then | |
484 | echo >&2 "$e" | |
485 | fi | |
486 | done | |
487 | IFS=$OIFS | |
488 | exit 1 | |
489 | fi | |
490 | } | |
70c7ac22 LH |
491 | } |
492 | ||
b57e8119 DL |
493 | # |
494 | # Configures a submodule's default branch | |
495 | # | |
496 | # $@ = requested path | |
497 | # | |
498 | cmd_set_branch() { | |
2964d6e5 | 499 | default= |
b57e8119 DL |
500 | branch= |
501 | ||
502 | while test $# -ne 0 | |
503 | do | |
504 | case "$1" in | |
505 | -q|--quiet) | |
506 | # we don't do anything with this but we need to accept it | |
507 | ;; | |
508 | -d|--default) | |
2964d6e5 | 509 | default=1 |
b57e8119 DL |
510 | ;; |
511 | -b|--branch) | |
512 | case "$2" in '') usage ;; esac | |
513 | branch=$2 | |
514 | shift | |
515 | ;; | |
516 | --) | |
517 | shift | |
518 | break | |
519 | ;; | |
520 | -*) | |
521 | usage | |
522 | ;; | |
523 | *) | |
524 | break | |
525 | ;; | |
526 | esac | |
527 | shift | |
528 | done | |
529 | ||
1cf823d8 | 530 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${GIT_QUIET:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" |
b57e8119 DL |
531 | } |
532 | ||
26b06100 DL |
533 | # |
534 | # Configures a submodule's remote url | |
535 | # | |
536 | # $@ = requested path, requested url | |
537 | # | |
538 | cmd_set_url() { | |
539 | while test $# -ne 0 | |
540 | do | |
541 | case "$1" in | |
542 | -q|--quiet) | |
543 | GIT_QUIET=1 | |
544 | ;; | |
545 | --) | |
546 | shift | |
547 | break | |
548 | ;; | |
549 | -*) | |
550 | usage | |
551 | ;; | |
552 | *) | |
553 | break | |
554 | ;; | |
555 | esac | |
556 | shift | |
557 | done | |
558 | ||
1cf823d8 | 559 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@" |
26b06100 DL |
560 | } |
561 | ||
28f9af5d PY |
562 | # |
563 | # Show commit summary for submodules in index or working tree | |
564 | # | |
565 | # If '--cached' is given, show summary between index and given commit, | |
566 | # or between working tree and given commit | |
567 | # | |
568 | # $@ = [commit (default 'HEAD'),] requested paths (default all) | |
569 | # | |
570 | cmd_summary() { | |
f2dc06a3 | 571 | summary_limit=-1 |
d0f64dd4 | 572 | for_status= |
1c244f6e | 573 | diff_cmd=diff-index |
f2dc06a3 | 574 | |
28f9af5d PY |
575 | # parse $args after "submodule ... summary". |
576 | while test $# -ne 0 | |
577 | do | |
578 | case "$1" in | |
579 | --cached) | |
580 | cached="$1" | |
581 | ;; | |
1c244f6e JL |
582 | --files) |
583 | files="$1" | |
584 | ;; | |
d0f64dd4 PY |
585 | --for-status) |
586 | for_status="$1" | |
587 | ;; | |
f2dc06a3 | 588 | -n|--summary-limit) |
862ae6cd RS |
589 | summary_limit="$2" |
590 | isnumber "$summary_limit" || usage | |
f2dc06a3 PY |
591 | shift |
592 | ;; | |
862ae6cd RS |
593 | --summary-limit=*) |
594 | summary_limit="${1#--summary-limit=}" | |
595 | isnumber "$summary_limit" || usage | |
596 | ;; | |
28f9af5d PY |
597 | --) |
598 | shift | |
599 | break | |
600 | ;; | |
601 | -*) | |
602 | usage | |
603 | ;; | |
604 | *) | |
605 | break | |
606 | ;; | |
607 | esac | |
608 | shift | |
609 | done | |
bffe71f4 | 610 | |
1cf823d8 | 611 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary ${files:+--files} ${cached:+--cached} ${for_status:+--for-status} ${summary_limit:+-n $summary_limit} -- "$@" |
28f9af5d | 612 | } |
70c7ac22 | 613 | # |
941987a5 | 614 | # List all submodules, prefixed with: |
70c7ac22 LH |
615 | # - submodule not initialized |
616 | # + different revision checked out | |
617 | # | |
618 | # If --cached was specified the revision in the index will be printed | |
619 | # instead of the currently checked out revision. | |
620 | # | |
621 | # $@ = requested paths (default to all) | |
622 | # | |
23a485e3 | 623 | cmd_status() |
70c7ac22 | 624 | { |
5c08dbbd JH |
625 | # parse $args after "submodule ... status". |
626 | while test $# -ne 0 | |
627 | do | |
628 | case "$1" in | |
629 | -q|--quiet) | |
2e6a30ef | 630 | GIT_QUIET=1 |
5c08dbbd JH |
631 | ;; |
632 | --cached) | |
633 | cached=1 | |
634 | ;; | |
64b19ffe JH |
635 | --recursive) |
636 | recursive=1 | |
637 | ;; | |
5c08dbbd JH |
638 | --) |
639 | shift | |
640 | break | |
641 | ;; | |
642 | -*) | |
643 | usage | |
644 | ;; | |
645 | *) | |
646 | break | |
647 | ;; | |
648 | esac | |
649 | shift | |
650 | done | |
651 | ||
1cf823d8 | 652 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" |
70c7ac22 | 653 | } |
2327f61e DA |
654 | # |
655 | # Sync remote urls for submodules | |
656 | # This makes the value for remote.$remote.url match the value | |
657 | # specified in .gitmodules. | |
658 | # | |
659 | cmd_sync() | |
660 | { | |
661 | while test $# -ne 0 | |
662 | do | |
663 | case "$1" in | |
664 | -q|--quiet) | |
2e6a30ef | 665 | GIT_QUIET=1 |
2327f61e DA |
666 | shift |
667 | ;; | |
82f49f29 PH |
668 | --recursive) |
669 | recursive=1 | |
670 | shift | |
671 | ;; | |
2327f61e DA |
672 | --) |
673 | shift | |
674 | break | |
675 | ;; | |
676 | -*) | |
677 | usage | |
678 | ;; | |
679 | *) | |
680 | break | |
681 | ;; | |
682 | esac | |
683 | done | |
e7849a96 | 684 | |
1cf823d8 | 685 | git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" |
2327f61e | 686 | } |
70c7ac22 | 687 | |
f6f85861 SB |
688 | cmd_absorbgitdirs() |
689 | { | |
690 | git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@" | |
691 | } | |
692 | ||
5c08dbbd JH |
693 | # This loop parses the command line arguments to find the |
694 | # subcommand name to dispatch. Parsing of the subcommand specific | |
695 | # options are primarily done by the subcommand implementations. | |
696 | # Subcommand specific options such as --branch and --cached are | |
697 | # parsed here as well, for backward compatibility. | |
698 | ||
699 | while test $# != 0 && test -z "$command" | |
70c7ac22 LH |
700 | do |
701 | case "$1" in | |
26b06100 | 702 | add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs) |
5c08dbbd | 703 | command=$1 |
70c7ac22 LH |
704 | ;; |
705 | -q|--quiet) | |
2e6a30ef | 706 | GIT_QUIET=1 |
70c7ac22 | 707 | ;; |
ecda0723 SV |
708 | -b|--branch) |
709 | case "$2" in | |
710 | '') | |
711 | usage | |
712 | ;; | |
713 | esac | |
714 | branch="$2"; shift | |
715 | ;; | |
70c7ac22 | 716 | --cached) |
28f9af5d | 717 | cached="$1" |
70c7ac22 LH |
718 | ;; |
719 | --) | |
720 | break | |
721 | ;; | |
722 | -*) | |
723 | usage | |
724 | ;; | |
725 | *) | |
726 | break | |
727 | ;; | |
728 | esac | |
729 | shift | |
730 | done | |
731 | ||
5c08dbbd | 732 | # No command word defaults to "status" |
af9c9f97 RR |
733 | if test -z "$command" |
734 | then | |
735 | if test $# = 0 | |
736 | then | |
737 | command=status | |
738 | else | |
739 | usage | |
740 | fi | |
741 | fi | |
5c08dbbd | 742 | |
b57e8119 DL |
743 | # "-b branch" is accepted only by "add" and "set-branch" |
744 | if test -n "$branch" && (test "$command" != add || test "$command" != set-branch) | |
5c08dbbd | 745 | then |
ecda0723 | 746 | usage |
5c08dbbd JH |
747 | fi |
748 | ||
28f9af5d | 749 | # "--cached" is accepted only by "status" and "summary" |
496eeeb1 | 750 | if test -n "$cached" && test "$command" != status && test "$command" != summary |
5c08dbbd | 751 | then |
70c7ac22 | 752 | usage |
5c08dbbd JH |
753 | fi |
754 | ||
b57e8119 | 755 | "cmd_$(echo $command | sed -e s/-/_/g)" "$@" |