interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / git-submodule.sh

689 lines · 11161 bytes Raw Blame History
1#!/bin/sh
2#
3# git-submodule.sh: add, init, update or list git submodules
4#
5# Copyright (c) 2007 Lars Hjemli
6
7dashless=$(basename "$0" | sed -e 's/-/ /')
8USAGE="[--quiet] [--cached]
9 or: $dashless [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
10 or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
11 or: $dashless [--quiet] init [--] [<path>...]
12 or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
13 or: $dashless [--quiet] update [--init [--filter=<filter-spec>]] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...]
14 or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path>
15 or: $dashless [--quiet] set-url [--] <path> <newurl>
16 or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
17 or: $dashless [--quiet] foreach [--recursive] <command>
18 or: $dashless [--quiet] sync [--recursive] [--] [<path>...]
19 or: $dashless [--quiet] absorbgitdirs [--] [<path>...]"
20OPTIONS_SPEC=
21SUBDIRECTORY_OK=Yes
22. git-sh-setup
23require_work_tree
24wt_prefix=$(git rev-parse --show-prefix)
25cd_to_toplevel
26
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.
29GIT_PROTOCOL_FROM_USER=0
30export GIT_PROTOCOL_FROM_USER
31
32command=
33quiet=
34branch=
35force=
36reference=
37cached=
38recursive=
39init=
40require_init=
41files=
42remote=
43no_fetch=
44rebase=
45merge=
46checkout=
47name=
48depth=
49progress=
50dissociate=
51single_branch=
52jobs=
53recommend_shallow=
54filter=
55all=
56default=
57summary_limit=
58for_status=
59
60#
61# Add a new submodule to the working tree, .gitmodules and the index
62#
63# $@ = repo path
64#
65# optional branch is stored in global branch variable
66#
67cmd_add()
68{
69 # parse $args after "submodule ... add".
70 while test $# -ne 0
71 do
72 case "$1" in
73 -b | --branch)
74 case "$2" in '') usage ;; esac
75 branch="--branch=$2"
76 shift
77 ;;
78 -b* | --branch=*)
79 branch="$1"
80 ;;
81 -f | --force)
82 force=$1
83 ;;
84 -q|--quiet)
85 quiet=$1
86 ;;
87 --progress)
88 progress=$1
89 ;;
90 --reference)
91 case "$2" in '') usage ;; esac
92 reference="--reference=$2"
93 shift
94 ;;
95 --reference=*)
96 reference="$1"
97 ;;
98 --ref-format|--ref-storage-format)
99 case "$2" in '') usage ;; esac
100 ref_storage_format="--ref-storage-format=$2"
101 shift
102 ;;
103 --ref-format=*|--ref-storage-format=*)
104 ref_storage_format="$1"
105 ;;
106 --object-storage-format)
107 case "$2" in '') usage ;; esac
108 object_storage_format="--object-storage-format=$2"
109 shift
110 ;;
111 --object-storage-format=*)
112 object_storage_format="$1"
113 ;;
114 --dissociate)
115 dissociate=$1
116 ;;
117 --name)
118 case "$2" in '') usage ;; esac
119 name="--name=$2"
120 shift
121 ;;
122 --name=*)
123 name="$1"
124 ;;
125 --depth)
126 case "$2" in '') usage ;; esac
127 depth="--depth=$2"
128 shift
129 ;;
130 --depth=*)
131 depth="$1"
132 ;;
133 --)
134 shift
135 break
136 ;;
137 -*)
138 usage
139 ;;
140 *)
141 break
142 ;;
143 esac
144 shift
145 done
146
147 if test -z "$1"
148 then
149 usage
150 fi
151
152 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add \
153 $quiet \
154 $force \
155 $progress \
156 ${branch:+"$branch"} \
157 ${reference:+"$reference"} \
158 ${ref_storage_format:+"$ref_storage_format"} \
159 ${object_storage_format:+"$object_storage_format"} \
160 $dissociate \
161 ${name:+"$name"} \
162 ${depth:+"$depth"} \
163 -- \
164 "$@"
165}
166
167#
168# Execute an arbitrary command sequence in each checked out
169# submodule
170#
171# $@ = command to execute
172#
173cmd_foreach()
174{
175 # parse $args after "submodule ... foreach".
176 while test $# -ne 0
177 do
178 case "$1" in
179 -q|--quiet)
180 quiet=$1
181 ;;
182 --recursive)
183 recursive=$1
184 ;;
185 -*)
186 usage
187 ;;
188 *)
189 break
190 ;;
191 esac
192 shift
193 done
194
195 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach \
196 $quiet \
197 $recursive \
198 -- \
199 "$@"
200}
201
202#
203# Register submodules in .git/config
204#
205# $@ = requested paths (default to all)
206#
207cmd_init()
208{
209 # parse $args after "submodule ... init".
210 while test $# -ne 0
211 do
212 case "$1" in
213 -q|--quiet)
214 quiet=$1
215 ;;
216 --)
217 shift
218 break
219 ;;
220 -*)
221 usage
222 ;;
223 *)
224 break
225 ;;
226 esac
227 shift
228 done
229
230 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init \
231 $quiet \
232 -- \
233 "$@"
234}
235
236#
237# Unregister submodules from .git/config and remove their work tree
238#
239cmd_deinit()
240{
241 # parse $args after "submodule ... deinit".
242 while test $# -ne 0
243 do
244 case "$1" in
245 -f|--force)
246 force=$1
247 ;;
248 -q|--quiet)
249 quiet=$1
250 ;;
251 --all)
252 all=$1
253 ;;
254 --)
255 shift
256 break
257 ;;
258 -*)
259 usage
260 ;;
261 *)
262 break
263 ;;
264 esac
265 shift
266 done
267
268 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit \
269 $quiet \
270 $force \
271 $all \
272 -- \
273 "$@"
274}
275
276#
277# Update each submodule path to correct revision, using clone and checkout as needed
278#
279# $@ = requested paths (default to all)
280#
281cmd_update()
282{
283 # parse $args after "submodule ... update".
284 while test $# -ne 0
285 do
286 case "$1" in
287 -q|--quiet)
288 quiet=$1
289 ;;
290 -v|--verbose)
291 quiet=
292 ;;
293 --progress)
294 progress=$1
295 ;;
296 -i|--init)
297 init=$1
298 ;;
299 --require-init)
300 require_init=$1
301 ;;
302 --remote)
303 remote=$1
304 ;;
305 -N|--no-fetch)
306 no_fetch=$1
307 ;;
308 -f|--force)
309 force=$1
310 ;;
311 -r|--rebase)
312 rebase=$1
313 ;;
314 --ref-format|--ref-storage-format)
315 case "$2" in '') usage ;; esac
316 ref_storage_format="--ref-storage-format=$2"
317 shift
318 ;;
319 --ref-format=*|--ref-storage-format=*)
320 ref_storage_format="$1"
321 ;;
322 --object-storage-format)
323 case "$2" in '') usage ;; esac
324 object_storage_format="--object-storage-format=$2"
325 shift
326 ;;
327 --object-storage-format=*)
328 object_storage_format="$1"
329 ;;
330 --reference)
331 case "$2" in '') usage ;; esac
332 reference="--reference=$2"
333 shift
334 ;;
335 --reference=*)
336 reference="$1"
337 ;;
338 --dissociate)
339 dissociate=$1
340 ;;
341 -m|--merge)
342 merge=$1
343 ;;
344 --recursive)
345 recursive=$1
346 ;;
347 --checkout)
348 checkout=$1
349 ;;
350 --recommend-shallow|--no-recommend-shallow)
351 recommend_shallow=$1
352 ;;
353 --depth)
354 case "$2" in '') usage ;; esac
355 depth="--depth=$2"
356 shift
357 ;;
358 --depth=*)
359 depth="$1"
360 ;;
361 -j|--jobs)
362 case "$2" in '') usage ;; esac
363 jobs="--jobs=$2"
364 shift
365 ;;
366 -j*|--jobs=*)
367 jobs="$1"
368 ;;
369 --single-branch|--no-single-branch)
370 single_branch=$1
371 ;;
372 --filter)
373 case "$2" in '') usage ;; esac
374 filter="--filter=$2"
375 shift
376 ;;
377 --filter=*)
378 filter="$1"
379 ;;
380 --)
381 shift
382 break
383 ;;
384 -*)
385 usage
386 ;;
387 *)
388 break
389 ;;
390 esac
391 shift
392 done
393
394 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
395 $quiet \
396 $force \
397 $progress \
398 $remote \
399 $recursive \
400 $init \
401 $no_fetch \
402 $rebase \
403 $merge \
404 $checkout \
405 ${ref_storage_format:+"$ref_storage_format"} \
406 ${object_storage_format:+"$object_storage_format"} \
407 ${reference:+"$reference"} \
408 $dissociate \
409 ${depth:+"$depth"} \
410 $require_init \
411 $single_branch \
412 $recommend_shallow \
413 $jobs \
414 $filter \
415 -- \
416 "$@"
417}
418
419#
420# Configures a submodule's default branch
421#
422# $@ = requested path
423#
424cmd_set_branch() {
425 # parse $args after "submodule ... set-branch".
426 while test $# -ne 0
427 do
428 case "$1" in
429 -q|--quiet)
430 # we don't do anything with this but we need to accept it
431 ;;
432 -d|--default)
433 default=$1
434 ;;
435 -b|--branch)
436 case "$2" in '') usage ;; esac
437 branch="--branch=$2"
438 shift
439 ;;
440 -b*|--branch=*)
441 branch="$1"
442 ;;
443 --)
444 shift
445 break
446 ;;
447 -*)
448 usage
449 ;;
450 *)
451 break
452 ;;
453 esac
454 shift
455 done
456
457 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch \
458 $quiet \
459 ${branch:+"$branch"} \
460 $default \
461 -- \
462 "$@"
463}
464
465#
466# Configures a submodule's remote url
467#
468# $@ = requested path, requested url
469#
470cmd_set_url() {
471 # parse $args after "submodule ... set-url".
472 while test $# -ne 0
473 do
474 case "$1" in
475 -q|--quiet)
476 quiet=$1
477 ;;
478 --)
479 shift
480 break
481 ;;
482 -*)
483 usage
484 ;;
485 *)
486 break
487 ;;
488 esac
489 shift
490 done
491
492 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url \
493 $quiet \
494 -- \
495 "$@"
496}
497
498#
499# Show commit summary for submodules in index or working tree
500#
501# If '--cached' is given, show summary between index and given commit,
502# or between working tree and given commit
503#
504# $@ = [commit (default 'HEAD'),] requested paths (default all)
505#
506cmd_summary() {
507 # parse $args after "submodule ... summary".
508 while test $# -ne 0
509 do
510 case "$1" in
511 --cached)
512 cached=$1
513 ;;
514 --files)
515 files=$1
516 ;;
517 --for-status)
518 for_status=$1
519 ;;
520 -n|--summary-limit)
521 case "$2" in '') usage ;; esac
522 summary_limit="--summary-limit=$2"
523 shift
524 ;;
525 -n*|--summary-limit=*)
526 summary_limit="$1"
527 ;;
528 --)
529 shift
530 break
531 ;;
532 -*)
533 usage
534 ;;
535 *)
536 break
537 ;;
538 esac
539 shift
540 done
541
542 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary \
543 $files \
544 $cached \
545 $for_status \
546 ${summary_limit:+"$summary_limit"} \
547 -- \
548 "$@"
549}
550#
551# List all submodules, prefixed with:
552# - submodule not initialized
553# + different revision checked out
554#
555# If --cached was specified the revision in the index will be printed
556# instead of the currently checked out revision.
557#
558# $@ = requested paths (default to all)
559#
560cmd_status()
561{
562 # parse $args after "submodule ... status".
563 while test $# -ne 0
564 do
565 case "$1" in
566 -q|--quiet)
567 quiet=$1
568 ;;
569 --cached)
570 cached=$1
571 ;;
572 --recursive)
573 recursive=$1
574 ;;
575 --)
576 shift
577 break
578 ;;
579 -*)
580 usage
581 ;;
582 *)
583 break
584 ;;
585 esac
586 shift
587 done
588
589 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status \
590 $quiet \
591 $cached \
592 $recursive \
593 -- \
594 "$@"
595}
596
597#
598# Sync remote urls for submodules
599# This makes the value for remote.$remote.url match the value
600# specified in .gitmodules.
601#
602cmd_sync()
603{
604 # parse $args after "submodule ... sync".
605 while test $# -ne 0
606 do
607 case "$1" in
608 -q|--quiet)
609 quiet=$1
610 shift
611 ;;
612 --recursive)
613 recursive=$1
614 shift
615 ;;
616 --)
617 shift
618 break
619 ;;
620 -*)
621 usage
622 ;;
623 *)
624 break
625 ;;
626 esac
627 done
628
629 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync \
630 $quiet \
631 $recursive \
632 -- \
633 "$@"
634}
635
636cmd_absorbgitdirs()
637{
638 git ${wt_prefix:+-C "$wt_prefix"} submodule--helper absorbgitdirs "$@"
639}
640
641# This loop parses the command line arguments to find the
642# subcommand name to dispatch. Parsing of the subcommand specific
643# options are primarily done by the subcommand implementations.
644# Subcommand specific options such as --branch and --cached are
645# parsed here as well, for backward compatibility.
646
647while test $# != 0 && test -z "$command"
648do
649 case "$1" in
650 add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs)
651 command=$1
652 ;;
653 -q|--quiet)
654 quiet=$1
655 ;;
656 --cached)
657 cached=$1
658 ;;
659 --)
660 break
661 ;;
662 -*)
663 usage
664 ;;
665 *)
666 break
667 ;;
668 esac
669 shift
670done
671
672# No command word defaults to "status"
673if test -z "$command"
674then
675 if test $# = 0
676 then
677 command=status
678 else
679 usage
680 fi
681fi
682
683# "--cached" is accepted only by "status" and "summary"
684if test -n "$cached" && test "$command" != status && test "$command" != summary
685then
686 usage
687fi
688
689"cmd_$(echo $command | sed -e s/-/_/g)" "$@"