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] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
9 or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
10 or: $dashless [--quiet] init [--] [<path>...]
11 or: $dashless [--quiet] deinit [-f|--force] [--] <path>...
12 or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--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>...]"
37 # The function takes at most 2 arguments. The first argument is the
38 # URL that navigates to the submodule origin repo. When relative, this URL
39 # is relative to the superproject origin URL repo. The second up_path
40 # argument, if specified, is the relative path that navigates
41 # from the submodule working tree to the superproject working tree.
43 # The output of the function is the origin URL of the submodule.
45 # The output will either be an absolute URL or filesystem path (if the
46 # superproject origin URL is an absolute URL or filesystem path,
47 # respectively) or a relative file system path (if the superproject
48 # origin URL is a relative file system path).
50 # When the output is a relative file system path, the path is either
51 # relative to the submodule working tree, if up_path is specified, or to
52 # the superproject working tree otherwise.
53 resolve_relative_url
()
55 remote
=$
(get_default_remote
)
56 remoteurl
=$
(git config
"remote.$remote.url") ||
57 remoteurl
=$
(pwd) # the repository is its own authoritative upstream
59 remoteurl
=${remoteurl%/}
72 remoteurl
="./$remoteurl"
83 remoteurl
="${remoteurl%/*}"
86 remoteurl
="${remoteurl%:*}"
90 if test -z "$is_relative" ||
test "." = "$remoteurl"
92 die
"$(eval_gettext "cannot strip one component off url
'\$remoteurl'")"
106 remoteurl
="$remoteurl$sep${url%/}"
107 echo "${is_relative:+${up_path}}${remoteurl#./}"
111 # Get submodule info for registered submodules
112 # $@ = path to limit submodule list
117 git ls-files
--error-unmatch --stage -- "$@" ||
118 echo "unmatched pathspec exists"
122 my ($null_sha1) = ("0" x 40);
126 if (/^unmatched pathspec/) {
131 my ($mode, $sha1, $stage, $path) =
132 /^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
133 next unless $mode eq "160000";
135 if (!$unmerged{$path}++) {
136 push @out, "$mode $null_sha1 U\t$path\n";
143 print "#unmatched\n";
152 if test "$1" = "#unmatched"
159 # Print a submodule configuration setting
161 # $1 = submodule name
165 # Checks in the usual git-config places first (for overrides),
166 # otherwise it falls back on .gitmodules. This allows you to
167 # distribute project-wide defaults in .gitmodules, while still
168 # customizing individual repositories if necessary. If the option is
169 # not in .gitmodules either, print a default value.
171 get_submodule_config
() {
175 value
=$
(git config submodule.
"$name".
"$option")
178 value
=$
(git config
-f .gitmodules submodule.
"$name".
"$option")
180 printf '%s' "${value:-$default}"
185 # Map submodule path to submodule name
191 # Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
193 re
=$
(printf '%s\n' "$1" |
sed -e 's/[].[^$\\*]/\\&/g')
194 name
=$
( git config
-f .gitmodules
--get-regexp '^submodule\..*\.path$' |
195 sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
197 die
"$(eval_gettext "No submodule mapping found
in .gitmodules
for path
'\$sm_path'")"
204 # Prior to calling, cmd_update checks that a possibly existing
205 # path is not a git repository.
206 # Likewise, cmd_add checks that path does not exist at all,
207 # since it is the location of a new submodule.
217 if test -n "$GIT_QUIET"
224 base_name
=$
(dirname "$name")
226 gitdir
=$
(git rev-parse
--git-dir)
227 gitdir_base
="$gitdir/modules/$base_name"
228 gitdir
="$gitdir/modules/$name"
233 rm -f "$gitdir/index"
235 mkdir
-p "$gitdir_base"
238 git clone
$quiet ${depth:+"$depth"} -n ${reference:+"$reference"} \
239 --separate-git-dir "$gitdir" "$url" "$sm_path"
241 die
"$(eval_gettext "Clone of
'\$url' into submodule path
'\$sm_path' failed
")"
244 # We already are at the root of the work tree but cd_to_toplevel will
245 # resolve any symlinks that might be present in $PWD
246 a
=$
(cd_to_toplevel
&& cd "$gitdir" && pwd)/
247 b
=$
(cd_to_toplevel
&& cd "$sm_path" && pwd)/
248 # normalize Windows-style absolute paths to POSIX-style absolute paths
249 case $a in [a-zA-Z
]:/*) a
=/${a%%:*}${a#*:} ;; esac
250 case $b in [a-zA-Z
]:/*) b
=/${b%%:*}${b#*:} ;; esac
251 # Remove all common leading directories after a sanity check
252 if test "${a#$b}" != "$a" ||
test "${b#$a}" != "$b"; then
253 die
"$(eval_gettext "Gitdir
'\$a' is part of the submodule path
'\$b' or vice versa
")"
255 while test "${a%%/*}" = "${b%%/*}"
260 # Now chop off the trailing '/'s that were added in the beginning
264 # Turn each leading "*/" component into "../"
265 rel
=$
(echo $b |
sed -e 's|[^/][^/]*|..|g')
266 echo "gitdir: $rel/$a" >"$sm_path/.git"
268 rel
=$
(echo $a |
sed -e 's|[^/][^/]*|..|g')
269 (clear_local_git_env
; cd "$sm_path" && GIT_WORK_TREE
=. git config core.worktree
"$rel/$b")
274 n
=$
(($1 + 0)) 2>/dev
/null
&& test "$n" = "$1"
278 # Add a new submodule to the working tree, .gitmodules and the index
282 # optional branch is stored in global branch variable
286 # parse $args after "submodule ... add".
291 case "$2" in '') usage
;; esac
302 case "$2" in '') usage
;; esac
303 reference
="--reference=$2"
310 case "$2" in '') usage
;; esac
315 case "$2" in '') usage
;; esac
339 if test -z "$sm_path"; then
340 sm_path
=$
(echo "$repo" |
341 sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
344 if test -z "$repo" -o -z "$sm_path"; then
348 # assure repo is absolute or relative to parent
351 # dereference source url relative to parent's url
352 realrepo
=$
(resolve_relative_url
"$repo") ||
exit
359 die
"$(eval_gettext "repo URL
: '\$repo' must be absolute or begin with .
/|..
/")"
364 # multiple //; leading ./; /./; /../; trailing /
365 sm_path
=$
(printf '%s/\n' "$sm_path" |
375 git ls-files
--error-unmatch "$sm_path" > /dev
/null
2>&1 &&
376 die
"$(eval_gettext "'\$sm_path' already exists
in the index
")"
378 if test -z "$force" && ! git add
--dry-run --ignore-missing "$sm_path" > /dev
/null
2>&1
380 eval_gettextln
"The following path is ignored by one of your .gitignore files:
382 Use -f if you really want to add it." >&2
386 if test -n "$custom_name"
388 sm_name
="$custom_name"
393 # perhaps the path exists and is already a git repo, else clone it
394 if test -e "$sm_path"
396 if test -d "$sm_path"/.git
-o -f "$sm_path"/.git
398 eval_gettextln
"Adding existing repo at '\$sm_path' to the index"
400 die
"$(eval_gettext "'\$sm_path' already exists and is not a valid git repo
")"
404 if test -d ".git/modules/$sm_name"
408 echo >&2 "$(eval_gettext "A git directory
for '\$sm_name' is found locally with remote
(s
):")"
409 GIT_DIR
=".git/modules/$sm_name" GIT_WORK_TREE
=. git remote
-v |
grep '(fetch)' |
sed -e s
,^
," ", -e s
,' (fetch)',, >&2
410 echo >&2 "$(eval_gettext "If you want to reuse this
local git directory instead of cloning again from
")"
411 echo >&2 " $realrepo"
412 echo >&2 "$(eval_gettext "use the
'--force' option. If the
local git directory is not the correct repo
")"
413 die
"$(eval_gettext "or you are unsure what this means choose another name with the
'--name' option.
")"
415 echo "$(eval_gettext "Reactivating
local git directory
for submodule
'\$sm_name'.
")"
418 module_clone
"$sm_path" "$sm_name" "$realrepo" "$reference" "$depth" ||
exit
422 # ash fails to wordsplit ${branch:+-b "$branch"...}
424 '') git checkout
-f -q ;;
425 ?
*) git checkout
-f -q -B "$branch" "origin/$branch" ;;
427 ) || die
"$(eval_gettext "Unable to checkout submodule
'\$sm_path'")"
429 git config submodule.
"$sm_name".url
"$realrepo"
431 git add
$force "$sm_path" ||
432 die
"$(eval_gettext "Failed to add submodule
'\$sm_path'")"
434 git config
-f .gitmodules submodule.
"$sm_name".path
"$sm_path" &&
435 git config
-f .gitmodules submodule.
"$sm_name".url
"$repo" &&
438 git config
-f .gitmodules submodule.
"$sm_name".branch
"$branch"
440 git add
--force .gitmodules ||
441 die
"$(eval_gettext "Failed to register submodule
'\$sm_path'")"
445 # Execute an arbitrary command sequence in each checked out
448 # $@ = command to execute
452 # parse $args after "submodule ... foreach".
474 # dup stdin so that it can be restored when running the external
475 # command in the subshell (and a recursive call to this function)
479 while read mode sha1 stage sm_path
481 die_if_unmatched
"$mode"
482 if test -e "$sm_path"/.git
484 say
"$(eval_gettext "Entering
'\$prefix\$sm_path'")"
485 name
=$
(module_name
"$sm_path")
487 prefix
="$prefix$sm_path/"
489 # we make $path available to scripts ...
493 if test -n "$recursive"
495 cmd_foreach
"--recursive" "$@"
498 die
"$(eval_gettext "Stopping
at '\$sm_path'; script returned non-zero status.
")"
504 # Register submodules in .git/config
506 # $@ = requested paths (default to all)
510 # parse $args after "submodule ... init".
532 while read mode sha1 stage sm_path
534 die_if_unmatched
"$mode"
535 name
=$
(module_name
"$sm_path") ||
exit
537 # Copy url setting when it is not set yet
538 if test -z "$(git config "submodule.
$name.url
")"
540 url
=$
(git config
-f .gitmodules submodule.
"$name".url
)
542 die
"$(eval_gettext "No url found
for submodule path
'\$sm_path' in .gitmodules
")"
544 # Possibly a url relative to parent
547 url
=$
(resolve_relative_url
"$url") ||
exit
550 git config submodule.
"$name".url
"$url" ||
551 die
"$(eval_gettext "Failed to register url
for submodule path
'\$sm_path'")"
553 say
"$(eval_gettext "Submodule
'\$name' (\
$url) registered
for path
'\$sm_path'")"
556 # Copy "update" setting when it is not set yet
557 upd
="$(git config -f .gitmodules submodule."$name".update)"
559 test -n "$(git config submodule."$name".update)" ||
560 git config submodule.
"$name".update
"$upd" ||
561 die
"$(eval_gettext "Failed to register update mode
for submodule path
'\$sm_path'")"
566 # Unregister submodules from .git/config and remove their work tree
568 # $@ = requested paths (use '.' to deinit all submodules)
572 # parse $args after "submodule ... deinit".
598 die
"$(eval_gettext "Use
'.' if you really want to deinitialize all submodules
")"
602 while read mode sha1 stage sm_path
604 die_if_unmatched
"$mode"
605 name
=$
(module_name
"$sm_path") ||
exit
607 # Remove the submodule work tree (unless the user already did it)
608 if test -d "$sm_path"
610 # Protect submodules containing a .git directory
611 if test -d "$sm_path/.git"
613 echo >&2 "$(eval_gettext "Submodule work tree
'\$sm_path' contains a .git directory
")"
614 die
"$(eval_gettext "(use
'rm -rf' if you really want to remove it including all of its
history)")"
619 git
rm -qn "$sm_path" ||
620 die
"$(eval_gettext "Submodule work tree
'\$sm_path' contains
local modifications
; use
'-f' to discard them
")"
623 say
"$(eval_gettext "Cleared directory
'\$sm_path'")" ||
624 say
"$(eval_gettext "Could not remove submodule work tree
'\$sm_path'")"
627 mkdir
"$sm_path" || say
"$(eval_gettext "Could not create empty submodule directory
'\$sm_path'")"
629 # Remove the .git/config entries (unless the user already did it)
630 if test -n "$(git config --get-regexp submodule."$name\.
")"
632 # Remove the whole section so we have a clean state when
633 # the user later decides to init this submodule again
634 url
=$
(git config submodule.
"$name".url
)
635 git config
--remove-section submodule.
"$name" 2>/dev
/null
&&
636 say
"$(eval_gettext "Submodule
'\$name' (\
$url) unregistered
for path
'\$sm_path'")"
642 # Update each submodule path to correct revision, using clone and checkout as needed
644 # $@ = requested paths (default to all)
648 # parse $args after "submodule ... update".
672 case "$2" in '') usage
;; esac
673 reference
="--reference=$2"
674 orig_flags
="$orig_flags $(git rev-parse --sq-quote "$1")"
690 case "$2" in '') usage
;; esac
708 orig_flags
="$orig_flags $(git rev-parse --sq-quote "$1")"
714 cmd_init
"--" "$@" ||
return
720 while read mode sha1 stage sm_path
722 die_if_unmatched
"$mode"
725 echo >&2 "Skipping unmerged submodule $prefix$sm_path"
728 name
=$
(module_name
"$sm_path") ||
exit
729 url
=$
(git config submodule.
"$name".url
)
730 branch
=$
(get_submodule_config
"$name" branch master
)
731 if ! test -z "$update"
733 update_module
=$update
735 update_module
=$
(git config submodule.
"$name".update
)
738 if test "$update_module" = "none"
740 echo "Skipping submodule '$prefix$sm_path'"
746 # Only mention uninitialized submodules when its
747 # path have been specified
749 say
"$(eval_gettext "Submodule path
'\$prefix\$sm_path' not initialized
750 Maybe you want to use
'update --init'?
")"
754 if ! test -d "$sm_path"/.git
-o -f "$sm_path"/.git
756 module_clone
"$sm_path" "$name" "$url" "$reference" "$depth" ||
exit
757 cloned_modules
="$cloned_modules;$name"
760 subsha1
=$
(clear_local_git_env
; cd "$sm_path" &&
761 git rev-parse
--verify HEAD
) ||
762 die
"$(eval_gettext "Unable to
find current revision
in submodule path
'\$prefix\$sm_path'")"
767 if test -z "$nofetch"
769 # Fetch remote before determining tracking $sha1
770 (clear_local_git_env
; cd "$sm_path" && git-fetch
) ||
771 die
"$(eval_gettext "Unable to fetch
in submodule path
'\$sm_path'")"
773 remote_name
=$
(clear_local_git_env
; cd "$sm_path" && get_default_remote
)
774 sha1
=$
(clear_local_git_env
; cd "$sm_path" &&
775 git rev-parse
--verify "${remote_name}/${branch}") ||
776 die
"$(eval_gettext "Unable to
find current
${remote_name}/${branch} revision
in submodule path
'\$sm_path'")"
779 if test "$subsha1" != "$sha1" -o -n "$force"
782 # If we don't already have a -f flag and the submodule has never been checked out
783 if test -z "$subsha1" -a -z "$force"
788 if test -z "$nofetch"
790 # Run fetch only if $sha1 isn't present or it
791 # is not reachable from a ref.
792 (clear_local_git_env
; cd "$sm_path" &&
793 ( (rev=$
(git rev-list
-n 1 $sha1 --not --all 2>/dev
/null
) &&
794 test -z "$rev") || git-fetch
)) ||
795 die
"$(eval_gettext "Unable to fetch
in submodule path
'\$prefix\$sm_path'")"
798 # Is this something we just cloned?
799 case ";$cloned_modules;" in
801 # then there is no local change to integrate
806 case "$update_module" in
809 die_msg
="$(eval_gettext "Unable to rebase
'\$sha1' in submodule path
'\$prefix\$sm_path'")"
810 say_msg
="$(eval_gettext "Submodule path
'\$prefix\$sm_path': rebased into
'\$sha1'")"
811 must_die_on_failure
=yes
815 die_msg
="$(eval_gettext "Unable to merge
'\$sha1' in submodule path
'\$prefix\$sm_path'")"
816 say_msg
="$(eval_gettext "Submodule path
'\$prefix\$sm_path': merged
in '\$sha1'")"
817 must_die_on_failure
=yes
820 command="git checkout $subforce -q"
821 die_msg
="$(eval_gettext "Unable to checkout
'\$sha1' in submodule path
'\$prefix\$sm_path'")"
822 say_msg
="$(eval_gettext "Submodule path
'\$prefix\$sm_path': checked out
'\$sha1'")"
826 if (clear_local_git_env
; cd "$sm_path" && $command "$sha1")
829 elif test -n "$must_die_on_failure"
831 die_with_status
2 "$die_msg"
833 err
="${err};$die_msg"
838 if test -n "$recursive"
841 prefix
="$prefix$sm_path/"
844 eval cmd_update
"$orig_flags"
849 die_msg
="$(eval_gettext "Failed to recurse into submodule path
'\$prefix\$sm_path'")"
852 err
="${err};$die_msg"
855 die_with_status
$res "$die_msg"
882 git describe
"$2" 2>/dev
/null ||
883 git describe
--tags "$2" 2>/dev
/null ||
884 git describe
--contains "$2" 2>/dev
/null ||
885 git describe
--all --always "$2"
888 test -z "$revname" || revname
=" ($revname)"
891 # Show commit summary for submodules in index or working tree
893 # If '--cached' is given, show summary between index and given commit,
894 # or between working tree and given commit
896 # $@ = [commit (default 'HEAD'),] requested paths (default all)
903 # parse $args after "submodule ... summary".
918 isnumber
"$summary_limit" || usage
922 summary_limit
="${1#--summary-limit=}"
923 isnumber
"$summary_limit" || usage
939 test $summary_limit = 0 && return
941 if rev=$
(git rev-parse
-q --verify --default HEAD
${1+"$1"})
945 elif test -z "$1" -o "$1" = "HEAD"
947 # before the first commit: compare with an empty tree
948 head=$
(git hash-object
-w -t tree
--stdin </dev
/null
)
949 test -z "$1" ||
shift
957 die
"$(gettext "The
--cached option cannot be used with the
--files option
")"
963 # Get modified modules cared by user
964 modules
=$
(git
$diff_cmd $cached --ignore-submodules=dirty
--raw $head -- "$@" |
965 sane_egrep
'^:([0-7]* )?160000' |
966 while read mod_src mod_dst sha1_src sha1_dst status name
968 # Always show modules deleted or type-changed (blob<->module)
969 test $status = D
-o $status = T
&& echo "$name" && continue
970 # Also show added or modified modules which are checked out
971 GIT_DIR
="$name/.git" git-rev-parse
--git-dir >/dev
/null
2>&1 &&
976 test -z "$modules" && return
978 git
$diff_cmd $cached --ignore-submodules=dirty
--raw $head -- $modules |
979 sane_egrep
'^:([0-7]* )?160000' |
981 while read mod_src mod_dst sha1_src sha1_dst status name
983 if test -z "$cached" &&
984 test $sha1_dst = 0000000000000000000000000000000000000000
988 sha1_dst
=$
(GIT_DIR
="$name/.git" git rev-parse HEAD
)
990 100644 |
100755 |
120000)
991 sha1_dst
=$
(git hash-object
$name)
997 eval_gettextln
"unexpected mode \$mod_dst" >&2
1004 test $mod_src = 160000 &&
1005 ! GIT_DIR
="$name/.git" git-rev-parse
-q --verify $sha1_src^
0 >/dev
/null
&&
1008 test $mod_dst = 160000 &&
1009 ! GIT_DIR
="$name/.git" git-rev-parse
-q --verify $sha1_dst^
0 >/dev
/null
&&
1013 case "$missing_src,$missing_dst" in
1015 errmsg
="$(eval_gettext " Warn
: \
$name doesn
't contain commit \$sha1_src")"
1018 errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \
$sha1_dst")"
1021 errmsg
="$(eval_gettext " Warn
: \
$name doesn
't contain commits \$sha1_src and \$sha1_dst")"
1026 if test $mod_src = 160000 -a $mod_dst = 160000
1028 range="$sha1_src...$sha1_dst"
1029 elif test $mod_src = 160000
1035 GIT_DIR="$name/.git" \
1036 git rev-list --first-parent $range -- | wc -l
1038 total_commits=" ($(($total_commits + 0)))"
1042 sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
1043 sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
1046 blob="$(gettext "blob")"
1047 submodule="$(gettext "submodule")"
1048 if test $mod_dst = 160000
1050 echo "* $name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:"
1052 echo "* $name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:"
1055 echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
1057 if test -n "$errmsg"
1059 # Don't give error msg
for modification whose dst is not submodule
1060 # i.e. deleted or changed to blob
1061 test $mod_dst = 160000 && echo "$errmsg"
1063 if test $mod_src = 160000 -a $mod_dst = 160000
1066 test $summary_limit -gt 0 && limit
="-$summary_limit"
1067 GIT_DIR
="$name/.git" \
1068 git log
$limit --pretty='format: %m %s' \
1069 --first-parent $sha1_src...
$sha1_dst
1070 elif test $mod_dst = 160000
1072 GIT_DIR
="$name/.git" \
1073 git log
--pretty='format: > %s' -1 $sha1_dst
1075 GIT_DIR
="$name/.git" \
1076 git log
--pretty='format: < %s' -1 $sha1_src
1082 if test -n "$for_status"; then
1083 if [ -n "$files" ]; then
1084 gettextln
"Submodules changed but not updated:" | git stripspace
-c
1086 gettextln
"Submodule changes to be committed:" | git stripspace
-c
1088 printf "\n" | git stripspace
-c
1095 # List all submodules, prefixed with:
1096 # - submodule not initialized
1097 # + different revision checked out
1099 # If --cached was specified the revision in the index will be printed
1100 # instead of the currently checked out revision.
1102 # $@ = requested paths (default to all)
1106 # parse $args after "submodule ... status".
1134 while read mode sha1 stage sm_path
1136 die_if_unmatched
"$mode"
1137 name
=$
(module_name
"$sm_path") ||
exit
1138 url
=$
(git config submodule.
"$name".url
)
1139 displaypath
="$prefix$sm_path"
1140 if test "$stage" = U
1142 say
"U$sha1 $displaypath"
1145 if test -z "$url" ||
! test -d "$sm_path"/.git
-o -f "$sm_path"/.git
1147 say
"-$sha1 $displaypath"
1150 set_name_rev
"$sm_path" "$sha1"
1151 if git diff-files
--ignore-submodules=dirty
--quiet -- "$sm_path"
1153 say
" $sha1 $displaypath$revname"
1155 if test -z "$cached"
1157 sha1
=$
(clear_local_git_env
; cd "$sm_path" && git rev-parse
--verify HEAD
)
1158 set_name_rev
"$sm_path" "$sha1"
1160 say
"+$sha1 $displaypath$revname"
1163 if test -n "$recursive"
1166 prefix
="$displaypath/"
1171 die
"$(eval_gettext "Failed to recurse into submodule path
'\$sm_path'")"
1176 # Sync remote urls for submodules
1177 # This makes the value for remote.$remote.url match the value
1178 # specified in .gitmodules.
1207 while read mode sha1 stage sm_path
1209 die_if_unmatched
"$mode"
1210 name
=$
(module_name
"$sm_path")
1211 url
=$
(git config
-f .gitmodules
--get submodule.
"$name".url
)
1213 # Possibly a url relative to parent
1216 # rewrite foo/bar as ../.. to find path from
1217 # submodule work tree to superproject work tree
1218 up_path
="$(echo "$sm_path" | sed "s
/[^
/][^
/]*/..
/g
")" &&
1219 # guarantee a trailing /
1220 up_path
=${up_path%/}/ &&
1221 # path from submodule work tree to submodule origin repo
1222 sub_origin_url
=$
(resolve_relative_url
"$url" "$up_path") &&
1223 # path from superproject work tree to submodule origin repo
1224 super_config_url
=$
(resolve_relative_url
"$url") ||
exit
1227 sub_origin_url
="$url"
1228 super_config_url
="$url"
1232 if git config
"submodule.$name.url" >/dev
/null
2>/dev
/null
1234 say
"$(eval_gettext "Synchronizing submodule url
for '\$prefix\$sm_path'")"
1235 git config submodule.
"$name".url
"$super_config_url"
1237 if test -e "$sm_path"/.git
1242 remote
=$
(get_default_remote
)
1243 git config remote.
"$remote".url
"$sub_origin_url"
1245 if test -n "$recursive"
1247 prefix
="$prefix$sm_path/"
1256 # This loop parses the command line arguments to find the
1257 # subcommand name to dispatch. Parsing of the subcommand specific
1258 # options are primarily done by the subcommand implementations.
1259 # Subcommand specific options such as --branch and --cached are
1260 # parsed here as well, for backward compatibility.
1262 while test $# != 0 && test -z "$command"
1265 add | foreach | init | deinit | update | status | summary | sync
)
1295 # No command word defaults to "status"
1296 if test -z "$command"
1306 # "-b branch" is accepted only by "add"
1307 if test -n "$branch" && test "$command" != add
1312 # "--cached" is accepted only by "status" and "summary"
1313 if test -n "$cached" && test "$command" != status
-a "$command" != summary