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] [--checkout|--merge|--rebase] [--reference <repository>] [--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>...]"
22 wt_prefix=$(git rev-parse --show-prefix)
25 # Restrict ourselves to a vanilla subset of protocols; the URLs
26 # we get are under control of a remote repository, and we do not
27 # want them kicking off arbitrary git-remote-* programs.
29 # If the user has already specified a set of allowed protocols,
30 # we assume they know what they're doing and use that instead.
31 : ${GIT_ALLOW_PROTOCOL=file:git:http:https:ssh}
32 export GIT_ALLOW_PROTOCOL
49 # The function takes at most 2 arguments. The first argument is the
50 # URL that navigates to the submodule origin repo. When relative, this URL
51 # is relative to the superproject origin URL repo. The second up_path
52 # argument, if specified, is the relative path that navigates
53 # from the submodule working tree to the superproject working tree.
55 # The output of the function is the origin URL of the submodule.
57 # The output will either be an absolute URL or filesystem path (if the
58 # superproject origin URL is an absolute URL or filesystem path,
59 # respectively) or a relative file system path (if the superproject
60 # origin URL is a relative file system path).
62 # When the output is a relative file system path, the path is either
63 # relative to the submodule working tree, if up_path is specified, or to
64 # the superproject working tree otherwise.
65 resolve_relative_url ()
67 remote=$(get_default_remote)
68 remoteurl=$(git config "remote.$remote.url") ||
69 remoteurl=$(pwd) # the repository is its own authoritative upstream
71 remoteurl=${remoteurl%/}
84 remoteurl="./$remoteurl"
95 remoteurl="${remoteurl%/*}"
98 remoteurl="${remoteurl%:*}"
102 if test -z "$is_relative" || test "." = "$remoteurl"
104 die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
118 remoteurl="$remoteurl$sep${url%/}"
119 echo "${is_relative:+${up_path}}${remoteurl#./}"
122 # Resolve a path to be relative to another path. This is intended for
123 # converting submodule paths when git-submodule is run in a subdirectory
124 # and only handles paths where the directory separator is '/'.
126 # The output is the first argument as a path relative to the second argument,
127 # which defaults to $wt_prefix if it is omitted.
130 local target curdir result
132 curdir=${2-$wt_prefix}
136 while test -n "$curdir"
140 target=${target#"$curdir"/}
145 result="${result}../"
146 if test "$curdir" = "${curdir%/*}"
150 curdir="${curdir%/*}"
154 echo "$result$target"
159 if test "$1" = "#unmatched"
166 # Print a submodule configuration setting
168 # $1 = submodule name
172 # Checks in the usual git-config places first (for overrides),
173 # otherwise it falls back on .gitmodules. This allows you to
174 # distribute project-wide defaults in .gitmodules, while still
175 # customizing individual repositories if necessary. If the option is
176 # not in .gitmodules either, print a default value.
178 get_submodule_config () {
182 value=$(git config submodule."$name"."$option")
185 value=$(git config -f .gitmodules submodule."$name"."$option")
187 printf '%s' "${value:-$default}"
192 n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
195 # Sanitize the local git environment for use within a submodule. We
196 # can't simply use clear_local_git_env since we want to preserve some
197 # of the settings from GIT_CONFIG_PARAMETERS.
198 sanitize_submodule_env()
200 sanitized_config=$(git submodule--helper sanitize-config)
202 GIT_CONFIG_PARAMETERS=$sanitized_config
206 # Add a new submodule to the working tree, .gitmodules and the index
210 # optional branch is stored in global branch variable
214 # parse $args after "submodule ... add".
220 case "$2" in '') usage ;; esac
231 case "$2" in '') usage ;; esac
236 reference_path="${1#--reference=}"
239 case "$2" in '') usage ;; esac
244 case "$2" in '') usage ;; esac
265 if test -n "$reference_path"
267 is_absolute_path "$reference_path" ||
268 reference_path="$wt_prefix$reference_path"
270 reference="--reference=$reference_path"
276 if test -z "$sm_path"; then
277 sm_path=$(printf '%s\n' "$repo" |
278 sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
281 if test -z "$repo" || test -z "$sm_path"; then
285 is_absolute_path "$sm_path" || sm_path="$wt_prefix$sm_path"
287 # assure repo is absolute or relative to parent
290 test -z "$wt_prefix" ||
291 die "$(gettext "Relative path can only be used from the toplevel of the working tree")"
293 # dereference source url relative to parent's url
294 realrepo=$(resolve_relative_url "$repo") || exit
301 die "$(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")"
306 # multiple //; leading ./; /./; /../; trailing /
307 sm_path=$(printf '%s/\n' "$sm_path" |
317 git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
318 die "$(eval_gettext "'\$sm_path' already exists in the index")"
320 if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1
322 eval_gettextln "The following path is ignored by one of your .gitignore files:
324 Use -f if you really want to add it." >&2
328 if test -n "$custom_name"
330 sm_name="$custom_name"
335 # perhaps the path exists and is already a git repo, else clone it
336 if test -e "$sm_path"
338 if test -d "$sm_path"/.git || test -f "$sm_path"/.git
340 eval_gettextln "Adding existing repo at '\$sm_path' to the index"
342 die "$(eval_gettext "'\$sm_path' already exists and is not a valid git repo")"
346 if test -d ".git/modules/$sm_name"
350 echo >&2 "$(eval_gettext "A git directory for '\$sm_name' is found locally with remote(s):")"
351 GIT_DIR=".git/modules/$sm_name" GIT_WORK_TREE=. git remote -v | grep '(fetch)' | sed -e s,^," ", -e s,' (fetch)',, >&2
352 echo >&2 "$(eval_gettext "If you want to reuse this local git directory instead of cloning again from")"
353 echo >&2 " $realrepo"
354 echo >&2 "$(eval_gettext "use the '--force' option. If the local git directory is not the correct repo")"
355 die "$(eval_gettext "or you are unsure what this means choose another name with the '--name' option.")"
357 echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")"
360 git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${depth:+"$depth"} || exit
362 sanitize_submodule_env
364 # ash fails to wordsplit ${branch:+-b "$branch"...}
366 '') git checkout -f -q ;;
367 ?*) git checkout -f -q -B "$branch" "origin/$branch" ;;
369 ) || die "$(eval_gettext "Unable to checkout submodule '\$sm_path'")"
371 git config submodule."$sm_name".url "$realrepo"
373 git add $force "$sm_path" ||
374 die "$(eval_gettext "Failed to add submodule '\$sm_path'")"
376 git config -f .gitmodules submodule."$sm_name".path "$sm_path" &&
377 git config -f .gitmodules submodule."$sm_name".url "$repo" &&
380 git config -f .gitmodules submodule."$sm_name".branch "$branch"
382 git add --force .gitmodules ||
383 die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
387 # Execute an arbitrary command sequence in each checked out
390 # $@ = command to execute
394 # parse $args after "submodule ... foreach".
416 # dup stdin so that it can be restored when running the external
417 # command in the subshell (and a recursive call to this function)
420 git submodule--helper list --prefix "$wt_prefix"|
421 while read mode sha1 stage sm_path
423 die_if_unmatched "$mode"
424 if test -e "$sm_path"/.git
426 displaypath=$(relative_path "$sm_path")
427 say "$(eval_gettext "Entering '\$prefix\$displaypath'")"
428 name=$(git submodule--helper name "$sm_path")
430 prefix="$prefix$sm_path/"
431 sanitize_submodule_env
433 sm_path=$(relative_path "$sm_path") &&
434 # we make $path available to scripts ...
442 if test -n "$recursive"
444 cmd_foreach "--recursive" "$@"
447 die "$(eval_gettext "Stopping at '\$prefix\$displaypath'; script returned non-zero status.")"
453 # Register submodules in .git/config
455 # $@ = requested paths (default to all)
459 # parse $args after "submodule ... init".
480 git submodule--helper list --prefix "$wt_prefix" "$@" |
481 while read mode sha1 stage sm_path
483 die_if_unmatched "$mode"
484 name=$(git submodule--helper name "$sm_path") || exit
486 displaypath=$(relative_path "$sm_path")
488 # Copy url setting when it is not set yet
489 if test -z "$(git config "submodule.$name.url")"
491 url=$(git config -f .gitmodules submodule."$name".url)
493 die "$(eval_gettext "No url found for submodule path '\$displaypath' in .gitmodules")"
495 # Possibly a url relative to parent
498 url=$(resolve_relative_url "$url") || exit
501 git config submodule."$name".url "$url" ||
502 die "$(eval_gettext "Failed to register url for submodule path '\$displaypath'")"
504 say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$displaypath'")"
507 # Copy "update" setting when it is not set yet
508 if upd="$(git config -f .gitmodules submodule."$name".update)" &&
510 test -z "$(git config submodule."$name".update)"
513 checkout | rebase | merge | none)
514 ;; # known modes of updating
516 echo >&2 "warning: unknown update mode '$upd' suggested for submodule '$name'"
520 git config submodule."$name".update "$upd" ||
521 die "$(eval_gettext "Failed to register update mode for submodule path '\$displaypath'")"
527 # Unregister submodules from .git/config and remove their work tree
529 # $@ = requested paths (use '.' to deinit all submodules)
533 # parse $args after "submodule ... deinit".
559 die "$(eval_gettext "Use '.' if you really want to deinitialize all submodules")"
562 git submodule--helper list --prefix "$wt_prefix" "$@" |
563 while read mode sha1 stage sm_path
565 die_if_unmatched "$mode"
566 name=$(git submodule--helper name "$sm_path") || exit
568 displaypath=$(relative_path "$sm_path")
570 # Remove the submodule work tree (unless the user already did it)
571 if test -d "$sm_path"
573 # Protect submodules containing a .git directory
574 if test -d "$sm_path/.git"
576 echo >&2 "$(eval_gettext "Submodule work tree '\$displaypath' contains a .git directory")"
577 die "$(eval_gettext "(use 'rm -rf' if you really want to remove it including all of its history)")"
582 git rm -qn "$sm_path" ||
583 die "$(eval_gettext "Submodule work tree '\$displaypath' contains local modifications; use '-f' to discard them")"
586 say "$(eval_gettext "Cleared directory '\$displaypath'")" ||
587 say "$(eval_gettext "Could not remove submodule work tree '\$displaypath'")"
590 mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$displaypath'")"
592 # Remove the .git/config entries (unless the user already did it)
593 if test -n "$(git config --get-regexp submodule."$name\.")"
595 # Remove the whole section so we have a clean state when
596 # the user later decides to init this submodule again
597 url=$(git config submodule."$name".url)
598 git config --remove-section submodule."$name" 2>/dev/null &&
599 say "$(eval_gettext "Submodule '\$name' (\$url) unregistered for path '\$displaypath'")"
604 is_tip_reachable () (
605 sanitize_submodule_env &&
607 rev=$(git rev-list -n 1 "$2" --not --all 2>/dev/null) &&
611 fetch_in_submodule () (
612 sanitize_submodule_env &&
618 git fetch $(get_default_remote) "$2" ;;
623 # Update each submodule path to correct revision, using clone and checkout as needed
625 # $@ = requested paths (default to all)
629 # parse $args after "submodule ... update".
652 case "$2" in '') usage ;; esac
653 reference="--reference=$2"
669 case "$2" in '') usage ;; esac
677 case "$2" in '') usage ;; esac
700 cmd_init "--" "$@" || return
704 git submodule--helper update-clone ${GIT_QUIET:+--quiet} \
705 ${wt_prefix:+--prefix "$wt_prefix"} \
706 ${prefix:+--recursive-prefix "$prefix"} \
707 ${update:+--update "$update"} \
708 ${reference:+--reference "$reference"} \
709 ${depth:+--depth "$depth"} \
711 "$@" || echo "#unmatched"
714 while read mode sha1 stage just_cloned sm_path
716 die_if_unmatched "$mode"
718 name=$(git submodule--helper name "$sm_path") || exit
719 url=$(git config submodule."$name".url)
720 branch=$(get_submodule_config "$name" branch master)
721 if ! test -z "$update"
723 update_module=$update
725 update_module=$(git config submodule."$name".update)
726 if test -z "$update_module"
728 update_module="checkout"
732 displaypath=$(relative_path "$prefix$sm_path")
734 if test $just_cloned -eq 1
737 update_module=checkout
739 subsha1=$(sanitize_submodule_env; cd "$sm_path" &&
740 git rev-parse --verify HEAD) ||
741 die "$(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
746 if test -z "$nofetch"
748 # Fetch remote before determining tracking $sha1
749 (sanitize_submodule_env; cd "$sm_path" && git-fetch) ||
750 die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
752 remote_name=$(sanitize_submodule_env; cd "$sm_path" && get_default_remote)
753 sha1=$(sanitize_submodule_env; cd "$sm_path" &&
754 git rev-parse --verify "${remote_name}/${branch}") ||
755 die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
758 if test "$subsha1" != "$sha1" || test -n "$force"
761 # If we don't already have a -f flag and the submodule has never been checked out
762 if test -z "$subsha1" && test -z "$force"
767 if test -z "$nofetch"
769 # Run fetch only if $sha1 isn't present or it
770 # is not reachable from a ref.
771 is_tip_reachable "$sm_path" "$sha1" ||
772 fetch_in_submodule "$sm_path" ||
773 die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
775 # Now we tried the usual fetch, but $sha1 may
776 # not be reachable from any of the refs
777 is_tip_reachable "$sm_path" "$sha1" ||
778 fetch_in_submodule "$sm_path" "$sha1" ||
779 die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain $sha1. Direct fetching of that commit failed.")"
783 case "$update_module" in
785 command="git checkout $subforce -q"
786 die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$displaypath'")"
787 say_msg="$(eval_gettext "Submodule path '\$displaypath': checked out '\$sha1'")"
791 die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$displaypath'")"
792 say_msg="$(eval_gettext "Submodule path '\$displaypath': rebased into '\$sha1'")"
793 must_die_on_failure=yes
797 die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$displaypath'")"
798 say_msg="$(eval_gettext "Submodule path '\$displaypath': merged in '\$sha1'")"
799 must_die_on_failure=yes
802 command="${update_module#!}"
803 die_msg="$(eval_gettext "Execution of '\$command \$sha1' failed in submodule path '\$prefix\$sm_path'")"
804 say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': '\$command \$sha1'")"
805 must_die_on_failure=yes
808 die "$(eval_gettext "Invalid update mode '$update_module' for submodule '$name'")"
811 if (sanitize_submodule_env; cd "$sm_path" && $command "$sha1")
814 elif test -n "$must_die_on_failure"
816 die_with_status 2 "$die_msg"
818 err="${err};$die_msg"
823 if test -n "$recursive"
826 prefix="$prefix$sm_path/"
827 sanitize_submodule_env
834 die_msg="$(eval_gettext "Failed to recurse into submodule path '\$displaypath'")"
837 err="${err};$die_msg"
840 die_with_status $res "$die_msg"
865 sanitize_submodule_env
867 git describe "$2" 2>/dev/null ||
868 git describe --tags "$2" 2>/dev/null ||
869 git describe --contains "$2" 2>/dev/null ||
870 git describe --all --always "$2"
873 test -z "$revname" || revname=" ($revname)"
876 # Show commit summary for submodules in index or working tree
878 # If '--cached' is given, show summary between index and given commit,
879 # or between working tree and given commit
881 # $@ = [commit (default 'HEAD'),] requested paths (default all)
888 # parse $args after "submodule ... summary".
903 isnumber "$summary_limit" || usage
907 summary_limit="${1#--summary-limit=}"
908 isnumber "$summary_limit" || usage
924 test $summary_limit = 0 && return
926 if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
930 elif test -z "$1" || test "$1" = "HEAD"
932 # before the first commit: compare with an empty tree
933 head=$(git hash-object -w -t tree --stdin </dev/null)
934 test -z "$1" || shift
942 die "$(gettext "The --cached option cannot be used with the --files option")"
948 eval "set $(git rev-parse --sq --prefix "$wt_prefix" -- "$@")"
949 # Get modified modules cared by user
950 modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
951 sane_egrep '^:([0-7]* )?160000' |
952 while read mod_src mod_dst sha1_src sha1_dst status sm_path
954 # Always show modules deleted or type-changed (blob<->module)
955 if test "$status" = D || test "$status" = T
957 printf '%s\n' "$sm_path"
960 # Respect the ignore setting for --for-status.
961 if test -n "$for_status"
963 name=$(git submodule--helper name "$sm_path")
964 ignore_config=$(get_submodule_config "$name" ignore none)
965 test $status != A && test $ignore_config = all && continue
967 # Also show added or modified modules which are checked out
968 GIT_DIR="$sm_path/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
969 printf '%s\n' "$sm_path"
973 test -z "$modules" && return
975 git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules |
976 sane_egrep '^:([0-7]* )?160000' |
978 while read mod_src mod_dst sha1_src sha1_dst status name
980 if test -z "$cached" &&
981 test $sha1_dst = 0000000000000000000000000000000000000000
985 sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
987 100644 | 100755 | 120000)
988 sha1_dst=$(git hash-object $name)
994 eval_gettextln "unexpected mode \$mod_dst" >&2
1001 test $mod_src = 160000 &&
1002 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_src^0 >/dev/null &&
1005 test $mod_dst = 160000 &&
1006 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
1009 display_name=$(relative_path "$name")
1012 case "$missing_src,$missing_dst" in
1014 errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commit \$sha1_src")"
1017 errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commit \$sha1_dst")"
1020 errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commits \$sha1_src and \$sha1_dst")"
1025 if test $mod_src = 160000 && test $mod_dst = 160000
1027 range="$sha1_src...$sha1_dst"
1028 elif test $mod_src = 160000
1034 GIT_DIR="$name/.git" \
1035 git rev-list --first-parent $range -- | wc -l
1037 total_commits=" ($(($total_commits + 0)))"
1041 sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
1042 sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
1045 blob="$(gettext "blob")"
1046 submodule="$(gettext "submodule")"
1047 if test $mod_dst = 160000
1049 echo "* $display_name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:"
1051 echo "* $display_name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:"
1054 echo "* $display_name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
1056 if test -n "$errmsg"
1058 # Don't give error msg for modification whose dst is not submodule
1059 # i.e. deleted or changed to blob
1060 test $mod_dst = 160000 && echo "$errmsg"
1062 if test $mod_src = 160000 && test $mod_dst = 160000
1065 test $summary_limit -gt 0 && limit="-$summary_limit"
1066 GIT_DIR="$name/.git" \
1067 git log $limit --pretty='format: %m %s' \
1068 --first-parent $sha1_src...$sha1_dst
1069 elif test $mod_dst = 160000
1071 GIT_DIR="$name/.git" \
1072 git log --pretty='format: > %s' -1 $sha1_dst
1074 GIT_DIR="$name/.git" \
1075 git log --pretty='format: < %s' -1 $sha1_src
1083 # List all submodules, prefixed with:
1084 # - submodule not initialized
1085 # + different revision checked out
1087 # If --cached was specified the revision in the index will be printed
1088 # instead of the currently checked out revision.
1090 # $@ = requested paths (default to all)
1094 # parse $args after "submodule ... status".
1121 git submodule--helper list --prefix "$wt_prefix" "$@" |
1122 while read mode sha1 stage sm_path
1124 die_if_unmatched "$mode"
1125 name=$(git submodule--helper name "$sm_path") || exit
1126 url=$(git config submodule."$name".url)
1127 displaypath=$(relative_path "$prefix$sm_path")
1128 if test "$stage" = U
1130 say "U$sha1 $displaypath"
1133 if test -z "$url" ||
1135 ! test -d "$sm_path"/.git &&
1136 ! test -f "$sm_path"/.git
1139 say "-$sha1 $displaypath"
1142 if git diff-files --ignore-submodules=dirty --quiet -- "$sm_path"
1144 set_name_rev "$sm_path" "$sha1"
1145 say " $sha1 $displaypath$revname"
1147 if test -z "$cached"
1149 sha1=$(sanitize_submodule_env; cd "$sm_path" && git rev-parse --verify HEAD)
1151 set_name_rev "$sm_path" "$sha1"
1152 say "+$sha1 $displaypath$revname"
1155 if test -n "$recursive"
1158 prefix="$displaypath/"
1159 sanitize_submodule_env
1163 die "$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
1168 # Sync remote urls for submodules
1169 # This makes the value for remote.$remote.url match the value
1170 # specified in .gitmodules.
1198 git submodule--helper list --prefix "$wt_prefix" "$@" |
1199 while read mode sha1 stage sm_path
1201 die_if_unmatched "$mode"
1202 name=$(git submodule--helper name "$sm_path")
1203 url=$(git config -f .gitmodules --get submodule."$name".url)
1205 # Possibly a url relative to parent
1208 # rewrite foo/bar as ../.. to find path from
1209 # submodule work tree to superproject work tree
1210 up_path="$(printf '%s\n' "$sm_path" | sed "s/[^/][^/]*/../g")" &&
1211 # guarantee a trailing /
1212 up_path=${up_path%/}/ &&
1213 # path from submodule work tree to submodule origin repo
1214 sub_origin_url=$(resolve_relative_url "$url" "$up_path") &&
1215 # path from superproject work tree to submodule origin repo
1216 super_config_url=$(resolve_relative_url "$url") || exit
1219 sub_origin_url="$url"
1220 super_config_url="$url"
1224 if git config "submodule.$name.url" >/dev/null 2>/dev/null
1226 displaypath=$(relative_path "$prefix$sm_path")
1227 say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")"
1228 git config submodule."$name".url "$super_config_url"
1230 if test -e "$sm_path"/.git
1233 sanitize_submodule_env
1235 remote=$(get_default_remote)
1236 git config remote."$remote".url "$sub_origin_url"
1238 if test -n "$recursive"
1240 prefix="$prefix$sm_path/"
1249 # This loop parses the command line arguments to find the
1250 # subcommand name to dispatch. Parsing of the subcommand specific
1251 # options are primarily done by the subcommand implementations.
1252 # Subcommand specific options such as --branch and --cached are
1253 # parsed here as well, for backward compatibility.
1255 while test $# != 0 && test -z "$command"
1258 add | foreach | init | deinit | update | status | summary | sync)
1288 # No command word defaults to "status"
1289 if test -z "$command"
1299 # "-b branch" is accepted only by "add"
1300 if test -n "$branch" && test "$command" != add
1305 # "--cached" is accepted only by "status" and "summary"
1306 if test -n "$cached" && test "$command" != status && test "$command" != summary