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
56 n
=$
(($1 + 0)) 2>/dev
/null
&& test "$n" = "$1"
59 # Sanitize the local git environment for use within a submodule. We
60 # can't simply use clear_local_git_env since we want to preserve some
61 # of the settings from GIT_CONFIG_PARAMETERS.
62 sanitize_submodule_env
()
64 save_config
=$GIT_CONFIG_PARAMETERS
66 GIT_CONFIG_PARAMETERS
=$save_config
67 export GIT_CONFIG_PARAMETERS
71 # Add a new submodule to the working tree, .gitmodules and the index
75 # optional branch is stored in global branch variable
79 # parse $args after "submodule ... add".
85 case "$2" in '') usage
;; esac
99 case "$2" in '') usage
;; esac
104 reference_path
="${1#--reference=}"
110 case "$2" in '') usage
;; esac
115 case "$2" in '') usage
;; esac
141 git
${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@"
145 # Execute an arbitrary command sequence in each checked out
148 # $@ = command to execute
152 # parse $args after "submodule ... foreach".
172 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@"
176 # Register submodules in .git/config
178 # $@ = requested paths (default to all)
182 # parse $args after "submodule ... init".
203 git
${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@"
207 # Unregister submodules from .git/config and remove their work tree
211 # parse $args after "submodule ... deinit".
239 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@"
243 # Update each submodule path to correct revision, using clone and checkout as needed
245 # $@ = requested paths (default to all)
249 # parse $args after "submodule ... update".
282 case "$2" in '') usage
;; esac
283 reference
="--reference=$2"
302 recommend_shallow
="--recommend-shallow"
304 --no-recommend-shallow)
305 recommend_shallow
="--no-recommend-shallow"
308 case "$2" in '') usage
;; esac
316 case "$2" in '') usage
;; esac
324 single_branch
="--single-branch"
327 single_branch
="--no-single-branch"
330 case "$2" in '') usage
;; esac
351 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
352 ${GIT_QUIET:+--quiet} \
354 ${progress:+"--progress"} \
355 ${remote:+--remote} \
356 ${recursive:+--recursive} \
358 ${nofetch:+--no-fetch} \
359 ${wt_prefix:+--prefix "$wt_prefix"} \
360 ${prefix:+--recursive-prefix "$prefix"} \
361 ${update:+--update "$update"} \
362 ${reference:+"$reference"} \
363 ${dissociate:+"--dissociate"} \
365 ${require_init:+--require-init} \
366 ${dissociate:+"--dissociate"} \
376 # Configures a submodule's default branch
378 # $@ = requested path
388 # we don't do anything with this but we need to accept it
394 case "$2" in '') usage
;; esac
412 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${GIT_QUIET:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@"
416 # Configures a submodule's remote url
418 # $@ = requested path, requested url
441 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url
${GIT_QUIET:+--quiet} -- "$@"
445 # Show commit summary for submodules in index or working tree
447 # If '--cached' is given, show summary between index and given commit,
448 # or between working tree and given commit
450 # $@ = [commit (default 'HEAD'),] requested paths (default all)
457 # parse $args after "submodule ... summary".
472 isnumber
"$summary_limit" || usage
476 summary_limit
="${1#--summary-limit=}"
477 isnumber
"$summary_limit" || usage
493 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper summary ${files:+--files} ${cached:+--cached} ${for_status:+--for-status} ${summary_limit:+-n $summary_limit} -- "$@"
496 # List all submodules, prefixed with:
497 # - submodule not initialized
498 # + different revision checked out
500 # If --cached was specified the revision in the index will be printed
501 # instead of the currently checked out revision.
503 # $@ = requested paths (default to all)
507 # parse $args after "submodule ... status".
534 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@"
537 # Sync remote urls for submodules
538 # This makes the value for remote.$remote.url match the value
539 # specified in .gitmodules.
567 git
${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@"
572 git submodule--helper absorb-git-dirs
--prefix "$wt_prefix" "$@"
575 # This loop parses the command line arguments to find the
576 # subcommand name to dispatch. Parsing of the subcommand specific
577 # options are primarily done by the subcommand implementations.
578 # Subcommand specific options such as --branch and --cached are
579 # parsed here as well, for backward compatibility.
581 while test $# != 0 && test -z "$command"
584 add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs
)
614 # No command word defaults to "status"
615 if test -z "$command"
625 # "-b branch" is accepted only by "add" and "set-branch"
626 if test -n "$branch" && (test "$command" != add ||
test "$command" != set-branch
)
631 # "--cached" is accepted only by "status" and "summary"
632 if test -n "$cached" && test "$command" != status
&& test "$command" != summary
637 "cmd_$(echo $command | sed -e s/-/_/g)" "$@"