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] [--cached]
9 or: $dashless [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
10 or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
11 or: $dashless [--quiet] init [--] [<path>...]
12 or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
13 or: $dashless [--quiet] update [--init [--filter=<filter-spec>]] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...]
14 or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path>
15 or: $dashless [--quiet] set-url [--] <path> <newurl>
16 or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
17 or: $dashless [--quiet] foreach [--recursive] <command>
18 or: $dashless [--quiet] sync [--recursive] [--] [<path>...]
19 or: $dashless [--quiet] absorbgitdirs [--] [<path>...]"
24 wt_prefix
=$
(git rev-parse
--show-prefix)
27 # Tell the rest of git that any URLs we get don't come
28 # directly from the user, so it can apply policy as appropriate.
29 GIT_PROTOCOL_FROM_USER
=0
30 export GIT_PROTOCOL_FROM_USER
61 # Add a new submodule to the working tree, .gitmodules and the index
65 # optional branch is stored in global branch variable
69 # parse $args after "submodule ... add".
74 case "$2" in '') usage
;; esac
91 case "$2" in '') usage
;; esac
92 reference
="--reference=$2"
99 case "$2" in '') usage
;; esac
100 ref_format
="--ref-format=$2"
110 case "$2" in '') usage
;; esac
118 case "$2" in '') usage
;; esac
144 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper add \
148 ${branch:+"$branch"} \
149 ${reference:+"$reference"} \
150 ${ref_format:+"$ref_format"} \
159 # Execute an arbitrary command sequence in each checked out
162 # $@ = command to execute
166 # parse $args after "submodule ... foreach".
186 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach \
194 # Register submodules in .git/config
196 # $@ = requested paths (default to all)
200 # parse $args after "submodule ... init".
221 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper init \
228 # Unregister submodules from .git/config and remove their work tree
232 # parse $args after "submodule ... deinit".
259 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit \
268 # Update each submodule path to correct revision, using clone and checkout as needed
270 # $@ = requested paths (default to all)
274 # parse $args after "submodule ... update".
306 case "$2" in '') usage
;; esac
307 ref_format
="--ref-format=$2"
314 case "$2" in '') usage
;; esac
315 reference
="--reference=$2"
333 --recommend-shallow|
--no-recommend-shallow)
337 case "$2" in '') usage
;; esac
345 case "$2" in '') usage
;; esac
352 --single-branch|
--no-single-branch)
356 case "$2" in '') usage
;; esac
377 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
388 ${ref_format:+"$ref_format"} \
389 ${reference:+"$reference"} \
402 # Configures a submodule's default branch
404 # $@ = requested path
407 # parse $args after "submodule ... set-branch".
412 # we don't do anything with this but we need to accept it
418 case "$2" in '') usage
;; esac
439 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch \
441 ${branch:+"$branch"} \
448 # Configures a submodule's remote url
450 # $@ = requested path, requested url
453 # parse $args after "submodule ... set-url".
474 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url \
481 # Show commit summary for submodules in index or working tree
483 # If '--cached' is given, show summary between index and given commit,
484 # or between working tree and given commit
486 # $@ = [commit (default 'HEAD'),] requested paths (default all)
489 # parse $args after "submodule ... summary".
503 case "$2" in '') usage
;; esac
504 summary_limit
="--summary-limit=$2"
507 -n*|
--summary-limit=*)
524 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper summary \
528 ${summary_limit:+"$summary_limit"} \
533 # List all submodules, prefixed with:
534 # - submodule not initialized
535 # + different revision checked out
537 # If --cached was specified the revision in the index will be printed
538 # instead of the currently checked out revision.
540 # $@ = requested paths (default to all)
544 # parse $args after "submodule ... status".
571 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper status \
580 # Sync remote urls for submodules
581 # This makes the value for remote.$remote.url match the value
582 # specified in .gitmodules.
586 # parse $args after "submodule ... sync".
611 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper sync \
620 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper absorbgitdirs
"$@"
623 # This loop parses the command line arguments to find the
624 # subcommand name to dispatch. Parsing of the subcommand specific
625 # options are primarily done by the subcommand implementations.
626 # Subcommand specific options such as --branch and --cached are
627 # parsed here as well, for backward compatibility.
629 while test $# != 0 && test -z "$command"
632 add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs
)
654 # No command word defaults to "status"
655 if test -z "$command"
665 # "--cached" is accepted only by "status" and "summary"
666 if test -n "$cached" && test "$command" != status
&& test "$command" != summary
671 "cmd_$(echo $command | sed -e s/-/_/g)" "$@"