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)
40 # The function takes at most 2 arguments. The first argument is the
41 # URL that navigates to the submodule origin repo. When relative, this URL
42 # is relative to the superproject origin URL repo. The second up_path
43 # argument, if specified, is the relative path that navigates
44 # from the submodule working tree to the superproject working tree.
46 # The output of the function is the origin URL of the submodule.
48 # The output will either be an absolute URL or filesystem path (if the
49 # superproject origin URL is an absolute URL or filesystem path,
50 # respectively) or a relative file system path (if the superproject
51 # origin URL is a relative file system path).
53 # When the output is a relative file system path, the path is either
54 # relative to the submodule working tree, if up_path is specified, or to
55 # the superproject working tree otherwise.
56 resolve_relative_url
()
58 remote
=$
(get_default_remote
)
59 remoteurl
=$
(git config
"remote.$remote.url") ||
60 remoteurl
=$
(pwd) # the repository is its own authoritative upstream
62 remoteurl
=${remoteurl%/}
75 remoteurl
="./$remoteurl"
86 remoteurl
="${remoteurl%/*}"
89 remoteurl
="${remoteurl%:*}"
93 if test -z "$is_relative" ||
test "." = "$remoteurl"
95 die
"$(eval_gettext "cannot strip one component off url
'\$remoteurl'")"
109 remoteurl
="$remoteurl$sep${url%/}"
110 echo "${is_relative:+${up_path}}${remoteurl#./}"
113 # Resolve a path to be relative to another path. This is intended for
114 # converting submodule paths when git-submodule is run in a subdirectory
115 # and only handles paths where the directory separator is '/'.
117 # The output is the first argument as a path relative to the second argument,
118 # which defaults to $wt_prefix if it is omitted.
121 local target curdir result
123 curdir
=${2-$wt_prefix}
127 while test -n "$curdir"
131 target
=${target#"$curdir"/}
136 result
="${result}../"
137 if test "$curdir" = "${curdir%/*}"
141 curdir
="${curdir%/*}"
145 echo "$result$target"
150 if test "$1" = "#unmatched"
157 # Print a submodule configuration setting
159 # $1 = submodule name
163 # Checks in the usual git-config places first (for overrides),
164 # otherwise it falls back on .gitmodules. This allows you to
165 # distribute project-wide defaults in .gitmodules, while still
166 # customizing individual repositories if necessary. If the option is
167 # not in .gitmodules either, print a default value.
169 get_submodule_config
() {
173 value
=$
(git config submodule.
"$name".
"$option")
176 value
=$
(git config
-f .gitmodules submodule.
"$name".
"$option")
178 printf '%s' "${value:-$default}"
184 # $1 = submodule path
185 # $2 = submodule name
187 # $4 = reference repository to reuse (empty for independent)
188 # $5 = depth argument for shallow clones (empty for deep)
190 # Prior to calling, cmd_update checks that a possibly existing
191 # path is not a git repository.
192 # Likewise, cmd_add checks that path does not exist at all,
193 # since it is the location of a new submodule.
203 if test -n "$GIT_QUIET"
210 base_name
=$
(dirname "$name")
212 gitdir
=$
(git rev-parse
--git-dir)
213 gitdir_base
="$gitdir/modules/$base_name"
214 gitdir
="$gitdir/modules/$name"
219 rm -f "$gitdir/index"
221 mkdir
-p "$gitdir_base"
224 git clone
$quiet ${depth:+"$depth"} -n ${reference:+"$reference"} \
225 --separate-git-dir "$gitdir" "$url" "$sm_path"
227 die
"$(eval_gettext "Clone of
'\$url' into submodule path
'\$sm_path' failed
")"
230 # We already are at the root of the work tree but cd_to_toplevel will
231 # resolve any symlinks that might be present in $PWD
232 a
=$
(cd_to_toplevel
&& cd "$gitdir" && pwd)/
233 b
=$
(cd_to_toplevel
&& cd "$sm_path" && pwd)/
234 # Remove all common leading directories after a sanity check
235 if test "${a#$b}" != "$a" ||
test "${b#$a}" != "$b"; then
236 die
"$(eval_gettext "Gitdir
'\$a' is part of the submodule path
'\$b' or vice versa
")"
238 while test "${a%%/*}" = "${b%%/*}"
243 # Now chop off the trailing '/'s that were added in the beginning
247 # Turn each leading "*/" component into "../"
248 rel
=$
(printf '%s\n' "$b" |
sed -e 's|[^/][^/]*|..|g')
249 printf '%s\n' "gitdir: $rel/$a" >"$sm_path/.git"
251 rel
=$
(printf '%s\n' "$a" |
sed -e 's|[^/][^/]*|..|g')
252 (clear_local_git_env
; cd "$sm_path" && GIT_WORK_TREE
=. git config core.worktree
"$rel/$b")
257 n
=$
(($1 + 0)) 2>/dev
/null
&& test "$n" = "$1"
261 # Add a new submodule to the working tree, .gitmodules and the index
265 # optional branch is stored in global branch variable
269 # parse $args after "submodule ... add".
275 case "$2" in '') usage
;; esac
286 case "$2" in '') usage
;; esac
291 reference_path
="${1#--reference=}"
294 case "$2" in '') usage
;; esac
299 case "$2" in '') usage
;; esac
320 if test -n "$reference_path"
322 is_absolute_path
"$reference_path" ||
323 reference_path
="$wt_prefix$reference_path"
325 reference
="--reference=$reference_path"
331 if test -z "$sm_path"; then
332 sm_path
=$
(printf '%s\n' "$repo" |
333 sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
336 if test -z "$repo" ||
test -z "$sm_path"; then
340 is_absolute_path
"$sm_path" || sm_path
="$wt_prefix$sm_path"
342 # assure repo is absolute or relative to parent
345 test -z "$wt_prefix" ||
346 die
"$(gettext "Relative path can only be used from the toplevel of the working tree
")"
348 # dereference source url relative to parent's url
349 realrepo
=$
(resolve_relative_url
"$repo") ||
exit
356 die
"$(eval_gettext "repo URL
: '\$repo' must be absolute or begin with .
/|..
/")"
361 # multiple //; leading ./; /./; /../; trailing /
362 sm_path
=$
(printf '%s/\n' "$sm_path" |
372 git ls-files
--error-unmatch "$sm_path" > /dev
/null
2>&1 &&
373 die
"$(eval_gettext "'\$sm_path' already exists
in the index
")"
375 if test -z "$force" && ! git add
--dry-run --ignore-missing "$sm_path" > /dev
/null
2>&1
377 eval_gettextln
"The following path is ignored by one of your .gitignore files:
379 Use -f if you really want to add it." >&2
383 if test -n "$custom_name"
385 sm_name
="$custom_name"
390 # perhaps the path exists and is already a git repo, else clone it
391 if test -e "$sm_path"
393 if test -d "$sm_path"/.git ||
test -f "$sm_path"/.git
395 eval_gettextln
"Adding existing repo at '\$sm_path' to the index"
397 die
"$(eval_gettext "'\$sm_path' already exists and is not a valid git repo
")"
401 if test -d ".git/modules/$sm_name"
405 echo >&2 "$(eval_gettext "A git directory
for '\$sm_name' is found locally with remote
(s
):")"
406 GIT_DIR
=".git/modules/$sm_name" GIT_WORK_TREE
=. git remote
-v |
grep '(fetch)' |
sed -e s
,^
," ", -e s
,' (fetch)',, >&2
407 echo >&2 "$(eval_gettext "If you want to reuse this
local git directory instead of cloning again from
")"
408 echo >&2 " $realrepo"
409 echo >&2 "$(eval_gettext "use the
'--force' option. If the
local git directory is not the correct repo
")"
410 die
"$(eval_gettext "or you are unsure what this means choose another name with the
'--name' option.
")"
412 echo "$(eval_gettext "Reactivating
local git directory
for submodule
'\$sm_name'.
")"
415 module_clone
"$sm_path" "$sm_name" "$realrepo" "$reference" "$depth" ||
exit
419 # ash fails to wordsplit ${branch:+-b "$branch"...}
421 '') git checkout
-f -q ;;
422 ?
*) git checkout
-f -q -B "$branch" "origin/$branch" ;;
424 ) || die
"$(eval_gettext "Unable to checkout submodule
'\$sm_path'")"
426 git config submodule.
"$sm_name".url
"$realrepo"
428 git add
$force "$sm_path" ||
429 die
"$(eval_gettext "Failed to add submodule
'\$sm_path'")"
431 git config
-f .gitmodules submodule.
"$sm_name".path
"$sm_path" &&
432 git config
-f .gitmodules submodule.
"$sm_name".url
"$repo" &&
435 git config
-f .gitmodules submodule.
"$sm_name".branch
"$branch"
437 git add
--force .gitmodules ||
438 die
"$(eval_gettext "Failed to register submodule
'\$sm_path'")"
442 # Execute an arbitrary command sequence in each checked out
445 # $@ = command to execute
449 # parse $args after "submodule ... foreach".
471 # dup stdin so that it can be restored when running the external
472 # command in the subshell (and a recursive call to this function)
475 git submodule--helper list
--prefix "$wt_prefix"|
476 while read mode sha1 stage sm_path
478 die_if_unmatched
"$mode"
479 if test -e "$sm_path"/.git
481 displaypath
=$
(relative_path
"$sm_path")
482 say
"$(eval_gettext "Entering
'\$prefix\$displaypath'")"
483 name
=$
(git submodule--helper name
"$sm_path")
485 prefix
="$prefix$sm_path/"
488 sm_path
=$
(relative_path
"$sm_path") &&
489 # we make $path available to scripts ...
497 if test -n "$recursive"
499 cmd_foreach
"--recursive" "$@"
502 die
"$(eval_gettext "Stopping
at '\$prefix\$displaypath'; script returned non-zero status.
")"
508 # Register submodules in .git/config
510 # $@ = requested paths (default to all)
514 # parse $args after "submodule ... init".
535 git submodule--helper list
--prefix "$wt_prefix" "$@" |
536 while read mode sha1 stage sm_path
538 die_if_unmatched
"$mode"
539 name
=$
(git submodule--helper name
"$sm_path") ||
exit
541 displaypath
=$
(relative_path
"$sm_path")
543 # Copy url setting when it is not set yet
544 if test -z "$(git config "submodule.
$name.url
")"
546 url
=$
(git config
-f .gitmodules submodule.
"$name".url
)
548 die
"$(eval_gettext "No url found
for submodule path
'\$displaypath' in .gitmodules
")"
550 # Possibly a url relative to parent
553 url
=$
(resolve_relative_url
"$url") ||
exit
556 git config submodule.
"$name".url
"$url" ||
557 die
"$(eval_gettext "Failed to register url
for submodule path
'\$displaypath'")"
559 say
"$(eval_gettext "Submodule
'\$name' (\
$url) registered
for path
'\$displaypath'")"
562 # Copy "update" setting when it is not set yet
563 if upd
="$(git config -f .gitmodules submodule."$name".update)" &&
565 test -z "$(git config submodule."$name".update)"
568 checkout | rebase | merge | none
)
569 ;; # known modes of updating
571 echo >&2 "warning: unknown update mode '$upd' suggested for submodule '$name'"
575 git config submodule.
"$name".update
"$upd" ||
576 die
"$(eval_gettext "Failed to register update mode
for submodule path
'\$displaypath'")"
582 # Unregister submodules from .git/config and remove their work tree
584 # $@ = requested paths (use '.' to deinit all submodules)
588 # parse $args after "submodule ... deinit".
614 die
"$(eval_gettext "Use
'.' if you really want to deinitialize all submodules
")"
617 git submodule--helper list
--prefix "$wt_prefix" "$@" |
618 while read mode sha1 stage sm_path
620 die_if_unmatched
"$mode"
621 name
=$
(git submodule--helper name
"$sm_path") ||
exit
623 displaypath
=$
(relative_path
"$sm_path")
625 # Remove the submodule work tree (unless the user already did it)
626 if test -d "$sm_path"
628 # Protect submodules containing a .git directory
629 if test -d "$sm_path/.git"
631 echo >&2 "$(eval_gettext "Submodule work tree
'\$displaypath' contains a .git directory
")"
632 die
"$(eval_gettext "(use
'rm -rf' if you really want to remove it including all of its
history)")"
637 git
rm -qn "$sm_path" ||
638 die
"$(eval_gettext "Submodule work tree
'\$displaypath' contains
local modifications
; use
'-f' to discard them
")"
641 say
"$(eval_gettext "Cleared directory
'\$displaypath'")" ||
642 say
"$(eval_gettext "Could not remove submodule work tree
'\$displaypath'")"
645 mkdir
"$sm_path" || say
"$(eval_gettext "Could not create empty submodule directory
'\$displaypath'")"
647 # Remove the .git/config entries (unless the user already did it)
648 if test -n "$(git config --get-regexp submodule."$name\.
")"
650 # Remove the whole section so we have a clean state when
651 # the user later decides to init this submodule again
652 url
=$
(git config submodule.
"$name".url
)
653 git config
--remove-section submodule.
"$name" 2>/dev
/null
&&
654 say
"$(eval_gettext "Submodule
'\$name' (\
$url) unregistered
for path
'\$displaypath'")"
660 # Update each submodule path to correct revision, using clone and checkout as needed
662 # $@ = requested paths (default to all)
666 # parse $args after "submodule ... update".
689 case "$2" in '') usage
;; esac
690 reference
="--reference=$2"
706 case "$2" in '') usage
;; esac
729 cmd_init
"--" "$@" ||
return
733 git submodule--helper list
--prefix "$wt_prefix" "$@" |
{
735 while read mode sha1 stage sm_path
737 die_if_unmatched
"$mode"
740 echo >&2 "Skipping unmerged submodule $prefix$sm_path"
743 name
=$
(git submodule--helper name
"$sm_path") ||
exit
744 url
=$
(git config submodule.
"$name".url
)
745 branch
=$
(get_submodule_config
"$name" branch master
)
746 if ! test -z "$update"
748 update_module
=$update
750 update_module
=$
(git config submodule.
"$name".update
)
751 if test -z "$update_module"
753 update_module
="checkout"
757 displaypath
=$
(relative_path
"$prefix$sm_path")
759 if test "$update_module" = "none"
761 echo "Skipping submodule '$displaypath'"
767 # Only mention uninitialized submodules when its
768 # path have been specified
770 say
"$(eval_gettext "Submodule path
'\$displaypath' not initialized
771 Maybe you want to use
'update --init'?
")"
775 if ! test -d "$sm_path"/.git
&& ! test -f "$sm_path"/.git
777 module_clone
"$sm_path" "$name" "$url" "$reference" "$depth" ||
exit
778 cloned_modules
="$cloned_modules;$name"
781 subsha1
=$
(clear_local_git_env
; cd "$sm_path" &&
782 git rev-parse
--verify HEAD
) ||
783 die
"$(eval_gettext "Unable to
find current revision
in submodule path
'\$displaypath'")"
788 if test -z "$nofetch"
790 # Fetch remote before determining tracking $sha1
791 (clear_local_git_env
; cd "$sm_path" && git-fetch
) ||
792 die
"$(eval_gettext "Unable to fetch
in submodule path
'\$sm_path'")"
794 remote_name
=$
(clear_local_git_env
; cd "$sm_path" && get_default_remote
)
795 sha1
=$
(clear_local_git_env
; cd "$sm_path" &&
796 git rev-parse
--verify "${remote_name}/${branch}") ||
797 die
"$(eval_gettext "Unable to
find current
${remote_name}/${branch} revision
in submodule path
'\$sm_path'")"
800 if test "$subsha1" != "$sha1" ||
test -n "$force"
803 # If we don't already have a -f flag and the submodule has never been checked out
804 if test -z "$subsha1" && test -z "$force"
809 if test -z "$nofetch"
811 # Run fetch only if $sha1 isn't present or it
812 # is not reachable from a ref.
813 (clear_local_git_env
; cd "$sm_path" &&
814 ( (rev=$
(git rev-list
-n 1 $sha1 --not --all 2>/dev
/null
) &&
815 test -z "$rev") || git-fetch
)) ||
816 die
"$(eval_gettext "Unable to fetch
in submodule path
'\$displaypath'")"
819 # Is this something we just cloned?
820 case ";$cloned_modules;" in
822 # then there is no local change to integrate
823 update_module
=checkout
;;
827 case "$update_module" in
829 command="git checkout $subforce -q"
830 die_msg
="$(eval_gettext "Unable to checkout
'\$sha1' in submodule path
'\$displaypath'")"
831 say_msg
="$(eval_gettext "Submodule path
'\$displaypath': checked out
'\$sha1'")"
835 die_msg
="$(eval_gettext "Unable to rebase
'\$sha1' in submodule path
'\$displaypath'")"
836 say_msg
="$(eval_gettext "Submodule path
'\$displaypath': rebased into
'\$sha1'")"
837 must_die_on_failure
=yes
841 die_msg
="$(eval_gettext "Unable to merge
'\$sha1' in submodule path
'\$displaypath'")"
842 say_msg
="$(eval_gettext "Submodule path
'\$displaypath': merged
in '\$sha1'")"
843 must_die_on_failure
=yes
846 command="${update_module#!}"
847 die_msg
="$(eval_gettext "Execution of
'\$command \$sha1' failed
in submodule path
'\$prefix\$sm_path'")"
848 say_msg
="$(eval_gettext "Submodule path
'\$prefix\$sm_path': '\$command \$sha1'")"
849 must_die_on_failure
=yes
852 die
"$(eval_gettext "Invalid update mode
'$update_module' for submodule
'$name'")"
855 if (clear_local_git_env
; cd "$sm_path" && $command "$sha1")
858 elif test -n "$must_die_on_failure"
860 die_with_status
2 "$die_msg"
862 err
="${err};$die_msg"
867 if test -n "$recursive"
870 prefix
="$prefix$sm_path/"
878 die_msg
="$(eval_gettext "Failed to recurse into submodule path
'\$displaypath'")"
881 err
="${err};$die_msg"
884 die_with_status
$res "$die_msg"
911 git describe
"$2" 2>/dev
/null ||
912 git describe
--tags "$2" 2>/dev
/null ||
913 git describe
--contains "$2" 2>/dev
/null ||
914 git describe
--all --always "$2"
917 test -z "$revname" || revname
=" ($revname)"
920 # Show commit summary for submodules in index or working tree
922 # If '--cached' is given, show summary between index and given commit,
923 # or between working tree and given commit
925 # $@ = [commit (default 'HEAD'),] requested paths (default all)
932 # parse $args after "submodule ... summary".
947 isnumber
"$summary_limit" || usage
951 summary_limit
="${1#--summary-limit=}"
952 isnumber
"$summary_limit" || usage
968 test $summary_limit = 0 && return
970 if rev=$
(git rev-parse
-q --verify --default HEAD
${1+"$1"})
974 elif test -z "$1" ||
test "$1" = "HEAD"
976 # before the first commit: compare with an empty tree
977 head=$
(git hash-object
-w -t tree
--stdin </dev
/null
)
978 test -z "$1" ||
shift
986 die
"$(gettext "The
--cached option cannot be used with the
--files option
")"
992 eval "set $(git rev-parse --sq --prefix "$wt_prefix" -- "$@
")"
993 # Get modified modules cared by user
994 modules
=$
(git
$diff_cmd $cached --ignore-submodules=dirty
--raw $head -- "$@" |
995 sane_egrep
'^:([0-7]* )?160000' |
996 while read mod_src mod_dst sha1_src sha1_dst status sm_path
998 # Always show modules deleted or type-changed (blob<->module)
999 if test "$status" = D ||
test "$status" = T
1001 printf '%s\n' "$sm_path"
1004 # Respect the ignore setting for --for-status.
1005 if test -n "$for_status"
1007 name
=$
(git submodule--helper name
"$sm_path")
1008 ignore_config
=$
(get_submodule_config
"$name" ignore none
)
1009 test $status != A
&& test $ignore_config = all
&& continue
1011 # Also show added or modified modules which are checked out
1012 GIT_DIR
="$sm_path/.git" git-rev-parse
--git-dir >/dev
/null
2>&1 &&
1013 printf '%s\n' "$sm_path"
1017 test -z "$modules" && return
1019 git
$diff_cmd $cached --ignore-submodules=dirty
--raw $head -- $modules |
1020 sane_egrep
'^:([0-7]* )?160000' |
1022 while read mod_src mod_dst sha1_src sha1_dst status name
1024 if test -z "$cached" &&
1025 test $sha1_dst = 0000000000000000000000000000000000000000
1029 sha1_dst
=$
(GIT_DIR
="$name/.git" git rev-parse HEAD
)
1031 100644 |
100755 |
120000)
1032 sha1_dst
=$
(git hash-object
$name)
1038 eval_gettextln
"unexpected mode \$mod_dst" >&2
1045 test $mod_src = 160000 &&
1046 ! GIT_DIR
="$name/.git" git-rev-parse
-q --verify $sha1_src^
0 >/dev
/null
&&
1049 test $mod_dst = 160000 &&
1050 ! GIT_DIR
="$name/.git" git-rev-parse
-q --verify $sha1_dst^
0 >/dev
/null
&&
1053 display_name
=$
(relative_path
"$name")
1056 case "$missing_src,$missing_dst" in
1058 errmsg
="$(eval_gettext " Warn
: \
$display_name doesn
't contain commit \$sha1_src")"
1061 errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commit \
$sha1_dst")"
1064 errmsg
="$(eval_gettext " Warn
: \
$display_name doesn
't contain commits \$sha1_src and \$sha1_dst")"
1069 if test $mod_src = 160000 && test $mod_dst = 160000
1071 range="$sha1_src...$sha1_dst"
1072 elif test $mod_src = 160000
1078 GIT_DIR="$name/.git" \
1079 git rev-list --first-parent $range -- | wc -l
1081 total_commits=" ($(($total_commits + 0)))"
1085 sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
1086 sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
1089 blob="$(gettext "blob")"
1090 submodule="$(gettext "submodule")"
1091 if test $mod_dst = 160000
1093 echo "* $display_name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:"
1095 echo "* $display_name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:"
1098 echo "* $display_name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
1100 if test -n "$errmsg"
1102 # Don't give error msg
for modification whose dst is not submodule
1103 # i.e. deleted or changed to blob
1104 test $mod_dst = 160000 && echo "$errmsg"
1106 if test $mod_src = 160000 && test $mod_dst = 160000
1109 test $summary_limit -gt 0 && limit
="-$summary_limit"
1110 GIT_DIR
="$name/.git" \
1111 git log
$limit --pretty='format: %m %s' \
1112 --first-parent $sha1_src...
$sha1_dst
1113 elif test $mod_dst = 160000
1115 GIT_DIR
="$name/.git" \
1116 git log
--pretty='format: > %s' -1 $sha1_dst
1118 GIT_DIR
="$name/.git" \
1119 git log
--pretty='format: < %s' -1 $sha1_src
1127 # List all submodules, prefixed with:
1128 # - submodule not initialized
1129 # + different revision checked out
1131 # If --cached was specified the revision in the index will be printed
1132 # instead of the currently checked out revision.
1134 # $@ = requested paths (default to all)
1138 # parse $args after "submodule ... status".
1165 git submodule--helper list
--prefix "$wt_prefix" "$@" |
1166 while read mode sha1 stage sm_path
1168 die_if_unmatched
"$mode"
1169 name
=$
(git submodule--helper name
"$sm_path") ||
exit
1170 url
=$
(git config submodule.
"$name".url
)
1171 displaypath
=$
(relative_path
"$prefix$sm_path")
1172 if test "$stage" = U
1174 say
"U$sha1 $displaypath"
1177 if test -z "$url" ||
1179 ! test -d "$sm_path"/.git
&&
1180 ! test -f "$sm_path"/.git
1183 say
"-$sha1 $displaypath"
1186 if git diff-files
--ignore-submodules=dirty
--quiet -- "$sm_path"
1188 set_name_rev
"$sm_path" "$sha1"
1189 say
" $sha1 $displaypath$revname"
1191 if test -z "$cached"
1193 sha1
=$
(clear_local_git_env
; cd "$sm_path" && git rev-parse
--verify HEAD
)
1195 set_name_rev
"$sm_path" "$sha1"
1196 say
"+$sha1 $displaypath$revname"
1199 if test -n "$recursive"
1202 prefix
="$displaypath/"
1207 die
"$(eval_gettext "Failed to recurse into submodule path
'\$sm_path'")"
1212 # Sync remote urls for submodules
1213 # This makes the value for remote.$remote.url match the value
1214 # specified in .gitmodules.
1242 git submodule--helper list
--prefix "$wt_prefix" "$@" |
1243 while read mode sha1 stage sm_path
1245 die_if_unmatched
"$mode"
1246 name
=$
(git submodule--helper name
"$sm_path")
1247 url
=$
(git config
-f .gitmodules
--get submodule.
"$name".url
)
1249 # Possibly a url relative to parent
1252 # rewrite foo/bar as ../.. to find path from
1253 # submodule work tree to superproject work tree
1254 up_path
="$(printf '%s\n' "$sm_path" | sed "s
/[^
/][^
/]*/..
/g
")" &&
1255 # guarantee a trailing /
1256 up_path
=${up_path%/}/ &&
1257 # path from submodule work tree to submodule origin repo
1258 sub_origin_url
=$
(resolve_relative_url
"$url" "$up_path") &&
1259 # path from superproject work tree to submodule origin repo
1260 super_config_url
=$
(resolve_relative_url
"$url") ||
exit
1263 sub_origin_url
="$url"
1264 super_config_url
="$url"
1268 if git config
"submodule.$name.url" >/dev
/null
2>/dev
/null
1270 displaypath
=$
(relative_path
"$prefix$sm_path")
1271 say
"$(eval_gettext "Synchronizing submodule url
for '\$displaypath'")"
1272 git config submodule.
"$name".url
"$super_config_url"
1274 if test -e "$sm_path"/.git
1279 remote
=$
(get_default_remote
)
1280 git config remote.
"$remote".url
"$sub_origin_url"
1282 if test -n "$recursive"
1284 prefix
="$prefix$sm_path/"
1293 # This loop parses the command line arguments to find the
1294 # subcommand name to dispatch. Parsing of the subcommand specific
1295 # options are primarily done by the subcommand implementations.
1296 # Subcommand specific options such as --branch and --cached are
1297 # parsed here as well, for backward compatibility.
1299 while test $# != 0 && test -z "$command"
1302 add | foreach | init | deinit | update | status | summary | sync
)
1332 # No command word defaults to "status"
1333 if test -z "$command"
1343 # "-b branch" is accepted only by "add"
1344 if test -n "$branch" && test "$command" != add
1349 # "--cached" is accepted only by "status" and "summary"
1350 if test -n "$cached" && test "$command" != status
&& test "$command" != summary