Merge branch 'maint'
[git/git.git] / git-submodule.sh
CommitLineData
70c7ac22
LH
1#!/bin/sh
2#
ecda0723 3# git-submodules.sh: add, init, update or list git submodules
70c7ac22
LH
4#
5# Copyright (c) 2007 Lars Hjemli
6
f2dc06a3 7USAGE="[--quiet] [--cached] \
42b49178 8[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch] [--rebase|--merge]|summary [-n|--summary-limit <n>] [<commit>]] \
2327f61e 9[--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
8f321a39 10OPTIONS_SPEC=
70c7ac22 11. git-sh-setup
98fcf840 12. git-parse-remote
70c7ac22
LH
13require_work_tree
14
5c08dbbd 15command=
ecda0723 16branch=
d92a3959 17reference=
70c7ac22 18cached=
31ca3ac3 19nofetch=
32948425 20update=
70c7ac22 21
f31a522a
ML
22# Resolve relative url by appending to parent's url
23resolve_relative_url ()
24{
98fcf840 25 remote=$(get_default_remote)
8e7e6f39
ML
26 remoteurl=$(git config "remote.$remote.url") ||
27 die "remote ($remote) does not have a url defined in .git/config"
f31a522a 28 url="$1"
99b120af 29 remoteurl=${remoteurl%/}
f31a522a
ML
30 while test -n "$url"
31 do
32 case "$url" in
33 ../*)
34 url="${url#../}"
35 remoteurl="${remoteurl%/*}"
36 ;;
37 ./*)
38 url="${url#./}"
39 ;;
40 *)
41 break;;
42 esac
43 done
99b120af 44 echo "$remoteurl/${url%/}"
f31a522a
ML
45}
46
a7b3269c
DA
47#
48# Get submodule info for registered submodules
49# $@ = path to limit submodule list
50#
51module_list()
52{
496917b7 53 git ls-files --error-unmatch --stage -- "$@" | grep '^160000 '
a7b3269c
DA
54}
55
941987a5
LH
56#
57# Map submodule path to submodule name
58#
59# $1 = path
60#
61module_name()
62{
537601ac 63 # Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
fe22e542 64 re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
a5099bb4 65 name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
537601ac 66 sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
941987a5
LH
67 test -z "$name" &&
68 die "No submodule mapping found in .gitmodules for path '$path'"
69 echo "$name"
70}
33aa6fff
LH
71
72#
73# Clone a submodule
74#
23a485e3 75# Prior to calling, cmd_update checks that a possibly existing
ecda0723 76# path is not a git repository.
23a485e3 77# Likewise, cmd_add checks that path does not exist at all,
ecda0723
SV
78# since it is the location of a new submodule.
79#
33aa6fff
LH
80module_clone()
81{
82 path=$1
83 url=$2
d92a3959 84 reference="$3"
33aa6fff
LH
85
86 # If there already is a directory at the submodule path,
87 # expect it to be empty (since that is the default checkout
88 # action) and try to remove it.
89 # Note: if $path is a symlink to a directory the test will
90 # succeed but the rmdir will fail. We might want to fix this.
91 if test -d "$path"
92 then
93 rmdir "$path" 2>/dev/null ||
94 die "Directory '$path' exist, but is neither empty nor a git repository"
95 fi
96
97 test -e "$path" &&
98 die "A file already exist at path '$path'"
99
d92a3959
MT
100 if test -n "$reference"
101 then
102 git-clone "$reference" -n "$url" "$path"
103 else
104 git-clone -n "$url" "$path"
105 fi ||
941987a5 106 die "Clone of '$url' into submodule path '$path' failed"
33aa6fff
LH
107}
108
ecda0723
SV
109#
110# Add a new submodule to the working tree, .gitmodules and the index
111#
ec05df35 112# $@ = repo path
ecda0723
SV
113#
114# optional branch is stored in global branch variable
115#
23a485e3 116cmd_add()
ecda0723 117{
5c08dbbd
JH
118 # parse $args after "submodule ... add".
119 while test $# -ne 0
120 do
121 case "$1" in
122 -b | --branch)
123 case "$2" in '') usage ;; esac
124 branch=$2
125 shift
126 ;;
127 -q|--quiet)
2e6a30ef 128 GIT_QUIET=1
5c08dbbd 129 ;;
d92a3959
MT
130 --reference)
131 case "$2" in '') usage ;; esac
132 reference="--reference=$2"
133 shift
134 ;;
135 --reference=*)
136 reference="$1"
137 shift
138 ;;
5c08dbbd
JH
139 --)
140 shift
141 break
142 ;;
143 -*)
144 usage
145 ;;
146 *)
147 break
148 ;;
149 esac
150 shift
151 done
152
ecda0723
SV
153 repo=$1
154 path=$2
155
ec05df35 156 if test -z "$repo" -o -z "$path"; then
ecda0723
SV
157 usage
158 fi
159
ec05df35
ML
160 # assure repo is absolute or relative to parent
161 case "$repo" in
162 ./*|../*)
163 # dereference source url relative to parent's url
164 realrepo=$(resolve_relative_url "$repo") || exit
165 ;;
166 *:*|/*)
167 # absolute url
168 realrepo=$repo
169 ;;
170 *)
171 die "repo URL: '$repo' must be absolute or begin with ./|../"
172 ;;
173 esac
174
db75ada5
MG
175 # normalize path:
176 # multiple //; leading ./; /./; /../; trailing /
177 path=$(printf '%s/\n' "$path" |
178 sed -e '
179 s|//*|/|g
180 s|^\(\./\)*||
181 s|/\./|/|g
182 :start
183 s|\([^/]*\)/\.\./||
184 tstart
185 s|/*$||
186 ')
5be60078 187 git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
ecda0723
SV
188 die "'$path' already exists in the index"
189
d4264ca3
ML
190 # perhaps the path exists and is already a git repo, else clone it
191 if test -e "$path"
192 then
e9656473 193 if test -d "$path"/.git -o -f "$path"/.git
d4264ca3
ML
194 then
195 echo "Adding existing repo at '$path' to the index"
196 else
197 die "'$path' already exists and is not a valid git repo"
198 fi
c2f93917
ML
199
200 case "$repo" in
201 ./*|../*)
202 url=$(resolve_relative_url "$repo") || exit
203 ;;
204 *)
205 url="$repo"
206 ;;
207 esac
208 git config submodule."$path".url "$url"
d4264ca3 209 else
d4264ca3 210
d92a3959 211 module_clone "$path" "$realrepo" "$reference" || exit
ea10b60c
BJ
212 (
213 unset GIT_DIR
214 cd "$path" &&
215 # ash fails to wordsplit ${branch:+-b "$branch"...}
216 case "$branch" in
217 '') git checkout -f -q ;;
218 ?*) git checkout -f -q -b "$branch" "origin/$branch" ;;
219 esac
220 ) || die "Unable to checkout submodule '$path'"
d4264ca3
ML
221 fi
222
ecda0723
SV
223 git add "$path" ||
224 die "Failed to add submodule '$path'"
225
a5099bb4
IY
226 git config -f .gitmodules submodule."$path".path "$path" &&
227 git config -f .gitmodules submodule."$path".url "$repo" &&
ecda0723
SV
228 git add .gitmodules ||
229 die "Failed to register submodule '$path'"
230}
231
19a31f9c
ML
232#
233# Execute an arbitrary command sequence in each checked out
234# submodule
235#
236# $@ = command to execute
237#
238cmd_foreach()
239{
a7b3269c 240 module_list |
19a31f9c
ML
241 while read mode sha1 stage path
242 do
243 if test -e "$path"/.git
244 then
245 say "Entering '$path'"
246 (cd "$path" && eval "$@") ||
247 die "Stopping at '$path'; script returned non-zero status."
248 fi
249 done
250}
251
70c7ac22 252#
211b7f19 253# Register submodules in .git/config
70c7ac22
LH
254#
255# $@ = requested paths (default to all)
256#
23a485e3 257cmd_init()
70c7ac22 258{
5c08dbbd
JH
259 # parse $args after "submodule ... init".
260 while test $# -ne 0
261 do
262 case "$1" in
263 -q|--quiet)
2e6a30ef 264 GIT_QUIET=1
5c08dbbd
JH
265 ;;
266 --)
267 shift
268 break
269 ;;
270 -*)
271 usage
272 ;;
273 *)
274 break
275 ;;
276 esac
277 shift
278 done
279
a7b3269c 280 module_list "$@" |
70c7ac22
LH
281 while read mode sha1 stage path
282 do
211b7f19 283 # Skip already registered paths
941987a5 284 name=$(module_name "$path") || exit
5be60078 285 url=$(git config submodule."$name".url)
211b7f19 286 test -z "$url" || continue
70c7ac22 287
a5099bb4 288 url=$(git config -f .gitmodules submodule."$name".url)
70c7ac22 289 test -z "$url" &&
941987a5 290 die "No url found for submodule path '$path' in .gitmodules"
70c7ac22 291
f31a522a
ML
292 # Possibly a url relative to parent
293 case "$url" in
294 ./*|../*)
8e7e6f39 295 url=$(resolve_relative_url "$url") || exit
f31a522a
ML
296 ;;
297 esac
298
5be60078 299 git config submodule."$name".url "$url" ||
941987a5 300 die "Failed to register url for submodule path '$path'"
70c7ac22 301
32948425
JH
302 upd="$(git config -f .gitmodules submodule."$name".update)"
303 test -z "$upd" ||
304 git config submodule."$name".update "$upd" ||
305 die "Failed to register update mode for submodule path '$path'"
ca2cedba 306
941987a5 307 say "Submodule '$name' ($url) registered for path '$path'"
70c7ac22
LH
308 done
309}
310
311#
211b7f19 312# Update each submodule path to correct revision, using clone and checkout as needed
70c7ac22
LH
313#
314# $@ = requested paths (default to all)
315#
23a485e3 316cmd_update()
70c7ac22 317{
5c08dbbd
JH
318 # parse $args after "submodule ... update".
319 while test $# -ne 0
320 do
321 case "$1" in
322 -q|--quiet)
d1f63a37 323 shift
2e6a30ef 324 GIT_QUIET=1
5c08dbbd 325 ;;
be4d2c83 326 -i|--init)
d92a3959 327 init=1
be4d2c83 328 shift
be4d2c83 329 ;;
31ca3ac3
FF
330 -N|--no-fetch)
331 shift
332 nofetch=1
333 ;;
ca2cedba
PH
334 -r|--rebase)
335 shift
32948425 336 update="rebase"
ca2cedba 337 ;;
d92a3959
MT
338 --reference)
339 case "$2" in '') usage ;; esac
340 reference="--reference=$2"
341 shift 2
342 ;;
343 --reference=*)
344 reference="$1"
345 shift
346 ;;
42b49178
JH
347 -m|--merge)
348 shift
349 update="merge"
350 ;;
5c08dbbd
JH
351 --)
352 shift
353 break
354 ;;
355 -*)
356 usage
357 ;;
358 *)
359 break
360 ;;
361 esac
5c08dbbd
JH
362 done
363
d92a3959
MT
364 if test -n "$init"
365 then
366 cmd_init "--" "$@" || return
367 fi
368
a7b3269c 369 module_list "$@" |
70c7ac22
LH
370 while read mode sha1 stage path
371 do
941987a5 372 name=$(module_name "$path") || exit
5be60078 373 url=$(git config submodule."$name".url)
32948425 374 update_module=$(git config submodule."$name".update)
211b7f19 375 if test -z "$url"
70c7ac22
LH
376 then
377 # Only mention uninitialized submodules when its
378 # path have been specified
379 test "$#" != "0" &&
989206f5 380 say "Submodule path '$path' not initialized" &&
be4d2c83 381 say "Maybe you want to use 'update --init'?"
211b7f19
LH
382 continue
383 fi
384
ba88a1fe 385 if ! test -d "$path"/.git -o -f "$path"/.git
211b7f19 386 then
d92a3959 387 module_clone "$path" "$url" "$reference"|| exit
bf2d8246
LH
388 subsha1=
389 else
51884080 390 subsha1=$(unset GIT_DIR; cd "$path" &&
5be60078 391 git rev-parse --verify HEAD) ||
941987a5 392 die "Unable to find current revision in submodule path '$path'"
70c7ac22 393 fi
211b7f19 394
32948425 395 if ! test -z "$update"
ca2cedba 396 then
32948425 397 update_module=$update
ca2cedba
PH
398 fi
399
70c7ac22
LH
400 if test "$subsha1" != "$sha1"
401 then
b9b378a0
PY
402 force=
403 if test -z "$subsha1"
404 then
405 force="-f"
406 fi
31ca3ac3
FF
407
408 if test -z "$nofetch"
409 then
410 (unset GIT_DIR; cd "$path" &&
411 git-fetch) ||
412 die "Unable to fetch in submodule path '$path'"
413 fi
414
32948425
JH
415 case "$update_module" in
416 rebase)
417 command="git rebase"
ca2cedba
PH
418 action="rebase"
419 msg="rebased onto"
32948425 420 ;;
42b49178
JH
421 merge)
422 command="git merge"
423 action="merge"
424 msg="merged in"
425 ;;
32948425
JH
426 *)
427 command="git checkout $force -q"
ca2cedba
PH
428 action="checkout"
429 msg="checked out"
32948425
JH
430 ;;
431 esac
70c7ac22 432
ca2cedba
PH
433 (unset GIT_DIR; cd "$path" && $command "$sha1") ||
434 die "Unable to $action '$sha1' in submodule path '$path'"
435 say "Submodule path '$path': $msg '$sha1'"
70c7ac22
LH
436 fi
437 done
438}
439
bffe71f4
EM
440set_name_rev () {
441 revname=$( (
51884080 442 unset GIT_DIR
bffe71f4 443 cd "$1" && {
5be60078
JH
444 git describe "$2" 2>/dev/null ||
445 git describe --tags "$2" 2>/dev/null ||
f669ac0b
ML
446 git describe --contains "$2" 2>/dev/null ||
447 git describe --all --always "$2"
bffe71f4
EM
448 }
449 ) )
450 test -z "$revname" || revname=" ($revname)"
451}
28f9af5d
PY
452#
453# Show commit summary for submodules in index or working tree
454#
455# If '--cached' is given, show summary between index and given commit,
456# or between working tree and given commit
457#
458# $@ = [commit (default 'HEAD'),] requested paths (default all)
459#
460cmd_summary() {
f2dc06a3 461 summary_limit=-1
d0f64dd4 462 for_status=
f2dc06a3 463
28f9af5d
PY
464 # parse $args after "submodule ... summary".
465 while test $# -ne 0
466 do
467 case "$1" in
468 --cached)
469 cached="$1"
470 ;;
d0f64dd4
PY
471 --for-status)
472 for_status="$1"
473 ;;
f2dc06a3
PY
474 -n|--summary-limit)
475 if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
476 then
477 :
478 else
479 usage
480 fi
481 shift
482 ;;
28f9af5d
PY
483 --)
484 shift
485 break
486 ;;
487 -*)
488 usage
489 ;;
490 *)
491 break
492 ;;
493 esac
494 shift
495 done
bffe71f4 496
f2dc06a3
PY
497 test $summary_limit = 0 && return
498
30353a40 499 if rev=$(git rev-parse -q --verify "$1^0")
28f9af5d
PY
500 then
501 head=$rev
502 shift
503 else
504 head=HEAD
505 fi
506
507 cd_to_toplevel
508 # Get modified modules cared by user
509 modules=$(git diff-index $cached --raw $head -- "$@" |
759ad19e 510 egrep '^:([0-7]* )?160000' |
28f9af5d
PY
511 while read mod_src mod_dst sha1_src sha1_dst status name
512 do
513 # Always show modules deleted or type-changed (blob<->module)
514 test $status = D -o $status = T && echo "$name" && continue
515 # Also show added or modified modules which are checked out
516 GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
517 echo "$name"
518 done
519 )
1cb639e6 520
d0f64dd4
PY
521 test -z "$modules" && return
522
1cb639e6 523 git diff-index $cached --raw $head -- $modules |
759ad19e 524 egrep '^:([0-7]* )?160000' |
1cb639e6
PY
525 cut -c2- |
526 while read mod_src mod_dst sha1_src sha1_dst status name
527 do
528 if test -z "$cached" &&
529 test $sha1_dst = 0000000000000000000000000000000000000000
530 then
531 case "$mod_dst" in
532 160000)
533 sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
534 ;;
535 100644 | 100755 | 120000)
536 sha1_dst=$(git hash-object $name)
537 ;;
538 000000)
539 ;; # removed
540 *)
541 # unexpected type
542 echo >&2 "unexpected mode $mod_dst"
543 continue ;;
544 esac
545 fi
546 missing_src=
547 missing_dst=
548
549 test $mod_src = 160000 &&
30353a40 550 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_src^0 >/dev/null &&
1cb639e6
PY
551 missing_src=t
552
553 test $mod_dst = 160000 &&
30353a40 554 ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
1cb639e6 555 missing_dst=t
bffe71f4 556
1cb639e6
PY
557 total_commits=
558 case "$missing_src,$missing_dst" in
559 t,)
560 errmsg=" Warn: $name doesn't contain commit $sha1_src"
561 ;;
562 ,t)
563 errmsg=" Warn: $name doesn't contain commit $sha1_dst"
564 ;;
565 t,t)
566 errmsg=" Warn: $name doesn't contain commits $sha1_src and $sha1_dst"
567 ;;
568 *)
569 errmsg=
570 total_commits=$(
571 if test $mod_src = 160000 -a $mod_dst = 160000
572 then
573 range="$sha1_src...$sha1_dst"
574 elif test $mod_src = 160000
575 then
576 range=$sha1_src
577 else
578 range=$sha1_dst
579 fi
580 GIT_DIR="$name/.git" \
581 git log --pretty=oneline --first-parent $range | wc -l
582 )
eed35595 583 total_commits=" ($(($total_commits + 0)))"
1cb639e6
PY
584 ;;
585 esac
586
587 sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
588 sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
589 if test $status = T
590 then
591 if test $mod_dst = 160000
592 then
593 echo "* $name $sha1_abbr_src(blob)->$sha1_abbr_dst(submodule)$total_commits:"
594 else
595 echo "* $name $sha1_abbr_src(submodule)->$sha1_abbr_dst(blob)$total_commits:"
596 fi
597 else
598 echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
599 fi
600 if test -n "$errmsg"
601 then
602 # Don't give error msg for modification whose dst is not submodule
603 # i.e. deleted or changed to blob
604 test $mod_dst = 160000 && echo "$errmsg"
605 else
606 if test $mod_src = 160000 -a $mod_dst = 160000
607 then
f2dc06a3
PY
608 limit=
609 test $summary_limit -gt 0 && limit="-$summary_limit"
1cb639e6 610 GIT_DIR="$name/.git" \
f2dc06a3 611 git log $limit --pretty='format: %m %s' \
1cb639e6
PY
612 --first-parent $sha1_src...$sha1_dst
613 elif test $mod_dst = 160000
614 then
615 GIT_DIR="$name/.git" \
616 git log --pretty='format: > %s' -1 $sha1_dst
617 else
618 GIT_DIR="$name/.git" \
619 git log --pretty='format: < %s' -1 $sha1_src
620 fi
621 echo
622 fi
623 echo
d0f64dd4
PY
624 done |
625 if test -n "$for_status"; then
626 echo "# Modified submodules:"
627 echo "#"
628 sed -e 's|^|# |' -e 's|^# $|#|'
629 else
630 cat
631 fi
28f9af5d 632}
70c7ac22 633#
941987a5 634# List all submodules, prefixed with:
70c7ac22
LH
635# - submodule not initialized
636# + different revision checked out
637#
638# If --cached was specified the revision in the index will be printed
639# instead of the currently checked out revision.
640#
641# $@ = requested paths (default to all)
642#
23a485e3 643cmd_status()
70c7ac22 644{
5c08dbbd
JH
645 # parse $args after "submodule ... status".
646 while test $# -ne 0
647 do
648 case "$1" in
649 -q|--quiet)
2e6a30ef 650 GIT_QUIET=1
5c08dbbd
JH
651 ;;
652 --cached)
653 cached=1
654 ;;
655 --)
656 shift
657 break
658 ;;
659 -*)
660 usage
661 ;;
662 *)
663 break
664 ;;
665 esac
666 shift
667 done
668
a7b3269c 669 module_list "$@" |
70c7ac22
LH
670 while read mode sha1 stage path
671 do
941987a5 672 name=$(module_name "$path") || exit
5be60078 673 url=$(git config submodule."$name".url)
ba88a1fe 674 if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git
70c7ac22
LH
675 then
676 say "-$sha1 $path"
677 continue;
678 fi
41c7c1bd 679 set_name_rev "$path" "$sha1"
70c7ac22
LH
680 if git diff-files --quiet -- "$path"
681 then
bffe71f4 682 say " $sha1 $path$revname"
70c7ac22
LH
683 else
684 if test -z "$cached"
685 then
51884080 686 sha1=$(unset GIT_DIR; cd "$path" && git rev-parse --verify HEAD)
41c7c1bd 687 set_name_rev "$path" "$sha1"
70c7ac22 688 fi
bffe71f4 689 say "+$sha1 $path$revname"
70c7ac22
LH
690 fi
691 done
692}
2327f61e
DA
693#
694# Sync remote urls for submodules
695# This makes the value for remote.$remote.url match the value
696# specified in .gitmodules.
697#
698cmd_sync()
699{
700 while test $# -ne 0
701 do
702 case "$1" in
703 -q|--quiet)
2e6a30ef 704 GIT_QUIET=1
2327f61e
DA
705 shift
706 ;;
707 --)
708 shift
709 break
710 ;;
711 -*)
712 usage
713 ;;
714 *)
715 break
716 ;;
717 esac
718 done
719 cd_to_toplevel
720 module_list "$@" |
721 while read mode sha1 stage path
722 do
723 name=$(module_name "$path")
724 url=$(git config -f .gitmodules --get submodule."$name".url)
baede9f8
JH
725
726 # Possibly a url relative to parent
727 case "$url" in
728 ./*|../*)
729 url=$(resolve_relative_url "$url") || exit
730 ;;
731 esac
732
2327f61e
DA
733 if test -e "$path"/.git
734 then
735 (
736 unset GIT_DIR
737 cd "$path"
738 remote=$(get_default_remote)
739 say "Synchronizing submodule url for '$name'"
740 git config remote."$remote".url "$url"
741 )
742 fi
743 done
744}
70c7ac22 745
5c08dbbd
JH
746# This loop parses the command line arguments to find the
747# subcommand name to dispatch. Parsing of the subcommand specific
748# options are primarily done by the subcommand implementations.
749# Subcommand specific options such as --branch and --cached are
750# parsed here as well, for backward compatibility.
751
752while test $# != 0 && test -z "$command"
70c7ac22
LH
753do
754 case "$1" in
2327f61e 755 add | foreach | init | update | status | summary | sync)
5c08dbbd 756 command=$1
70c7ac22
LH
757 ;;
758 -q|--quiet)
2e6a30ef 759 GIT_QUIET=1
70c7ac22 760 ;;
ecda0723
SV
761 -b|--branch)
762 case "$2" in
763 '')
764 usage
765 ;;
766 esac
767 branch="$2"; shift
768 ;;
70c7ac22 769 --cached)
28f9af5d 770 cached="$1"
70c7ac22
LH
771 ;;
772 --)
773 break
774 ;;
775 -*)
776 usage
777 ;;
778 *)
779 break
780 ;;
781 esac
782 shift
783done
784
5c08dbbd
JH
785# No command word defaults to "status"
786test -n "$command" || command=status
787
788# "-b branch" is accepted only by "add"
789if test -n "$branch" && test "$command" != add
790then
ecda0723 791 usage
5c08dbbd
JH
792fi
793
28f9af5d
PY
794# "--cached" is accepted only by "status" and "summary"
795if test -n "$cached" && test "$command" != status -a "$command" != summary
5c08dbbd 796then
70c7ac22 797 usage
5c08dbbd
JH
798fi
799
800"cmd_$command" "$@"