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>...]"
36 # The function takes at most 2 arguments. The first argument is the
37 # URL that navigates to the submodule origin repo. When relative, this URL
38 # is relative to the superproject origin URL repo. The second up_path
39 # argument, if specified, is the relative path that navigates
40 # from the submodule working tree to the superproject working tree.
42 # The output of the function is the origin URL of the submodule.
44 # The output will either be an absolute URL or filesystem path (if the
45 # superproject origin URL is an absolute URL or filesystem path,
46 # respectively) or a relative file system path (if the superproject
47 # origin URL is a relative file system path).
49 # When the output is a relative file system path, the path is either
50 # relative to the submodule working tree, if up_path is specified, or to
51 # the superproject working tree otherwise.
52 resolve_relative_url ()
54 remote=$(get_default_remote)
55 remoteurl=$(git config "remote.$remote.url") ||
56 remoteurl=$(pwd) # the repository is its own authoritative upstream
58 remoteurl=${remoteurl%/}
71 remoteurl="./$remoteurl"
82 remoteurl="${remoteurl%/*}"
85 remoteurl="${remoteurl%:*}"
89 if test -z "$is_relative" || test "." = "$remoteurl"
91 die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
105 remoteurl="$remoteurl$sep${url%/}"
106 echo "${is_relative:+${up_path}}${remoteurl#./}"
110 # Get submodule info for registered submodules
111 # $@ = path to limit submodule list
116 git ls-files --error-unmatch --stage -- "$@" ||
117 echo "unmatched pathspec exists"
121 my ($null_sha1) = ("0" x 40);
125 if (/^unmatched pathspec/) {
130 my ($mode, $sha1, $stage, $path) =
131 /^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
132 next unless $mode eq "160000";
134 if (!$unmerged{$path}++) {
135 push @out, "$mode $null_sha1 U\t$path\n";
142 print "#unmatched\n";
151 if test "$1" = "#unmatched"
158 # Print a submodule configuration setting
160 # $1 = submodule name
164 # Checks in the usual git-config places first (for overrides),
165 # otherwise it falls back on .gitmodules. This allows you to
166 # distribute project-wide defaults in .gitmodules, while still
167 # customizing individual repositories if necessary. If the option is
168 # not in .gitmodules either, print a default value.
170 get_submodule_config () {
174 value=$(git config submodule."$name"."$option")
177 value=$(git config -f .gitmodules submodule."$name"."$option")
179 printf '%s' "${value:-$default}"
184 # Map submodule path to submodule name
190 # Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
192 re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
193 name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
194 sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
196 die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$sm_path'")"
203 # Prior to calling, cmd_update checks that a possibly existing
204 # path is not a git repository.
205 # Likewise, cmd_add checks that path does not exist at all,
206 # since it is the location of a new submodule.
215 if test -n "$GIT_QUIET"
222 base_name=$(dirname "$name")
224 gitdir=$(git rev-parse --git-dir)
225 gitdir_base="$gitdir/modules/$base_name"
226 gitdir="$gitdir/modules/$name"
231 rm -f "$gitdir/index"
233 mkdir -p "$gitdir_base"
236 git clone $quiet -n ${reference:+"$reference"} \
237 --separate-git-dir "$gitdir" "$url" "$sm_path"
239 die "$(eval_gettext "Clone of '\$url' into submodule path '\$sm_path' failed")"
242 # We already are at the root of the work tree but cd_to_toplevel will
243 # resolve any symlinks that might be present in $PWD
244 a=$(cd_to_toplevel && cd "$gitdir" && pwd)/
245 b=$(cd_to_toplevel && cd "$sm_path" && pwd)/
246 # normalize Windows-style absolute paths to POSIX-style absolute paths
247 case $a in [a-zA-Z]:/*) a=/${a%%:*}${a#*:} ;; esac
248 case $b in [a-zA-Z]:/*) b=/${b%%:*}${b#*:} ;; esac
249 # Remove all common leading directories after a sanity check
250 if test "${a#$b}" != "$a" || test "${b#$a}" != "$b"; then
251 die "$(eval_gettext "Gitdir '\$a' is part of the submodule path '\$b' or vice versa")"
253 while test "${a%%/*}" = "${b%%/*}"
258 # Now chop off the trailing '/'s that were added in the beginning
262 # Turn each leading "*/" component into "../"
263 rel=$(echo $b | sed -e 's|[^/][^/]*|..|g')
264 echo "gitdir: $rel/$a" >"$sm_path/.git"
266 rel=$(echo $a | sed -e 's|[^/][^/]*|..|g')
267 (clear_local_git_env; cd "$sm_path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b")
271 # Add a new submodule to the working tree, .gitmodules and the index
275 # optional branch is stored in global branch variable
279 # parse $args after "submodule ... add".
284 case "$2" in '') usage ;; esac
295 case "$2" in '') usage ;; esac
296 reference="--reference=$2"
303 case "$2" in '') usage ;; esac
324 if test -z "$sm_path"; then
325 sm_path=$(echo "$repo" |
326 sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
329 if test -z "$repo" -o -z "$sm_path"; then
333 # assure repo is absolute or relative to parent
336 # dereference source url relative to parent's url
337 realrepo=$(resolve_relative_url "$repo") || exit
344 die "$(eval_gettext "repo URL: '\$repo' must be absolute or begin with ./|../")"
349 # multiple //; leading ./; /./; /../; trailing /
350 sm_path=$(printf '%s/\n' "$sm_path" |
360 git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
361 die "$(eval_gettext "'\$sm_path' already exists in the index")"
363 if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1
365 eval_gettextln "The following path is ignored by one of your .gitignore files:
367 Use -f if you really want to add it." >&2
371 if test -n "$custom_name"
373 sm_name="$custom_name"
378 # perhaps the path exists and is already a git repo, else clone it
379 if test -e "$sm_path"
381 if test -d "$sm_path"/.git -o -f "$sm_path"/.git
383 eval_gettextln "Adding existing repo at '\$sm_path' to the index"
385 die "$(eval_gettext "'\$sm_path' already exists and is not a valid git repo")"
389 if test -d ".git/modules/$sm_name"
393 echo >&2 "$(eval_gettext "A git directory for '\$sm_name' is found locally with remote(s):")"
394 GIT_DIR=".git/modules/$sm_name" GIT_WORK_TREE=. git remote -v | grep '(fetch)' | sed -e s,^," ", -e s,' (fetch)',, >&2
395 echo >&2 "$(eval_gettext "If you want to reuse this local git directory instead of cloning again from")"
396 echo >&2 " $realrepo"
397 echo >&2 "$(eval_gettext "use the '--force' option. If the local git directory is not the correct repo")"
398 die "$(eval_gettext "or you are unsure what this means choose another name with the '--name' option.")"
400 echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")"
403 module_clone "$sm_path" "$sm_name" "$realrepo" "$reference" || exit
407 # ash fails to wordsplit ${branch:+-b "$branch"...}
409 '') git checkout -f -q ;;
410 ?*) git checkout -f -q -B "$branch" "origin/$branch" ;;
412 ) || die "$(eval_gettext "Unable to checkout submodule '\$sm_path'")"
414 git config submodule."$sm_name".url "$realrepo"
416 git add $force "$sm_path" ||
417 die "$(eval_gettext "Failed to add submodule '\$sm_path'")"
419 git config -f .gitmodules submodule."$sm_name".path "$sm_path" &&
420 git config -f .gitmodules submodule."$sm_name".url "$repo" &&
423 git config -f .gitmodules submodule."$sm_name".branch "$branch"
425 git add --force .gitmodules ||
426 die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
430 # Execute an arbitrary command sequence in each checked out
433 # $@ = command to execute
437 # parse $args after "submodule ... foreach".
459 # dup stdin so that it can be restored when running the external
460 # command in the subshell (and a recursive call to this function)
464 while read mode sha1 stage sm_path
466 die_if_unmatched "$mode"
467 if test -e "$sm_path"/.git
469 say "$(eval_gettext "Entering '\$prefix\$sm_path'")"
470 name=$(module_name "$sm_path")
472 prefix="$prefix$sm_path/"
474 # we make $path available to scripts ...
478 if test -n "$recursive"
480 cmd_foreach "--recursive" "$@"
483 die "$(eval_gettext "Stopping at '\$sm_path'; script returned non-zero status.")"
489 # Register submodules in .git/config
491 # $@ = requested paths (default to all)
495 # parse $args after "submodule ... init".
517 while read mode sha1 stage sm_path
519 die_if_unmatched "$mode"
520 name=$(module_name "$sm_path") || exit
522 # Copy url setting when it is not set yet
523 if test -z "$(git config "submodule.$name.url")"
525 url=$(git config -f .gitmodules submodule."$name".url)
527 die "$(eval_gettext "No url found for submodule path '\$sm_path' in .gitmodules")"
529 # Possibly a url relative to parent
532 url=$(resolve_relative_url "$url") || exit
535 git config submodule."$name".url "$url" ||
536 die "$(eval_gettext "Failed to register url for submodule path '\$sm_path'")"
538 say "$(eval_gettext "Submodule '\$name' (\$url) registered for path '\$sm_path'")"
541 # Copy "update" setting when it is not set yet
542 upd="$(git config -f .gitmodules submodule."$name".update)"
544 test -n "$(git config submodule."$name".update)" ||
545 git config submodule."$name".update "$upd" ||
546 die "$(eval_gettext "Failed to register update mode for submodule path '\$sm_path'")"
551 # Unregister submodules from .git/config and remove their work tree
553 # $@ = requested paths (use '.' to deinit all submodules)
557 # parse $args after "submodule ... deinit".
583 die "$(eval_gettext "Use '.' if you really want to deinitialize all submodules")"
587 while read mode sha1 stage sm_path
589 die_if_unmatched "$mode"
590 name=$(module_name "$sm_path") || exit
592 # Remove the submodule work tree (unless the user already did it)
593 if test -d "$sm_path"
595 # Protect submodules containing a .git directory
596 if test -d "$sm_path/.git"
598 echo >&2 "$(eval_gettext "Submodule work tree '\$sm_path' contains a .git directory")"
599 die "$(eval_gettext "(use 'rm -rf' if you really want to remove it including all of its history)")"
604 git rm -n "$sm_path" ||
605 die "$(eval_gettext "Submodule work tree '\$sm_path' contains local modifications; use '-f' to discard them")"
607 rm -rf "$sm_path" || say "$(eval_gettext "Could not remove submodule work tree '\$sm_path'")"
610 mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$sm_path'")"
612 # Remove the .git/config entries (unless the user already did it)
613 if test -n "$(git config --get-regexp submodule."$name\.")"
615 # Remove the whole section so we have a clean state when
616 # the user later decides to init this submodule again
617 url=$(git config submodule."$name".url)
618 git config --remove-section submodule."$name" 2>/dev/null &&
619 say "$(eval_gettext "Submodule '\$name' (\$url) unregistered for path '\$sm_path'")"
625 # Update each submodule path to correct revision, using clone and checkout as needed
627 # $@ = requested paths (default to all)
631 # parse $args after "submodule ... update".
655 case "$2" in '') usage ;; esac
656 reference="--reference=$2"
657 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
683 orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
689 cmd_init "--" "$@" || return
695 while read mode sha1 stage sm_path
697 die_if_unmatched "$mode"
700 echo >&2 "Skipping unmerged submodule $prefix$sm_path"
703 name=$(module_name "$sm_path") || exit
704 url=$(git config submodule."$name".url)
705 branch=$(get_submodule_config "$name" branch master)
706 if ! test -z "$update"
708 update_module=$update
710 update_module=$(git config submodule."$name".update)
713 if test "$update_module" = "none"
715 echo "Skipping submodule '$prefix$sm_path'"
721 # Only mention uninitialized submodules when its
722 # path have been specified
724 say "$(eval_gettext "Submodule path '\$prefix\$sm_path' not initialized
725 Maybe you want to use 'update --init'?")"
729 if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
731 module_clone "$sm_path" "$name" "$url" "$reference" || exit
732 cloned_modules="$cloned_modules;$name"
735 subsha1=$(clear_local_git_env; cd "$sm_path" &&
736 git rev-parse --verify HEAD) ||
737 die "$(eval_gettext "Unable to find current revision in submodule path '\$prefix\$sm_path'")"
742 if test -z "$nofetch"
744 # Fetch remote before determining tracking $sha1
745 (clear_local_git_env; cd "$sm_path" && git-fetch) ||
746 die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
748 remote_name=$(clear_local_git_env; cd "$sm_path" && get_default_remote)
749 sha1=$(clear_local_git_env; cd "$sm_path" &&
750 git rev-parse --verify "${remote_name}/${branch}") ||
751 die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
754 if test "$subsha1" != "$sha1" -o -n "$force"
757 # If we don't already have a -f flag and the submodule has never been checked out
758 if test -z "$subsha1" -a -z "$force"
763 if test -z "$nofetch"
765 # Run fetch only if $sha1 isn't present or it
766 # is not reachable from a ref.
767 (clear_local_git_env; cd "$sm_path" &&
768 ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
769 test -z "$rev") || git-fetch)) ||
770 die "$(eval_gettext "Unable to fetch in submodule path '\$prefix\$sm_path'")"
773 # Is this something we just cloned?
774 case ";$cloned_modules;" in
776 # then there is no local change to integrate
781 case "$update_module" in
784 die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$prefix\$sm_path'")"
785 say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': rebased into '\$sha1'")"
786 must_die_on_failure=yes
790 die_msg="$(eval_gettext "Unable to merge '\$sha1' in submodule path '\$prefix\$sm_path'")"
791 say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': merged in '\$sha1'")"
792 must_die_on_failure=yes
795 command="git checkout $subforce -q"
796 die_msg="$(eval_gettext "Unable to checkout '\$sha1' in submodule path '\$prefix\$sm_path'")"
797 say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': checked out '\$sha1'")"
801 if (clear_local_git_env; cd "$sm_path" && $command "$sha1")
804 elif test -n "$must_die_on_failure"
806 die_with_status 2 "$die_msg"
808 err="${err};$die_msg"
813 if test -n "$recursive"
816 prefix="$prefix$sm_path/"
819 eval cmd_update "$orig_flags"
824 die_msg="$(eval_gettext "Failed to recurse into submodule path '\$prefix\$sm_path'")"
827 err="${err};$die_msg"
830 die_with_status $res "$die_msg"
857 git describe "$2" 2>/dev/null ||
858 git describe --tags "$2" 2>/dev/null ||
859 git describe --contains "$2" 2>/dev/null ||
860 git describe --all --always "$2"
863 test -z "$revname" || revname=" ($revname)"
866 # Show commit summary for submodules in index or working tree
868 # If '--cached' is given, show summary between index and given commit,
869 # or between working tree and given commit
871 # $@ = [commit (default 'HEAD'),] requested paths (default all)
878 # parse $args after "submodule ... summary".
892 if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
914 test $summary_limit = 0 && return
916 if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
920 elif test -z "$1" -o "$1" = "HEAD"
922 # before the first commit: compare with an empty tree
923 head=$(git hash-object -w -t tree --stdin </dev/null)
924 test -z "$1" || shift
932 die "$(gettext "The --cached option cannot be used with the --files option")"
938 # Get modified modules cared by user
939 modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
940 sane_egrep '^:([0-7]* )?160000' |
941 while read mod_src mod_dst sha1_src sha1_dst status name
943 # Always show modules deleted or type-changed (blob<->module)
944 test $status = D -o $status = T && echo "$name" && continue
945 # Also show added or modified modules which are checked out
946 GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
951 test -z "$modules" && return
953 git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules |
954 sane_egrep '^:([0-7]* )?160000' |
956 while read mod_src mod_dst sha1_src sha1_dst status name
958 if test -z "$cached" &&
959 test $sha1_dst = 0000000000000000000000000000000000000000
963 sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
965 100644 | 100755 | 120000)
966 sha1_dst=$(git hash-object $name)
972 eval_gettextln "unexpected mode \$mod_dst" >&2
979 test $mod_src = 160000 &&
980 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_src^0 >/dev/null &&
983 test $mod_dst = 160000 &&
984 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
988 case "$missing_src,$missing_dst" in
990 errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_src")"
993 errmsg="$(eval_gettext " Warn: \$name doesn't contain commit \$sha1_dst")"
996 errmsg="$(eval_gettext " Warn: \$name doesn't contain commits \$sha1_src and \$sha1_dst")"
1001 if test $mod_src = 160000 -a $mod_dst = 160000
1003 range="$sha1_src...$sha1_dst"
1004 elif test $mod_src = 160000
1010 GIT_DIR="$name/.git" \
1011 git rev-list --first-parent $range -- | wc -l
1013 total_commits=" ($(($total_commits + 0)))"
1017 sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
1018 sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
1021 blob="$(gettext "blob")"
1022 submodule="$(gettext "submodule")"
1023 if test $mod_dst = 160000
1025 echo "* $name $sha1_abbr_src($blob)->$sha1_abbr_dst($submodule)$total_commits:"
1027 echo "* $name $sha1_abbr_src($submodule)->$sha1_abbr_dst($blob)$total_commits:"
1030 echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
1032 if test -n "$errmsg"
1034 # Don't give error msg for modification whose dst is not submodule
1035 # i.e. deleted or changed to blob
1036 test $mod_dst = 160000 && echo "$errmsg"
1038 if test $mod_src = 160000 -a $mod_dst = 160000
1041 test $summary_limit -gt 0 && limit="-$summary_limit"
1042 GIT_DIR="$name/.git" \
1043 git log $limit --pretty='format: %m %s' \
1044 --first-parent $sha1_src...$sha1_dst
1045 elif test $mod_dst = 160000
1047 GIT_DIR="$name/.git" \
1048 git log --pretty='format: > %s' -1 $sha1_dst
1050 GIT_DIR="$name/.git" \
1051 git log --pretty='format: < %s' -1 $sha1_src
1057 if test -n "$for_status"; then
1058 if [ -n "$files" ]; then
1059 gettextln "Submodules changed but not updated:" | git stripspace -c
1061 gettextln "Submodule changes to be committed:" | git stripspace -c
1063 printf "\n" | git stripspace -c
1070 # List all submodules, prefixed with:
1071 # - submodule not initialized
1072 # + different revision checked out
1074 # If --cached was specified the revision in the index will be printed
1075 # instead of the currently checked out revision.
1077 # $@ = requested paths (default to all)
1081 # parse $args after "submodule ... status".
1109 while read mode sha1 stage sm_path
1111 die_if_unmatched "$mode"
1112 name=$(module_name "$sm_path") || exit
1113 url=$(git config submodule."$name".url)
1114 displaypath="$prefix$sm_path"
1115 if test "$stage" = U
1117 say "U$sha1 $displaypath"
1120 if test -z "$url" || ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
1122 say "-$sha1 $displaypath"
1125 set_name_rev "$sm_path" "$sha1"
1126 if git diff-files --ignore-submodules=dirty --quiet -- "$sm_path"
1128 say " $sha1 $displaypath$revname"
1130 if test -z "$cached"
1132 sha1=$(clear_local_git_env; cd "$sm_path" && git rev-parse --verify HEAD)
1133 set_name_rev "$sm_path" "$sha1"
1135 say "+$sha1 $displaypath$revname"
1138 if test -n "$recursive"
1141 prefix="$displaypath/"
1146 die "$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
1151 # Sync remote urls for submodules
1152 # This makes the value for remote.$remote.url match the value
1153 # specified in .gitmodules.
1182 while read mode sha1 stage sm_path
1184 die_if_unmatched "$mode"
1185 name=$(module_name "$sm_path")
1186 url=$(git config -f .gitmodules --get submodule."$name".url)
1188 # Possibly a url relative to parent
1191 # rewrite foo/bar as ../.. to find path from
1192 # submodule work tree to superproject work tree
1193 up_path="$(echo "$sm_path" | sed "s/[^/][^/]*/../g")" &&
1194 # guarantee a trailing /
1195 up_path=${up_path%/}/ &&
1196 # path from submodule work tree to submodule origin repo
1197 sub_origin_url=$(resolve_relative_url "$url" "$up_path") &&
1198 # path from superproject work tree to submodule origin repo
1199 super_config_url=$(resolve_relative_url "$url") || exit
1202 sub_origin_url="$url"
1203 super_config_url="$url"
1207 if git config "submodule.$name.url" >/dev/null 2>/dev/null
1209 say "$(eval_gettext "Synchronizing submodule url for '\$prefix\$sm_path'")"
1210 git config submodule."$name".url "$super_config_url"
1212 if test -e "$sm_path"/.git
1217 remote=$(get_default_remote)
1218 git config remote."$remote".url "$sub_origin_url"
1220 if test -n "$recursive"
1222 prefix="$prefix$sm_path/"
1231 # This loop parses the command line arguments to find the
1232 # subcommand name to dispatch. Parsing of the subcommand specific
1233 # options are primarily done by the subcommand implementations.
1234 # Subcommand specific options such as --branch and --cached are
1235 # parsed here as well, for backward compatibility.
1237 while test $# != 0 && test -z "$command"
1240 add | foreach | init | deinit | update | status | summary | sync)
1270 # No command word defaults to "status"
1271 if test -z "$command"
1281 # "-b branch" is accepted only by "add"
1282 if test -n "$branch" && test "$command" != add
1287 # "--cached" is accepted only by "status" and "summary"
1288 if test -n "$cached" && test "$command" != status -a "$command" != summary