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>...]"
22 wt_prefix
=$
(git rev-parse
--show-prefix)
39 # The function takes at most 2 arguments. The first argument is the
40 # URL that navigates to the submodule origin repo. When relative, this URL
41 # is relative to the superproject origin URL repo. The second up_path
42 # argument, if specified, is the relative path that navigates
43 # from the submodule working tree to the superproject working tree.
45 # The output of the function is the origin URL of the submodule.
47 # The output will either be an absolute URL or filesystem path (if the
48 # superproject origin URL is an absolute URL or filesystem path,
49 # respectively) or a relative file system path (if the superproject
50 # origin URL is a relative file system path).
52 # When the output is a relative file system path, the path is either
53 # relative to the submodule working tree, if up_path is specified, or to
54 # the superproject working tree otherwise.
55 resolve_relative_url
()
57 remote
=$
(get_default_remote
)
58 remoteurl
=$
(git config
"remote.$remote.url") ||
59 remoteurl
=$
(pwd) # the repository is its own authoritative upstream
61 remoteurl
=${remoteurl%/}
74 remoteurl
="./$remoteurl"
85 remoteurl
="${remoteurl%/*}"
88 remoteurl
="${remoteurl%:*}"
92 if test -z "$is_relative" ||
test "." = "$remoteurl"
94 die
"$(eval_gettext "cannot strip one component off url
'\$remoteurl'")"
108 remoteurl
="$remoteurl$sep${url%/}"
109 echo "${is_relative:+${up_path}}${remoteurl#./}"
112 # Resolve a path to be relative to another path. This is intended for
113 # converting submodule paths when git-submodule is run in a subdirectory
114 # and only handles paths where the directory separator is '/'.
116 # The output is the first argument as a path relative to the second argument,
117 # which defaults to $wt_prefix if it is omitted.
120 local target curdir result
122 curdir
=${2-$wt_prefix}
126 while test -n "$curdir"
130 target
=${target#"$curdir"/}
135 result
="${result}../"
136 if test "$curdir" = "${curdir%/*}"
140 curdir
="${curdir%/*}"
144 echo "$result$target"
148 # Get submodule info for registered submodules
149 # $@ = path to limit submodule list
153 eval "set $(git rev-parse --sq --prefix "$wt_prefix" -- "$@
")"
155 git ls-files
-z --error-unmatch --stage -- "$@" ||
156 echo "unmatched pathspec exists"
160 my ($null_sha1) = ("0" x 40);
165 if (/^unmatched pathspec/) {
170 my ($mode, $sha1, $stage, $path) =
171 /^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
172 next unless $mode eq "160000";
174 if (!$unmerged{$path}++) {
175 push @out, "$mode $null_sha1 U\t$path\n";
182 print "#unmatched\n";
191 if test "$1" = "#unmatched"
198 # Print a submodule configuration setting
200 # $1 = submodule name
204 # Checks in the usual git-config places first (for overrides),
205 # otherwise it falls back on .gitmodules. This allows you to
206 # distribute project-wide defaults in .gitmodules, while still
207 # customizing individual repositories if necessary. If the option is
208 # not in .gitmodules either, print a default value.
210 get_submodule_config
() {
214 value
=$
(git config submodule.
"$name".
"$option")
217 value
=$
(git config
-f .gitmodules submodule.
"$name".
"$option")
219 printf '%s' "${value:-$default}"
224 # Map submodule path to submodule name
230 # Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
232 re
=$
(printf '%s\n' "$1" |
sed -e 's/[].[^$\\*]/\\&/g')
233 name
=$
( git config
-f .gitmodules
--get-regexp '^submodule\..*\.path$' |
234 sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
236 die
"$(eval_gettext "No submodule mapping found
in .gitmodules
for path
'\$sm_path'")"
243 # Prior to calling, cmd_update checks that a possibly existing
244 # path is not a git repository.
245 # Likewise, cmd_add checks that path does not exist at all,
246 # since it is the location of a new submodule.
255 if test -n "$GIT_QUIET"
262 base_name
=$
(dirname "$name")
264 gitdir
=$
(git rev-parse
--git-dir)
265 gitdir_base
="$gitdir/modules/$base_name"
266 gitdir
="$gitdir/modules/$name"
271 rm -f "$gitdir/index"
273 mkdir
-p "$gitdir_base"
276 git clone
$quiet -n ${reference:+"$reference"} \
277 --separate-git-dir "$gitdir" "$url" "$sm_path"
279 die
"$(eval_gettext "Clone of
'\$url' into submodule path
'\$sm_path' failed
")"
282 # We already are at the root of the work tree but cd_to_toplevel will
283 # resolve any symlinks that might be present in $PWD
284 a
=$
(cd_to_toplevel
&& cd "$gitdir" && pwd)/
285 b
=$
(cd_to_toplevel
&& cd "$sm_path" && pwd)/
286 # normalize Windows-style absolute paths to POSIX-style absolute paths
287 case $a in [a-zA-Z
]:/*) a
=/${a%%:*}${a#*:} ;; esac
288 case $b in [a-zA-Z
]:/*) b
=/${b%%:*}${b#*:} ;; esac
289 # Remove all common leading directories after a sanity check
290 if test "${a#$b}" != "$a" ||
test "${b#$a}" != "$b"; then
291 die
"$(eval_gettext "Gitdir
'\$a' is part of the submodule path
'\$b' or vice versa
")"
293 while test "${a%%/*}" = "${b%%/*}"
298 # Now chop off the trailing '/'s that were added in the beginning
302 # Turn each leading "*/" component into "../"
303 rel
=$
(echo $b |
sed -e 's|[^/][^/]*|..|g')
304 echo "gitdir: $rel/$a" >"$sm_path/.git"
306 rel
=$
(echo $a |
sed -e 's|[^/][^/]*|..|g')
307 (clear_local_git_env
; cd "$sm_path" && GIT_WORK_TREE
=. git config core.worktree
"$rel/$b")
312 n
=$
(($1 + 0)) 2>/dev
/null
&& test "$n" = "$1"
316 # Add a new submodule to the working tree, .gitmodules and the index
320 # optional branch is stored in global branch variable
324 # parse $args after "submodule ... add".
330 case "$2" in '') usage
;; esac
341 case "$2" in '') usage
;; esac
346 reference_path
="${1#--reference=}"
349 case "$2" in '') usage
;; esac
367 if test -n "$reference_path"
369 is_absolute_path
"$reference_path" ||
370 reference_path
="$wt_prefix$reference_path"
372 reference
="--reference=$reference_path"
378 if test -z "$sm_path"; then
379 sm_path
=$
(echo "$repo" |
380 sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
383 if test -z "$repo" -o -z "$sm_path"; then
387 is_absolute_path
"$sm_path" || sm_path
="$wt_prefix$sm_path"
389 # assure repo is absolute or relative to parent
392 test -z "$wt_prefix" ||
393 die
"$(gettext "Relative path can only be used from the toplevel of the working tree
")"
395 # dereference source url relative to parent's url
396 realrepo
=$
(resolve_relative_url
"$repo") ||
exit
403 die
"$(eval_gettext "repo URL
: '\$repo' must be absolute or begin with .
/|..
/")"
408 # multiple //; leading ./; /./; /../; trailing /
409 sm_path
=$
(printf '%s/\n' "$sm_path" |
419 git ls-files
--error-unmatch "$sm_path" > /dev
/null
2>&1 &&
420 die
"$(eval_gettext "'\$sm_path' already exists
in the index
")"
422 if test -z "$force" && ! git add
--dry-run --ignore-missing "$sm_path" > /dev
/null
2>&1
424 eval_gettextln
"The following path is ignored by one of your .gitignore files:
426 Use -f if you really want to add it." >&2
430 if test -n "$custom_name"
432 sm_name
="$custom_name"
437 # perhaps the path exists and is already a git repo, else clone it
438 if test -e "$sm_path"
440 if test -d "$sm_path"/.git
-o -f "$sm_path"/.git
442 eval_gettextln
"Adding existing repo at '\$sm_path' to the index"
444 die
"$(eval_gettext "'\$sm_path' already exists and is not a valid git repo
")"
448 if test -d ".git/modules/$sm_name"
452 echo >&2 "$(eval_gettext "A git directory
for '\$sm_name' is found locally with remote
(s
):")"
453 GIT_DIR
=".git/modules/$sm_name" GIT_WORK_TREE
=. git remote
-v |
grep '(fetch)' |
sed -e s
,^
," ", -e s
,' (fetch)',, >&2
454 echo >&2 "$(eval_gettext "If you want to reuse this
local git directory instead of cloning again from
")"
455 echo >&2 " $realrepo"
456 echo >&2 "$(eval_gettext "use the
'--force' option. If the
local git directory is not the correct repo
")"
457 die
"$(eval_gettext "or you are unsure what this means choose another name with the
'--name' option.
")"
459 echo "$(eval_gettext "Reactivating
local git directory
for submodule
'\$sm_name'.
")"
462 module_clone
"$sm_path" "$sm_name" "$realrepo" "$reference" ||
exit
466 # ash fails to wordsplit ${branch:+-b "$branch"...}
468 '') git checkout
-f -q ;;
469 ?
*) git checkout
-f -q -B "$branch" "origin/$branch" ;;
471 ) || die
"$(eval_gettext "Unable to checkout submodule
'\$sm_path'")"
473 git config submodule.
"$sm_name".url
"$realrepo"
475 git add
$force "$sm_path" ||
476 die
"$(eval_gettext "Failed to add submodule
'\$sm_path'")"
478 git config
-f .gitmodules submodule.
"$sm_name".path
"$sm_path" &&
479 git config
-f .gitmodules submodule.
"$sm_name".url
"$repo" &&
482 git config
-f .gitmodules submodule.
"$sm_name".branch
"$branch"
484 git add
--force .gitmodules ||
485 die
"$(eval_gettext "Failed to register submodule
'\$sm_path'")"
489 # Execute an arbitrary command sequence in each checked out
492 # $@ = command to execute
496 # parse $args after "submodule ... foreach".
518 # dup stdin so that it can be restored when running the external
519 # command in the subshell (and a recursive call to this function)
523 while read mode sha1 stage sm_path
525 die_if_unmatched
"$mode"
526 if test -e "$sm_path"/.git
528 displaypath
=$
(relative_path
"$sm_path")
529 say
"$(eval_gettext "Entering
'\$prefix\$displaypath'")"
530 name
=$
(module_name
"$sm_path")
532 prefix
="$prefix$sm_path/"
535 sm_path
=$
(relative_path
"$sm_path") &&
536 # we make $path available to scripts ...
539 if test -n "$recursive"
541 cmd_foreach
"--recursive" "$@"
544 die
"$(eval_gettext "Stopping
at '\$prefix\$displaypath'; script returned non-zero status.
")"
550 # Register submodules in .git/config
552 # $@ = requested paths (default to all)
556 # parse $args after "submodule ... init".
578 while read mode sha1 stage sm_path
580 die_if_unmatched
"$mode"
581 name
=$
(module_name
"$sm_path") ||
exit
583 displaypath
=$
(relative_path
"$sm_path")
585 # Copy url setting when it is not set yet
586 if test -z "$(git config "submodule.
$name.url
")"
588 url
=$
(git config
-f .gitmodules submodule.
"$name".url
)
590 die
"$(eval_gettext "No url found
for submodule path
'\$displaypath' in .gitmodules
")"
592 # Possibly a url relative to parent
595 url
=$
(resolve_relative_url
"$url") ||
exit
598 git config submodule.
"$name".url
"$url" ||
599 die
"$(eval_gettext "Failed to register url
for submodule path
'\$displaypath'")"
601 say
"$(eval_gettext "Submodule
'\$name' (\
$url) registered
for path
'\$displaypath'")"
604 # Copy "update" setting when it is not set yet
605 upd
="$(git config -f .gitmodules submodule."$name".update)"
607 test -n "$(git config submodule."$name".update)" ||
608 git config submodule.
"$name".update
"$upd" ||
609 die
"$(eval_gettext "Failed to register update mode
for submodule path
'\$displaypath'")"
614 # Unregister submodules from .git/config and remove their work tree
616 # $@ = requested paths (use '.' to deinit all submodules)
620 # parse $args after "submodule ... deinit".
646 die
"$(eval_gettext "Use
'.' if you really want to deinitialize all submodules
")"
650 while read mode sha1 stage sm_path
652 die_if_unmatched
"$mode"
653 name
=$
(module_name
"$sm_path") ||
exit
655 displaypath
=$
(relative_path
"$sm_path")
657 # Remove the submodule work tree (unless the user already did it)
658 if test -d "$sm_path"
660 # Protect submodules containing a .git directory
661 if test -d "$sm_path/.git"
663 echo >&2 "$(eval_gettext "Submodule work tree
'\$displaypath' contains a .git directory
")"
664 die
"$(eval_gettext "(use
'rm -rf' if you really want to remove it including all of its
history)")"
669 git
rm -qn "$sm_path" ||
670 die
"$(eval_gettext "Submodule work tree
'\$displaypath' contains
local modifications
; use
'-f' to discard them
")"
673 say
"$(eval_gettext "Cleared directory
'\$displaypath'")" ||
674 say
"$(eval_gettext "Could not remove submodule work tree
'\$displaypath'")"
677 mkdir
"$sm_path" || say
"$(eval_gettext "Could not create empty submodule directory
'\$displaypath'")"
679 # Remove the .git/config entries (unless the user already did it)
680 if test -n "$(git config --get-regexp submodule."$name\.
")"
682 # Remove the whole section so we have a clean state when
683 # the user later decides to init this submodule again
684 url
=$
(git config submodule.
"$name".url
)
685 git config
--remove-section submodule.
"$name" 2>/dev
/null
&&
686 say
"$(eval_gettext "Submodule
'\$name' (\
$url) unregistered
for path
'\$displaypath'")"
692 # Update each submodule path to correct revision, using clone and checkout as needed
694 # $@ = requested paths (default to all)
698 # parse $args after "submodule ... update".
722 case "$2" in '') usage
;; esac
723 reference
="--reference=$2"
724 orig_flags
="$orig_flags $(git rev-parse --sq-quote "$1")"
750 orig_flags
="$orig_flags $(git rev-parse --sq-quote "$1")"
756 cmd_init
"--" "$@" ||
return
762 while read mode sha1 stage sm_path
764 die_if_unmatched
"$mode"
767 echo >&2 "Skipping unmerged submodule $prefix$sm_path"
770 name
=$
(module_name
"$sm_path") ||
exit
771 url
=$
(git config submodule.
"$name".url
)
772 branch
=$
(get_submodule_config
"$name" branch master
)
773 if ! test -z "$update"
775 update_module
=$update
777 update_module
=$
(git config submodule.
"$name".update
)
780 displaypath
=$
(relative_path
"$prefix$sm_path")
782 if test "$update_module" = "none"
784 echo "Skipping submodule '$displaypath'"
790 # Only mention uninitialized submodules when its
791 # path have been specified
793 say
"$(eval_gettext "Submodule path
'\$displaypath' not initialized
794 Maybe you want to use
'update --init'?
")"
798 if ! test -d "$sm_path"/.git
-o -f "$sm_path"/.git
800 module_clone
"$sm_path" "$name" "$url" "$reference" ||
exit
801 cloned_modules
="$cloned_modules;$name"
804 subsha1
=$
(clear_local_git_env
; cd "$sm_path" &&
805 git rev-parse
--verify HEAD
) ||
806 die
"$(eval_gettext "Unable to
find current revision
in submodule path
'\$displaypath'")"
811 if test -z "$nofetch"
813 # Fetch remote before determining tracking $sha1
814 (clear_local_git_env
; cd "$sm_path" && git-fetch
) ||
815 die
"$(eval_gettext "Unable to fetch
in submodule path
'\$sm_path'")"
817 remote_name
=$
(clear_local_git_env
; cd "$sm_path" && get_default_remote
)
818 sha1
=$
(clear_local_git_env
; cd "$sm_path" &&
819 git rev-parse
--verify "${remote_name}/${branch}") ||
820 die
"$(eval_gettext "Unable to
find current
${remote_name}/${branch} revision
in submodule path
'\$sm_path'")"
823 if test "$subsha1" != "$sha1" -o -n "$force"
826 # If we don't already have a -f flag and the submodule has never been checked out
827 if test -z "$subsha1" -a -z "$force"
832 if test -z "$nofetch"
834 # Run fetch only if $sha1 isn't present or it
835 # is not reachable from a ref.
836 (clear_local_git_env
; cd "$sm_path" &&
837 ( (rev=$
(git rev-list
-n 1 $sha1 --not --all 2>/dev
/null
) &&
838 test -z "$rev") || git-fetch
)) ||
839 die
"$(eval_gettext "Unable to fetch
in submodule path
'\$displaypath'")"
842 # Is this something we just cloned?
843 case ";$cloned_modules;" in
845 # then there is no local change to integrate
850 case "$update_module" in
853 die_msg
="$(eval_gettext "Unable to rebase
'\$sha1' in submodule path
'\$displaypath'")"
854 say_msg
="$(eval_gettext "Submodule path
'\$displaypath': rebased into
'\$sha1'")"
855 must_die_on_failure
=yes
859 die_msg
="$(eval_gettext "Unable to merge
'\$sha1' in submodule path
'\$displaypath'")"
860 say_msg
="$(eval_gettext "Submodule path
'\$displaypath': merged
in '\$sha1'")"
861 must_die_on_failure
=yes
864 command="git checkout $subforce -q"
865 die_msg
="$(eval_gettext "Unable to checkout
'\$sha1' in submodule path
'\$displaypath'")"
866 say_msg
="$(eval_gettext "Submodule path
'\$displaypath': checked out
'\$sha1'")"
870 if (clear_local_git_env
; cd "$sm_path" && $command "$sha1")
873 elif test -n "$must_die_on_failure"
875 die_with_status
2 "$die_msg"
877 err
="${err};$die_msg"
882 if test -n "$recursive"
885 prefix
="$prefix$sm_path/"
888 eval cmd_update
"$orig_flags"
893 die_msg
="$(eval_gettext "Failed to recurse into submodule path
'\$displaypath'")"
896 err
="${err};$die_msg"
899 die_with_status
$res "$die_msg"
926 git describe
"$2" 2>/dev
/null ||
927 git describe
--tags "$2" 2>/dev
/null ||
928 git describe
--contains "$2" 2>/dev
/null ||
929 git describe
--all --always "$2"
932 test -z "$revname" || revname
=" ($revname)"
935 # Show commit summary for submodules in index or working tree
937 # If '--cached' is given, show summary between index and given commit,
938 # or between working tree and given commit
940 # $@ = [commit (default 'HEAD'),] requested paths (default all)
947 # parse $args after "submodule ... summary".
962 isnumber
"$summary_limit" || usage
966 summary_limit
="${1#--summary-limit=}"
967 isnumber
"$summary_limit" || usage
983 test $summary_limit = 0 && return
985 if rev=$
(git rev-parse
-q --verify --default HEAD
${1+"$1"})
989 elif test -z "$1" -o "$1" = "HEAD"
991 # before the first commit: compare with an empty tree
992 head=$
(git hash-object
-w -t tree
--stdin </dev
/null
)
993 test -z "$1" ||
shift
1000 test -n "$cached" &&
1001 die
"$(gettext "The
--cached option cannot be used with the
--files option
")"
1007 eval "set $(git rev-parse --sq --prefix "$wt_prefix" -- "$@
")"
1008 # Get modified modules cared by user
1009 modules
=$
(git
$diff_cmd $cached --ignore-submodules=dirty
--raw $head -- "$@" |
1010 sane_egrep
'^:([0-7]* )?160000' |
1011 while read mod_src mod_dst sha1_src sha1_dst status name
1013 # Always show modules deleted or type-changed (blob<->module)
1014 test $status = D
-o $status = T
&& echo "$name" && continue
1015 # Also show added or modified modules which are checked out
1016 GIT_DIR
="$name/.git" git-rev-parse
--git-dir >/dev
/null
2>&1 &&
1021 test -z "$modules" && return
1023 git
$diff_cmd $cached --ignore-submodules=dirty
--raw $head -- $modules |
1024 sane_egrep
'^:([0-7]* )?160000' |
1026 while read mod_src mod_dst sha1_src sha1_dst status name
1028 if test -z "$cached" &&
1029 test $sha1_dst = 0000000000000000000000000000000000000000
1033 sha1_dst
=$
(GIT_DIR
="$name/.git" git rev-parse HEAD
)
1035 100644 |
100755 |
120000)
1036 sha1_dst
=$
(git hash-object
$name)
1042 eval_gettextln
"unexpected mode \$mod_dst" >&2
1049 test $mod_src = 160000 &&
1050 ! GIT_DIR
="$name/.git" git-rev-parse
-q --verify $sha1_src^
0 >/dev
/null
&&
1053 test $mod_dst = 160000 &&
1054 ! GIT_DIR
="$name/.git" git-rev-parse
-q --verify $sha1_dst^
0 >/dev
/null
&&
1057 display_name
=$
(relative_path
"$name")
1060 case "$missing_src,$missing_dst" in
1062 errmsg
="$(eval_gettext " Warn
: \
$display_name doesn
't contain commit \$sha1_src")"
1065 errmsg="$(eval_gettext " Warn: \$display_name doesn't contain commit \
$sha1_dst")"
1068 errmsg
="$(eval_gettext " Warn
: \
$display_name doesn
't contain commits \$sha1_src and \$sha1_dst")"
1073 if test $mod_src = 160000 -a $mod_dst = 160000
1075 range="$sha1_src...$sha1_dst"
1076 elif test $mod_src = 160000
1082 GIT_DIR="$name/.git" \
1083 git rev-list --first-parent $range -- | wc -l
1085 total_commits=" ($(($total_commits + 0)))"
1089 sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
1090 sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
1093 blob="$(gettext "blob")"
1094 submodule="$(gettext "submodule")"
1095 if test $mod_dst = 160000
1097 echo "* $display_name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:"
1099 echo "* $display_name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:"
1102 echo "* $display_name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
1104 if test -n "$errmsg"
1106 # Don't give error msg
for modification whose dst is not submodule
1107 # i.e. deleted or changed to blob
1108 test $mod_dst = 160000 && echo "$errmsg"
1110 if test $mod_src = 160000 -a $mod_dst = 160000
1113 test $summary_limit -gt 0 && limit
="-$summary_limit"
1114 GIT_DIR
="$name/.git" \
1115 git log
$limit --pretty='format: %m %s' \
1116 --first-parent $sha1_src...
$sha1_dst
1117 elif test $mod_dst = 160000
1119 GIT_DIR
="$name/.git" \
1120 git log
--pretty='format: > %s' -1 $sha1_dst
1122 GIT_DIR
="$name/.git" \
1123 git log
--pretty='format: < %s' -1 $sha1_src
1129 if test -n "$for_status"; then
1130 if [ -n "$files" ]; then
1131 gettextln
"Submodules changed but not updated:" | git stripspace
-c
1133 gettextln
"Submodule changes to be committed:" | git stripspace
-c
1135 printf "\n" | git stripspace
-c
1142 # List all submodules, prefixed with:
1143 # - submodule not initialized
1144 # + different revision checked out
1146 # If --cached was specified the revision in the index will be printed
1147 # instead of the currently checked out revision.
1149 # $@ = requested paths (default to all)
1153 # parse $args after "submodule ... status".
1181 while read mode sha1 stage sm_path
1183 die_if_unmatched
"$mode"
1184 name
=$
(module_name
"$sm_path") ||
exit
1185 url
=$
(git config submodule.
"$name".url
)
1186 displaypath
=$
(relative_path
"$prefix$sm_path")
1187 if test "$stage" = U
1189 say
"U$sha1 $displaypath"
1192 if test -z "$url" ||
! test -d "$sm_path"/.git
-o -f "$sm_path"/.git
1194 say
"-$sha1 $displaypath"
1197 if git diff-files
--ignore-submodules=dirty
--quiet -- "$sm_path"
1199 set_name_rev
"$sm_path" "$sha1"
1200 say
" $sha1 $displaypath$revname"
1202 if test -z "$cached"
1204 sha1
=$
(clear_local_git_env
; cd "$sm_path" && git rev-parse
--verify HEAD
)
1206 set_name_rev
"$sm_path" "$sha1"
1207 say
"+$sha1 $displaypath$revname"
1210 if test -n "$recursive"
1213 prefix
="$displaypath/"
1218 die
"$(eval_gettext "Failed to recurse into submodule path
'\$sm_path'")"
1223 # Sync remote urls for submodules
1224 # This makes the value for remote.$remote.url match the value
1225 # specified in .gitmodules.
1254 while read mode sha1 stage sm_path
1256 die_if_unmatched
"$mode"
1257 name
=$
(module_name
"$sm_path")
1258 url
=$
(git config
-f .gitmodules
--get submodule.
"$name".url
)
1260 # Possibly a url relative to parent
1263 # rewrite foo/bar as ../.. to find path from
1264 # submodule work tree to superproject work tree
1265 up_path
="$(echo "$sm_path" | sed "s
/[^
/][^
/]*/..
/g
")" &&
1266 # guarantee a trailing /
1267 up_path
=${up_path%/}/ &&
1268 # path from submodule work tree to submodule origin repo
1269 sub_origin_url
=$
(resolve_relative_url
"$url" "$up_path") &&
1270 # path from superproject work tree to submodule origin repo
1271 super_config_url
=$
(resolve_relative_url
"$url") ||
exit
1274 sub_origin_url
="$url"
1275 super_config_url
="$url"
1279 if git config
"submodule.$name.url" >/dev
/null
2>/dev
/null
1281 displaypath
=$
(relative_path
"$prefix$sm_path")
1282 say
"$(eval_gettext "Synchronizing submodule url
for '\$displaypath'")"
1283 git config submodule.
"$name".url
"$super_config_url"
1285 if test -e "$sm_path"/.git
1290 remote
=$
(get_default_remote
)
1291 git config remote.
"$remote".url
"$sub_origin_url"
1293 if test -n "$recursive"
1295 prefix
="$prefix$sm_path/"
1304 # This loop parses the command line arguments to find the
1305 # subcommand name to dispatch. Parsing of the subcommand specific
1306 # options are primarily done by the subcommand implementations.
1307 # Subcommand specific options such as --branch and --cached are
1308 # parsed here as well, for backward compatibility.
1310 while test $# != 0 && test -z "$command"
1313 add | foreach | init | deinit | update | status | summary | sync
)
1343 # No command word defaults to "status"
1344 if test -z "$command"
1354 # "-b branch" is accepted only by "add"
1355 if test -n "$branch" && test "$command" != add
1360 # "--cached" is accepted only by "status" and "summary"
1361 if test -n "$cached" && test "$command" != status
-a "$command" != summary