Handle the branch.<name>.rebase value 'interactive'
[git/dscho.git] / git-submodule.sh
blob289c2dd5583ec0aafbc11a43d58013eb27d0e257
1 #!/bin/sh
3 # git-submodules.sh: add, init, update or list git submodules
5 # Copyright (c) 2007 Lars Hjemli
7 dashless=$(basename "$0" | sed -e 's/-/ /')
8 USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
9 or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
10 or: $dashless [--quiet] init [--] [<path>...]
11 or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
12 or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
13 or: $dashless [--quiet] foreach [--recursive] <command>
14 or: $dashless [--quiet] sync [--] [<path>...]"
15 OPTIONS_SPEC=
16 . git-sh-setup
17 . git-sh-i18n
18 . git-parse-remote
19 require_work_tree
21 command=
22 branch=
23 force=
24 reference=
25 cached=
26 recursive=
27 init=
28 files=
29 nofetch=
30 update=
31 prefix=
33 # Resolve relative url by appending to parent's url
34 resolve_relative_url ()
36 remote=$(get_default_remote)
37 remoteurl=$(git config "remote.$remote.url") ||
38 remoteurl=$(pwd) # the repository is its own authoritative upstream
39 url="$1"
40 remoteurl=${remoteurl%/}
41 sep=/
42 while test -n "$url"
44 case "$url" in
45 ../*)
46 url="${url#../}"
47 case "$remoteurl" in
48 */*)
49 remoteurl="${remoteurl%/*}"
51 *:*)
52 remoteurl="${remoteurl%:*}"
53 sep=:
56 die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
58 esac
60 ./*)
61 url="${url#./}"
64 break;;
65 esac
66 done
67 echo "$remoteurl$sep${url%/}"
71 # Get submodule info for registered submodules
72 # $@ = path to limit submodule list
74 module_list()
76 git ls-files --error-unmatch --stage -- "$@" |
77 perl -e '
78 my %unmerged = ();
79 my ($null_sha1) = ("0" x 40);
80 while (<STDIN>) {
81 chomp;
82 my ($mode, $sha1, $stage, $path) =
83 /^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
84 next unless $mode eq "160000";
85 if ($stage ne "0") {
86 if (!$unmerged{$path}++) {
87 print "$mode $null_sha1 U\t$path\n";
89 next;
91 print "$_\n";
97 # Map submodule path to submodule name
99 # $1 = path
101 module_name()
103 # Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
104 sm_path="$1"
105 re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
106 name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
107 sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
108 test -z "$name" &&
109 die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$sm_path'")"
110 echo "$name"
114 # Clone a submodule
116 # Prior to calling, cmd_update checks that a possibly existing
117 # path is not a git repository.
118 # Likewise, cmd_add checks that path does not exist at all,
119 # since it is the location of a new submodule.
121 module_clone()
123 sm_path=$1
124 url=$2
125 reference="$3"
126 quiet=
127 if test -n "$GIT_QUIET"
128 then
129 quiet=-q
132 gitdir=
133 gitdir_base=
134 name=$(module_name "$sm_path" 2>/dev/null)
135 test -n "$name" || name="$sm_path"
136 base_name=$(dirname "$name")
138 gitdir=$(git rev-parse --git-dir)
139 gitdir_base="$gitdir/modules/$base_name"
140 gitdir="$gitdir/modules/$name"
142 if test -d "$gitdir"
143 then
144 mkdir -p "$sm_path"
145 rm -f "$gitdir/index"
146 else
147 mkdir -p "$gitdir_base"
148 git clone $quiet -n ${reference:+"$reference"} \
149 --separate-git-dir "$gitdir" "$url" "$sm_path" ||
150 die "$(eval_gettext "Clone of '\$url' into submodule path '\$sm_path' failed")"
153 a=$(cd "$gitdir" && pwd)/
154 b=$(cd "$sm_path" && pwd)/
155 # normalize Windows-style absolute paths to POSIX-style absolute paths
156 case $a in [a-zA-Z]:/*) a=/${a%%:*}${a#*:} ;; esac
157 case $b in [a-zA-Z]:/*) b=/${b%%:*}${b#*:} ;; esac
158 # Remove all common leading directories after a sanity check
159 if test "${a#$b}" != "$a" || test "${b#$a}" != "$b"; then
160 die "$(eval_gettext "Gitdir '\$a' is part of the submodule path '\$b' or vice versa")"
162 while test "${a%%/*}" = "${b%%/*}"
164 a=${a#*/}
165 b=${b#*/}
166 done
167 # Now chop off the trailing '/'s that were added in the beginning
168 a=${a%/}
169 b=${b%/}
171 # Turn each leading "*/" component into "../"
172 rel=$(echo $b | sed -e 's|[^/][^/]*|..|g')
173 echo "gitdir: $rel/$a" >"$sm_path/.git"
175 rel=$(echo $a | sed -e 's|[^/][^/]*|..|g')
176 (clear_local_git_env; cd "$sm_path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
180 # Add a new submodule to the working tree, .gitmodules and the index
182 # $@ = repo path
184 # optional branch is stored in global branch variable
186 cmd_add()
188 # parse $args after "submodule ... add".
189 while test $# -ne 0
191 case "$1" in
192 -b | --branch)
193 case "$2" in '') usage ;; esac
194 branch=$2
195 shift
197 -f | --force)
198 force=$1
200 -q|--quiet)
201 GIT_QUIET=1
203 --reference)
204 case "$2" in '') usage ;; esac
205 reference="--reference=$2"
206 shift
208 --reference=*)
209 reference="$1"
210 shift
213 shift
214 break
217 usage
220 break
222 esac
223 shift
224 done
226 repo=$1
227 sm_path=$2
229 if test -z "$sm_path"; then
230 sm_path=$(echo "$repo" |
231 sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
234 if test -z "$repo" -o -z "$sm_path"; then
235 usage
238 # assure repo is absolute or relative to parent
239 case "$repo" in
240 ./*|../*)
241 # dereference source url relative to parent's url
242 realrepo=$(resolve_relative_url "$repo") || exit
244 *:*|/*)
245 # absolute url
246 realrepo=$repo
249 die "$(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")"
251 esac
253 # normalize path:
254 # multiple //; leading ./; /./; /../; trailing /
255 sm_path=$(printf '%s/\n' "$sm_path" |
256 sed -e '
257 s|//*|/|g
258 s|^\(\./\)*||
259 s|/\./|/|g
260 :start
261 s|\([^/]*\)/\.\./||
262 tstart
263 s|/*$||
265 git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
266 die "$(eval_gettext "'\$sm_path' already exists in the index")"
268 if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1
269 then
270 cat >&2 <<EOF
271 The following path is ignored by one of your .gitignore files:
272 $(eval_gettextln $smpath)
273 Use -f if you really want to add it.
275 exit 1
278 # perhaps the path exists and is already a git repo, else clone it
279 if test -e "$sm_path"
280 then
281 if test -d "$sm_path"/.git -o -f "$sm_path"/.git
282 then
283 eval_gettextln "Adding existing repo at '\$sm_path' to the index"
284 else
285 die "$(eval_gettext "'\$sm_path' already exists and is not a valid git repo")"
288 else
290 module_clone "$sm_path" "$realrepo" "$reference" || exit
292 clear_local_git_env
293 cd "$sm_path" &&
294 # ash fails to wordsplit ${branch:+-b "$branch"...}
295 case "$branch" in
296 '') git checkout -f -q ;;
297 ?*) git checkout -f -q -B "$branch" "origin/$branch" ;;
298 esac
299 ) || die "$(eval_gettext "Unable to checkout submodule '\$sm_path'")"
301 git config submodule."$sm_path".url "$realrepo"
303 git add $force "$sm_path" ||
304 die "$(eval_gettext "Failed to add submodule '\$sm_path'")"
306 git config -f .gitmodules submodule."$sm_path".path "$sm_path" &&
307 git config -f .gitmodules submodule."$sm_path".url "$repo" &&
308 git add --force .gitmodules ||
309 die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
313 # Execute an arbitrary command sequence in each checked out
314 # submodule
316 # $@ = command to execute
318 cmd_foreach()
320 # parse $args after "submodule ... foreach".
321 while test $# -ne 0
323 case "$1" in
324 -q|--quiet)
325 GIT_QUIET=1
327 --recursive)
328 recursive=1
331 usage
334 break
336 esac
337 shift
338 done
340 toplevel=$(pwd)
342 # dup stdin so that it can be restored when running the external
343 # command in the subshell (and a recursive call to this function)
344 exec 3<&0
346 module_list |
347 while read mode sha1 stage sm_path
349 if test -e "$sm_path"/.git
350 then
351 say "$(eval_gettext "Entering '\$prefix\$sm_path'")"
352 name=$(module_name "$sm_path")
354 prefix="$prefix$sm_path/"
355 clear_local_git_env
356 # we make $path available to scripts ...
357 path=$sm_path
358 cd "$sm_path" &&
359 eval "$@" &&
360 if test -n "$recursive"
361 then
362 cmd_foreach "--recursive" "$@"
364 ) <&3 3<&- ||
365 die "$(eval_gettext "Stopping at '\$sm_path'; script returned non-zero status.")"
367 done
371 # Register submodules in .git/config
373 # $@ = requested paths (default to all)
375 cmd_init()
377 # parse $args after "submodule ... init".
378 while test $# -ne 0
380 case "$1" in
381 -q|--quiet)
382 GIT_QUIET=1
385 shift
386 break
389 usage
392 break
394 esac
395 shift
396 done
398 module_list "$@" |
399 while read mode sha1 stage sm_path
401 # Skip already registered paths
402 name=$(module_name "$sm_path") || exit
403 if test -z "$(git config "submodule.$name.url")"
404 then
405 url=$(git config -f .gitmodules submodule."$name".url)
406 test -z "$url" &&
407 die "$(eval_gettext "No url found for submodule path '\$sm_path' in .gitmodules")"
409 # Possibly a url relative to parent
410 case "$url" in
411 ./*|../*)
412 url=$(resolve_relative_url "$url") || exit
414 esac
415 git config submodule."$name".url "$url" ||
416 die "$(eval_gettext "Failed to register url for submodule path '\$sm_path'")"
419 # Copy "update" setting when it is not set yet
420 upd="$(git config -f .gitmodules submodule."$name".update)"
421 test -z "$upd" ||
422 test -n "$(git config submodule."$name".update)" ||
423 git config submodule."$name".update "$upd" ||
424 die "$(eval_gettext "Failed to register update mode for submodule path '\$sm_path'")"
426 say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$sm_path'")"
427 done
431 # Update each submodule path to correct revision, using clone and checkout as needed
433 # $@ = requested paths (default to all)
435 cmd_update()
437 # parse $args after "submodule ... update".
438 orig_flags=
439 while test $# -ne 0
441 case "$1" in
442 -q|--quiet)
443 GIT_QUIET=1
445 -i|--init)
446 init=1
448 -N|--no-fetch)
449 nofetch=1
451 -f|--force)
452 force=$1
454 -r|--rebase)
455 update="rebase"
457 --reference)
458 case "$2" in '') usage ;; esac
459 reference="--reference=$2"
460 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
461 shift
463 --reference=*)
464 reference="$1"
466 -m|--merge)
467 update="merge"
469 --recursive)
470 recursive=1
472 --checkout)
473 update="checkout"
476 shift
477 break
480 usage
483 break
485 esac
486 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
487 shift
488 done
490 if test -n "$init"
491 then
492 cmd_init "--" "$@" || return
495 cloned_modules=
496 module_list "$@" | {
497 err=
498 while read mode sha1 stage sm_path
500 if test "$stage" = U
501 then
502 echo >&2 "Skipping unmerged submodule $sm_path"
503 continue
505 name=$(module_name "$sm_path") || exit
506 url=$(git config submodule."$name".url)
507 if ! test -z "$update"
508 then
509 update_module=$update
510 else
511 update_module=$(git config submodule."$name".update)
514 if test "$update_module" = "none"
515 then
516 echo "Skipping submodule '$sm_path'"
517 continue
520 if test -z "$url"
521 then
522 # Only mention uninitialized submodules when its
523 # path have been specified
524 test "$#" != "0" &&
525 say "$(eval_gettext "Submodule path '\$sm_path' not initialized
526 Maybe you want to use 'update --init'?")"
527 continue
530 if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
531 then
532 module_clone "$sm_path" "$url" "$reference"|| exit
533 cloned_modules="$cloned_modules;$name"
534 subsha1=
535 else
536 subsha1=$(clear_local_git_env; cd "$sm_path" &&
537 git rev-parse --verify HEAD) ||
538 die "$(eval_gettext "Unable to find current revision in submodule path '\$sm_path'")"
541 if test "$subsha1" != "$sha1"
542 then
543 subforce=$force
544 # If we don't already have a -f flag and the submodule has never been checked out
545 if test -z "$subsha1" -a -z "$force"
546 then
547 subforce="-f"
550 if test -z "$nofetch"
551 then
552 # Run fetch only if $sha1 isn't present or it
553 # is not reachable from a ref.
554 (clear_local_git_env; cd "$sm_path" &&
555 ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
556 test -z "$rev") || git-fetch)) ||
557 die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
560 # Is this something we just cloned?
561 case ";$cloned_modules;" in
562 *";$name;"*)
563 # then there is no local change to integrate
564 update_module= ;;
565 esac
567 must_die_on_failure=
568 case "$update_module" in
569 rebase)
570 command="git rebase"
571 die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$sm_path'")"
572 say_msg="$(eval_gettext "Submodule path '\$sm_path': rebased into '\$sha1'")"
573 must_die_on_failure=yes
575 merge)
576 command="git merge"
577 die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$sm_path'")"
578 say_msg="$(eval_gettext "Submodule path '\$sm_path': merged in '\$sha1'")"
579 must_die_on_failure=yes
582 command="git checkout $subforce -q"
583 die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$sm_path'")"
584 say_msg="$(eval_gettext "Submodule path '\$sm_path': checked out '\$sha1'")"
586 esac
588 if (clear_local_git_env; cd "$sm_path" && $command "$sha1")
589 then
590 say "$say_msg"
591 elif test -n "$must_die_on_failure"
592 then
593 die_with_status 2 "$die_msg"
594 else
595 err="${err};$die_msg"
596 continue
600 if test -n "$recursive"
601 then
602 (clear_local_git_env; cd "$sm_path" && eval cmd_update "$orig_flags")
603 res=$?
604 if test $res -gt 0
605 then
606 die_msg="$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
607 if test $res -eq 1
608 then
609 err="${err};$die_msg"
610 continue
611 else
612 die_with_status $res "$die_msg"
616 done
618 if test -n "$err"
619 then
620 OIFS=$IFS
621 IFS=';'
622 for e in $err
624 if test -n "$e"
625 then
626 echo >&2 "$e"
628 done
629 IFS=$OIFS
630 exit 1
635 set_name_rev () {
636 revname=$( (
637 clear_local_git_env
638 cd "$1" && {
639 git describe "$2" 2>/dev/null ||
640 git describe --tags "$2" 2>/dev/null ||
641 git describe --contains "$2" 2>/dev/null ||
642 git describe --all --always "$2"
645 test -z "$revname" || revname=" ($revname)"
648 # Show commit summary for submodules in index or working tree
650 # If '--cached' is given, show summary between index and given commit,
651 # or between working tree and given commit
653 # $@ = [commit (default 'HEAD'),] requested paths (default all)
655 cmd_summary() {
656 summary_limit=-1
657 for_status=
658 diff_cmd=diff-index
660 # parse $args after "submodule ... summary".
661 while test $# -ne 0
663 case "$1" in
664 --cached)
665 cached="$1"
667 --files)
668 files="$1"
670 --for-status)
671 for_status="$1"
673 -n|--summary-limit)
674 if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
675 then
677 else
678 usage
680 shift
683 shift
684 break
687 usage
690 break
692 esac
693 shift
694 done
696 test $summary_limit = 0 && return
698 if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
699 then
700 head=$rev
701 test $# = 0 || shift
702 elif test -z "$1" -o "$1" = "HEAD"
703 then
704 # before the first commit: compare with an empty tree
705 head=$(git hash-object -w -t tree --stdin </dev/null)
706 test -z "$1" || shift
707 else
708 head="HEAD"
711 if [ -n "$files" ]
712 then
713 test -n "$cached" &&
714 die "$(gettext -- "--cached cannot be used with --files")"
715 diff_cmd=diff-files
716 head=
719 cd_to_toplevel
720 # Get modified modules cared by user
721 modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
722 sane_egrep '^:([0-7]* )?160000' |
723 while read mod_src mod_dst sha1_src sha1_dst status name
725 # Always show modules deleted or type-changed (blob<->module)
726 test $status = D -o $status = T && echo "$name" && continue
727 # Also show added or modified modules which are checked out
728 GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
729 echo "$name"
730 done
733 test -z "$modules" && return
735 git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules |
736 sane_egrep '^:([0-7]* )?160000' |
737 cut -c2- |
738 while read mod_src mod_dst sha1_src sha1_dst status name
740 if test -z "$cached" &&
741 test $sha1_dst = 0000000000000000000000000000000000000000
742 then
743 case "$mod_dst" in
744 160000)
745 sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
747 100644 | 100755 | 120000)
748 sha1_dst=$(git hash-object $name)
750 000000)
751 ;; # removed
753 # unexpected type
754 eval_gettextln "unexpected mode \$mod_dst" >&2
755 continue ;;
756 esac
758 missing_src=
759 missing_dst=
761 test $mod_src = 160000 &&
762 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_src^0 >/dev/null &&
763 missing_src=t
765 test $mod_dst = 160000 &&
766 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
767 missing_dst=t
769 total_commits=
770 case "$missing_src,$missing_dst" in
772 errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_src")"
775 errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_dst")"
777 t,t)
778 errmsg="$(eval_gettext " Warn: \$name doesn't contain commits \$sha1_src and \$sha1_dst")"
781 errmsg=
782 total_commits=$(
783 if test $mod_src = 160000 -a $mod_dst = 160000
784 then
785 range="$sha1_src...$sha1_dst"
786 elif test $mod_src = 160000
787 then
788 range=$sha1_src
789 else
790 range=$sha1_dst
792 GIT_DIR="$name/.git" \
793 git rev-list --first-parent $range -- | wc -l
795 total_commits=" ($(($total_commits + 0)))"
797 esac
799 sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
800 sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
801 if test $status = T
802 then
803 blob="$(gettext "blob")"
804 submodule="$(gettext "submodule")"
805 if test $mod_dst = 160000
806 then
807 echo "* $name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:"
808 else
809 echo "* $name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:"
811 else
812 echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
814 if test -n "$errmsg"
815 then
816 # Don't give error msg for modification whose dst is not submodule
817 # i.e. deleted or changed to blob
818 test $mod_dst = 160000 && echo "$errmsg"
819 else
820 if test $mod_src = 160000 -a $mod_dst = 160000
821 then
822 limit=
823 test $summary_limit -gt 0 && limit="-$summary_limit"
824 GIT_DIR="$name/.git" \
825 git log $limit --pretty='format: %m %s' \
826 --first-parent $sha1_src...$sha1_dst
827 elif test $mod_dst = 160000
828 then
829 GIT_DIR="$name/.git" \
830 git log --pretty='format: > %s' -1 $sha1_dst
831 else
832 GIT_DIR="$name/.git" \
833 git log --pretty='format: < %s' -1 $sha1_src
835 echo
837 echo
838 done |
839 if test -n "$for_status"; then
840 if [ -n "$files" ]; then
841 status_msg="$(gettextln "# Submodules changed but not updated:")"
842 else
843 status_msg="$(gettextln "# Submodule changes to be committed:")"
845 status_sed=$(sed -e 's|^|# |' -e 's|^# $|#|')
846 cat <<EOF
847 $status_msg
849 $status_sed
851 else
856 # List all submodules, prefixed with:
857 # - submodule not initialized
858 # + different revision checked out
860 # If --cached was specified the revision in the index will be printed
861 # instead of the currently checked out revision.
863 # $@ = requested paths (default to all)
865 cmd_status()
867 # parse $args after "submodule ... status".
868 orig_flags=
869 while test $# -ne 0
871 case "$1" in
872 -q|--quiet)
873 GIT_QUIET=1
875 --cached)
876 cached=1
878 --recursive)
879 recursive=1
882 shift
883 break
886 usage
889 break
891 esac
892 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
893 shift
894 done
896 module_list "$@" |
897 while read mode sha1 stage sm_path
899 name=$(module_name "$sm_path") || exit
900 url=$(git config submodule."$name".url)
901 displaypath="$prefix$sm_path"
902 if test "$stage" = U
903 then
904 say "U$sha1 $displaypath"
905 continue
907 if test -z "$url" || ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
908 then
909 say "-$sha1 $displaypath"
910 continue;
912 set_name_rev "$sm_path" "$sha1"
913 if git diff-files --ignore-submodules=dirty --quiet -- "$sm_path"
914 then
915 say " $sha1 $displaypath$revname"
916 else
917 if test -z "$cached"
918 then
919 sha1=$(clear_local_git_env; cd "$sm_path" && git rev-parse --verify HEAD)
920 set_name_rev "$sm_path" "$sha1"
922 say "+$sha1 $displaypath$revname"
925 if test -n "$recursive"
926 then
928 prefix="$displaypath/"
929 clear_local_git_env
930 cd "$sm_path" &&
931 eval cmd_status "$orig_args"
932 ) ||
933 die "$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
935 done
938 # Sync remote urls for submodules
939 # This makes the value for remote.$remote.url match the value
940 # specified in .gitmodules.
942 cmd_sync()
944 while test $# -ne 0
946 case "$1" in
947 -q|--quiet)
948 GIT_QUIET=1
949 shift
952 shift
953 break
956 usage
959 break
961 esac
962 done
963 cd_to_toplevel
964 module_list "$@" |
965 while read mode sha1 stage sm_path
967 name=$(module_name "$sm_path")
968 url=$(git config -f .gitmodules --get submodule."$name".url)
970 # Possibly a url relative to parent
971 case "$url" in
972 ./*|../*)
973 url=$(resolve_relative_url "$url") || exit
975 esac
977 if git config "submodule.$name.url" >/dev/null 2>/dev/null
978 then
979 say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
980 git config submodule."$name".url "$url"
982 if test -e "$sm_path"/.git
983 then
985 clear_local_git_env
986 cd "$sm_path"
987 remote=$(get_default_remote)
988 git config remote."$remote".url "$url"
992 done
995 # This loop parses the command line arguments to find the
996 # subcommand name to dispatch. Parsing of the subcommand specific
997 # options are primarily done by the subcommand implementations.
998 # Subcommand specific options such as --branch and --cached are
999 # parsed here as well, for backward compatibility.
1001 while test $# != 0 && test -z "$command"
1003 case "$1" in
1004 add | foreach | init | update | status | summary | sync)
1005 command=$1
1007 -q|--quiet)
1008 GIT_QUIET=1
1010 -b|--branch)
1011 case "$2" in
1013 usage
1015 esac
1016 branch="$2"; shift
1018 --cached)
1019 cached="$1"
1022 break
1025 usage
1028 break
1030 esac
1031 shift
1032 done
1034 # No command word defaults to "status"
1035 test -n "$command" || command=status
1037 # "-b branch" is accepted only by "add"
1038 if test -n "$branch" && test "$command" != add
1039 then
1040 usage
1043 # "--cached" is accepted only by "status" and "summary"
1044 if test -n "$cached" && test "$command" != status -a "$command" != summary
1045 then
1046 usage
1049 "cmd_$command" "$@"