Merge branch 'ab/diff-write-incomplete-line' into maint-1.7.11
[git.git] / git-submodule.sh
blob30fa93a8a0a4985f7ce980d4abf69410af22976c
1 #!/bin/sh
3 # git-submodule.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 # We already are at the root of the work tree but cd_to_toplevel will
154 # resolve any symlinks that might be present in $PWD
155 a=$(cd_to_toplevel && cd "$gitdir" && pwd)/
156 b=$(cd_to_toplevel && cd "$sm_path" && pwd)/
157 # normalize Windows-style absolute paths to POSIX-style absolute paths
158 case $a in [a-zA-Z]:/*) a=/${a%%:*}${a#*:} ;; esac
159 case $b in [a-zA-Z]:/*) b=/${b%%:*}${b#*:} ;; esac
160 # Remove all common leading directories after a sanity check
161 if test "${a#$b}" != "$a" || test "${b#$a}" != "$b"; then
162 die "$(eval_gettext "Gitdir '\$a' is part of the submodule path '\$b' or vice versa")"
164 while test "${a%%/*}" = "${b%%/*}"
166 a=${a#*/}
167 b=${b#*/}
168 done
169 # Now chop off the trailing '/'s that were added in the beginning
170 a=${a%/}
171 b=${b%/}
173 # Turn each leading "*/" component into "../"
174 rel=$(echo $b | sed -e 's|[^/][^/]*|..|g')
175 echo "gitdir: $rel/$a" >"$sm_path/.git"
177 rel=$(echo $a | sed -e 's|[^/][^/]*|..|g')
178 (clear_local_git_env; cd "$sm_path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
182 # Add a new submodule to the working tree, .gitmodules and the index
184 # $@ = repo path
186 # optional branch is stored in global branch variable
188 cmd_add()
190 # parse $args after "submodule ... add".
191 while test $# -ne 0
193 case "$1" in
194 -b | --branch)
195 case "$2" in '') usage ;; esac
196 branch=$2
197 shift
199 -f | --force)
200 force=$1
202 -q|--quiet)
203 GIT_QUIET=1
205 --reference)
206 case "$2" in '') usage ;; esac
207 reference="--reference=$2"
208 shift
210 --reference=*)
211 reference="$1"
212 shift
215 shift
216 break
219 usage
222 break
224 esac
225 shift
226 done
228 repo=$1
229 sm_path=$2
231 if test -z "$sm_path"; then
232 sm_path=$(echo "$repo" |
233 sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
236 if test -z "$repo" -o -z "$sm_path"; then
237 usage
240 # assure repo is absolute or relative to parent
241 case "$repo" in
242 ./*|../*)
243 # dereference source url relative to parent's url
244 realrepo=$(resolve_relative_url "$repo") || exit
246 *:*|/*)
247 # absolute url
248 realrepo=$repo
251 die "$(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")"
253 esac
255 # normalize path:
256 # multiple //; leading ./; /./; /../; trailing /
257 sm_path=$(printf '%s/\n' "$sm_path" |
258 sed -e '
259 s|//*|/|g
260 s|^\(\./\)*||
261 s|/\./|/|g
262 :start
263 s|\([^/]*\)/\.\./||
264 tstart
265 s|/*$||
267 git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
268 die "$(eval_gettext "'\$sm_path' already exists in the index")"
270 if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1
271 then
272 eval_gettextln "The following path is ignored by one of your .gitignore files:
273 \$sm_path
274 Use -f if you really want to add it." >&2
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 name=$(module_name "$sm_path") || exit
403 # Copy url setting when it is not set yet
404 if test -z "$(git config "submodule.$name.url")"
405 then
406 url=$(git config -f .gitmodules submodule."$name".url)
407 test -z "$url" &&
408 die "$(eval_gettext "No url found for submodule path '\$sm_path' in .gitmodules")"
410 # Possibly a url relative to parent
411 case "$url" in
412 ./*|../*)
413 url=$(resolve_relative_url "$url") || exit
415 esac
416 git config submodule."$name".url "$url" ||
417 die "$(eval_gettext "Failed to register url for submodule path '\$sm_path'")"
419 say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$sm_path'")"
422 # Copy "update" setting when it is not set yet
423 upd="$(git config -f .gitmodules submodule."$name".update)"
424 test -z "$upd" ||
425 test -n "$(git config submodule."$name".update)" ||
426 git config submodule."$name".update "$upd" ||
427 die "$(eval_gettext "Failed to register update mode for submodule path '\$sm_path'")"
428 done
432 # Update each submodule path to correct revision, using clone and checkout as needed
434 # $@ = requested paths (default to all)
436 cmd_update()
438 # parse $args after "submodule ... update".
439 orig_flags=
440 while test $# -ne 0
442 case "$1" in
443 -q|--quiet)
444 GIT_QUIET=1
446 -i|--init)
447 init=1
449 -N|--no-fetch)
450 nofetch=1
452 -f|--force)
453 force=$1
455 -r|--rebase)
456 update="rebase"
458 --reference)
459 case "$2" in '') usage ;; esac
460 reference="--reference=$2"
461 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
462 shift
464 --reference=*)
465 reference="$1"
467 -m|--merge)
468 update="merge"
470 --recursive)
471 recursive=1
473 --checkout)
474 update="checkout"
477 shift
478 break
481 usage
484 break
486 esac
487 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
488 shift
489 done
491 if test -n "$init"
492 then
493 cmd_init "--" "$@" || return
496 cloned_modules=
497 module_list "$@" | {
498 err=
499 while read mode sha1 stage sm_path
501 if test "$stage" = U
502 then
503 echo >&2 "Skipping unmerged submodule $sm_path"
504 continue
506 name=$(module_name "$sm_path") || exit
507 url=$(git config submodule."$name".url)
508 if ! test -z "$update"
509 then
510 update_module=$update
511 else
512 update_module=$(git config submodule."$name".update)
515 if test "$update_module" = "none"
516 then
517 echo "Skipping submodule '$sm_path'"
518 continue
521 if test -z "$url"
522 then
523 # Only mention uninitialized submodules when its
524 # path have been specified
525 test "$#" != "0" &&
526 say "$(eval_gettext "Submodule path '\$sm_path' not initialized
527 Maybe you want to use 'update --init'?")"
528 continue
531 if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
532 then
533 module_clone "$sm_path" "$url" "$reference"|| exit
534 cloned_modules="$cloned_modules;$name"
535 subsha1=
536 else
537 subsha1=$(clear_local_git_env; cd "$sm_path" &&
538 git rev-parse --verify HEAD) ||
539 die "$(eval_gettext "Unable to find current revision in submodule path '\$sm_path'")"
542 if test "$subsha1" != "$sha1"
543 then
544 subforce=$force
545 # If we don't already have a -f flag and the submodule has never been checked out
546 if test -z "$subsha1" -a -z "$force"
547 then
548 subforce="-f"
551 if test -z "$nofetch"
552 then
553 # Run fetch only if $sha1 isn't present or it
554 # is not reachable from a ref.
555 (clear_local_git_env; cd "$sm_path" &&
556 ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
557 test -z "$rev") || git-fetch)) ||
558 die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
561 # Is this something we just cloned?
562 case ";$cloned_modules;" in
563 *";$name;"*)
564 # then there is no local change to integrate
565 update_module= ;;
566 esac
568 must_die_on_failure=
569 case "$update_module" in
570 rebase)
571 command="git rebase"
572 die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$sm_path'")"
573 say_msg="$(eval_gettext "Submodule path '\$sm_path': rebased into '\$sha1'")"
574 must_die_on_failure=yes
576 merge)
577 command="git merge"
578 die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$sm_path'")"
579 say_msg="$(eval_gettext "Submodule path '\$sm_path': merged in '\$sha1'")"
580 must_die_on_failure=yes
583 command="git checkout $subforce -q"
584 die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$sm_path'")"
585 say_msg="$(eval_gettext "Submodule path '\$sm_path': checked out '\$sha1'")"
587 esac
589 if (clear_local_git_env; cd "$sm_path" && $command "$sha1")
590 then
591 say "$say_msg"
592 elif test -n "$must_die_on_failure"
593 then
594 die_with_status 2 "$die_msg"
595 else
596 err="${err};$die_msg"
597 continue
601 if test -n "$recursive"
602 then
603 (clear_local_git_env; cd "$sm_path" && eval cmd_update "$orig_flags")
604 res=$?
605 if test $res -gt 0
606 then
607 die_msg="$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
608 if test $res -eq 1
609 then
610 err="${err};$die_msg"
611 continue
612 else
613 die_with_status $res "$die_msg"
617 done
619 if test -n "$err"
620 then
621 OIFS=$IFS
622 IFS=';'
623 for e in $err
625 if test -n "$e"
626 then
627 echo >&2 "$e"
629 done
630 IFS=$OIFS
631 exit 1
636 set_name_rev () {
637 revname=$( (
638 clear_local_git_env
639 cd "$1" && {
640 git describe "$2" 2>/dev/null ||
641 git describe --tags "$2" 2>/dev/null ||
642 git describe --contains "$2" 2>/dev/null ||
643 git describe --all --always "$2"
646 test -z "$revname" || revname=" ($revname)"
649 # Show commit summary for submodules in index or working tree
651 # If '--cached' is given, show summary between index and given commit,
652 # or between working tree and given commit
654 # $@ = [commit (default 'HEAD'),] requested paths (default all)
656 cmd_summary() {
657 summary_limit=-1
658 for_status=
659 diff_cmd=diff-index
661 # parse $args after "submodule ... summary".
662 while test $# -ne 0
664 case "$1" in
665 --cached)
666 cached="$1"
668 --files)
669 files="$1"
671 --for-status)
672 for_status="$1"
674 -n|--summary-limit)
675 if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
676 then
678 else
679 usage
681 shift
684 shift
685 break
688 usage
691 break
693 esac
694 shift
695 done
697 test $summary_limit = 0 && return
699 if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
700 then
701 head=$rev
702 test $# = 0 || shift
703 elif test -z "$1" -o "$1" = "HEAD"
704 then
705 # before the first commit: compare with an empty tree
706 head=$(git hash-object -w -t tree --stdin </dev/null)
707 test -z "$1" || shift
708 else
709 head="HEAD"
712 if [ -n "$files" ]
713 then
714 test -n "$cached" &&
715 die "$(gettext -- "--cached cannot be used with --files")"
716 diff_cmd=diff-files
717 head=
720 cd_to_toplevel
721 # Get modified modules cared by user
722 modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
723 sane_egrep '^:([0-7]* )?160000' |
724 while read mod_src mod_dst sha1_src sha1_dst status name
726 # Always show modules deleted or type-changed (blob<->module)
727 test $status = D -o $status = T && echo "$name" && continue
728 # Also show added or modified modules which are checked out
729 GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
730 echo "$name"
731 done
734 test -z "$modules" && return
736 git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules |
737 sane_egrep '^:([0-7]* )?160000' |
738 cut -c2- |
739 while read mod_src mod_dst sha1_src sha1_dst status name
741 if test -z "$cached" &&
742 test $sha1_dst = 0000000000000000000000000000000000000000
743 then
744 case "$mod_dst" in
745 160000)
746 sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
748 100644 | 100755 | 120000)
749 sha1_dst=$(git hash-object $name)
751 000000)
752 ;; # removed
754 # unexpected type
755 eval_gettextln "unexpected mode \$mod_dst" >&2
756 continue ;;
757 esac
759 missing_src=
760 missing_dst=
762 test $mod_src = 160000 &&
763 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_src^0 >/dev/null &&
764 missing_src=t
766 test $mod_dst = 160000 &&
767 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
768 missing_dst=t
770 total_commits=
771 case "$missing_src,$missing_dst" in
773 errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_src")"
776 errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_dst")"
778 t,t)
779 errmsg="$(eval_gettext " Warn: \$name doesn't contain commits \$sha1_src and \$sha1_dst")"
782 errmsg=
783 total_commits=$(
784 if test $mod_src = 160000 -a $mod_dst = 160000
785 then
786 range="$sha1_src...$sha1_dst"
787 elif test $mod_src = 160000
788 then
789 range=$sha1_src
790 else
791 range=$sha1_dst
793 GIT_DIR="$name/.git" \
794 git rev-list --first-parent $range -- | wc -l
796 total_commits=" ($(($total_commits + 0)))"
798 esac
800 sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
801 sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
802 if test $status = T
803 then
804 blob="$(gettext "blob")"
805 submodule="$(gettext "submodule")"
806 if test $mod_dst = 160000
807 then
808 echo "* $name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:"
809 else
810 echo "* $name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:"
812 else
813 echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
815 if test -n "$errmsg"
816 then
817 # Don't give error msg for modification whose dst is not submodule
818 # i.e. deleted or changed to blob
819 test $mod_dst = 160000 && echo "$errmsg"
820 else
821 if test $mod_src = 160000 -a $mod_dst = 160000
822 then
823 limit=
824 test $summary_limit -gt 0 && limit="-$summary_limit"
825 GIT_DIR="$name/.git" \
826 git log $limit --pretty='format: %m %s' \
827 --first-parent $sha1_src...$sha1_dst
828 elif test $mod_dst = 160000
829 then
830 GIT_DIR="$name/.git" \
831 git log --pretty='format: > %s' -1 $sha1_dst
832 else
833 GIT_DIR="$name/.git" \
834 git log --pretty='format: < %s' -1 $sha1_src
836 echo
838 echo
839 done |
840 if test -n "$for_status"; then
841 if [ -n "$files" ]; then
842 gettextln "# Submodules changed but not updated:"
843 else
844 gettextln "# Submodule changes to be committed:"
846 echo "#"
847 sed -e 's|^|# |' -e 's|^# $|#|'
848 else
853 # List all submodules, prefixed with:
854 # - submodule not initialized
855 # + different revision checked out
857 # If --cached was specified the revision in the index will be printed
858 # instead of the currently checked out revision.
860 # $@ = requested paths (default to all)
862 cmd_status()
864 # parse $args after "submodule ... status".
865 orig_flags=
866 while test $# -ne 0
868 case "$1" in
869 -q|--quiet)
870 GIT_QUIET=1
872 --cached)
873 cached=1
875 --recursive)
876 recursive=1
879 shift
880 break
883 usage
886 break
888 esac
889 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
890 shift
891 done
893 module_list "$@" |
894 while read mode sha1 stage sm_path
896 name=$(module_name "$sm_path") || exit
897 url=$(git config submodule."$name".url)
898 displaypath="$prefix$sm_path"
899 if test "$stage" = U
900 then
901 say "U$sha1 $displaypath"
902 continue
904 if test -z "$url" || ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
905 then
906 say "-$sha1 $displaypath"
907 continue;
909 set_name_rev "$sm_path" "$sha1"
910 if git diff-files --ignore-submodules=dirty --quiet -- "$sm_path"
911 then
912 say " $sha1 $displaypath$revname"
913 else
914 if test -z "$cached"
915 then
916 sha1=$(clear_local_git_env; cd "$sm_path" && git rev-parse --verify HEAD)
917 set_name_rev "$sm_path" "$sha1"
919 say "+$sha1 $displaypath$revname"
922 if test -n "$recursive"
923 then
925 prefix="$displaypath/"
926 clear_local_git_env
927 cd "$sm_path" &&
928 eval cmd_status "$orig_args"
929 ) ||
930 die "$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
932 done
935 # Sync remote urls for submodules
936 # This makes the value for remote.$remote.url match the value
937 # specified in .gitmodules.
939 cmd_sync()
941 while test $# -ne 0
943 case "$1" in
944 -q|--quiet)
945 GIT_QUIET=1
946 shift
949 shift
950 break
953 usage
956 break
958 esac
959 done
960 cd_to_toplevel
961 module_list "$@" |
962 while read mode sha1 stage sm_path
964 name=$(module_name "$sm_path")
965 url=$(git config -f .gitmodules --get submodule."$name".url)
967 # Possibly a url relative to parent
968 case "$url" in
969 ./*|../*)
970 url=$(resolve_relative_url "$url") || exit
972 esac
974 if git config "submodule.$name.url" >/dev/null 2>/dev/null
975 then
976 say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
977 git config submodule."$name".url "$url"
979 if test -e "$sm_path"/.git
980 then
982 clear_local_git_env
983 cd "$sm_path"
984 remote=$(get_default_remote)
985 git config remote."$remote".url "$url"
989 done
992 # This loop parses the command line arguments to find the
993 # subcommand name to dispatch. Parsing of the subcommand specific
994 # options are primarily done by the subcommand implementations.
995 # Subcommand specific options such as --branch and --cached are
996 # parsed here as well, for backward compatibility.
998 while test $# != 0 && test -z "$command"
1000 case "$1" in
1001 add | foreach | init | update | status | summary | sync)
1002 command=$1
1004 -q|--quiet)
1005 GIT_QUIET=1
1007 -b|--branch)
1008 case "$2" in
1010 usage
1012 esac
1013 branch="$2"; shift
1015 --cached)
1016 cached="$1"
1019 break
1022 usage
1025 break
1027 esac
1028 shift
1029 done
1031 # No command word defaults to "status"
1032 test -n "$command" || command=status
1034 # "-b branch" is accepted only by "add"
1035 if test -n "$branch" && test "$command" != add
1036 then
1037 usage
1040 # "--cached" is accepted only by "status" and "summary"
1041 if test -n "$cached" && test "$command" != status -a "$command" != summary
1042 then
1043 usage
1046 "cmd_$command" "$@"