diff options
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-x | git-submodule.sh | 128 |
1 files changed, 56 insertions, 72 deletions
diff --git a/git-submodule.sh b/git-submodule.sh index 37c61f1652..0a477b4c97 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -9,7 +9,7 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...] or: $dashless [--quiet] init [--] [<path>...] or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...) - or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...] + or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] or: $dashless [--quiet] foreach [--recursive] <command> or: $dashless [--quiet] sync [--recursive] [--] [<path>...]" @@ -21,14 +21,10 @@ require_work_tree wt_prefix=$(git rev-parse --show-prefix) cd_to_toplevel -# Restrict ourselves to a vanilla subset of protocols; the URLs -# we get are under control of a remote repository, and we do not -# want them kicking off arbitrary git-remote-* programs. -# -# If the user has already specified a set of allowed protocols, -# we assume they know what they're doing and use that instead. -: ${GIT_ALLOW_PROTOCOL=file:git:http:https:ssh} -export GIT_ALLOW_PROTOCOL +# Tell the rest of git that any URLs we get don't come +# directly from the user, so it can apply policy as appropriate. +GIT_PROTOCOL_FROM_USER=0 +export GIT_PROTOCOL_FROM_USER command= branch= @@ -44,47 +40,13 @@ update= prefix= custom_name= depth= - -# Resolve a path to be relative to another path. This is intended for -# converting submodule paths when git-submodule is run in a subdirectory -# and only handles paths where the directory separator is '/'. -# -# The output is the first argument as a path relative to the second argument, -# which defaults to $wt_prefix if it is omitted. -relative_path () -{ - local target curdir result - target=$1 - curdir=${2-$wt_prefix} - curdir=${curdir%/} - result= - - while test -n "$curdir" - do - case "$target" in - "$curdir/"*) - target=${target#"$curdir"/} - break - ;; - esac - - result="${result}../" - if test "$curdir" = "${curdir%/*}" - then - curdir= - else - curdir="${curdir%/*}" - fi - done - - echo "$result$target" -} +progress= die_if_unmatched () { if test "$1" = "#unmatched" then - exit 1 + exit ${2:-1} fi } @@ -345,20 +307,23 @@ cmd_foreach() # command in the subshell (and a recursive call to this function) exec 3<&0 - git submodule--helper list --prefix "$wt_prefix"| + { + git submodule--helper list --prefix "$wt_prefix" || + echo "#unmatched" $? + } | while read mode sha1 stage sm_path do - die_if_unmatched "$mode" + die_if_unmatched "$mode" "$sha1" if test -e "$sm_path"/.git then - displaypath=$(relative_path "$prefix$sm_path") + displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") say "$(eval_gettext "Entering '\$displaypath'")" name=$(git submodule--helper name "$sm_path") ( prefix="$prefix$sm_path/" sanitize_submodule_env cd "$sm_path" && - sm_path=$(relative_path "$sm_path") && + sm_path=$(git submodule--helper relative-path "$sm_path" "$wt_prefix") && # we make $path available to scripts ... path=$sm_path && if test $# -eq 1 @@ -411,8 +376,6 @@ cmd_init() # # Unregister submodules from .git/config and remove their work tree # -# $@ = requested paths (use '.' to deinit all submodules) -# cmd_deinit() { # parse $args after "submodule ... deinit". @@ -453,13 +416,16 @@ cmd_deinit() die "$(eval_gettext "Use '--all' if you really want to deinitialize all submodules")" fi - git submodule--helper list --prefix "$wt_prefix" "$@" | + { + git submodule--helper list --prefix "$wt_prefix" "$@" || + echo "#unmatched" $? + } | while read mode sha1 stage sm_path do - die_if_unmatched "$mode" + die_if_unmatched "$mode" "$sha1" name=$(git submodule--helper name "$sm_path") || exit - displaypath=$(relative_path "$sm_path") + displaypath=$(git submodule--helper relative-path "$sm_path" "$wt_prefix") # Remove the submodule work tree (unless the user already did it) if test -d "$sm_path" @@ -510,7 +476,8 @@ fetch_in_submodule () ( '') git fetch ;; *) - git fetch $(get_default_remote) "$2" ;; + shift + git fetch $(get_default_remote) "$@" ;; esac ) @@ -528,6 +495,9 @@ cmd_update() -q|--quiet) GIT_QUIET=1 ;; + --progress) + progress="--progress" + ;; -i|--init) init=1 ;; @@ -560,6 +530,12 @@ cmd_update() --checkout) update="checkout" ;; + --recommend-shallow) + recommend_shallow="--recommend-shallow" + ;; + --no-recommend-shallow) + recommend_shallow="--no-recommend-shallow" + ;; --depth) case "$2" in '') usage ;; esac depth="--depth=$2" @@ -597,22 +573,23 @@ cmd_update() { git submodule--helper update-clone ${GIT_QUIET:+--quiet} \ + ${progress:+"$progress"} \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ - ${reference:+--reference "$reference"} \ + ${reference:+"$reference"} \ ${depth:+--depth "$depth"} \ + ${recommend_shallow:+"$recommend_shallow"} \ ${jobs:+$jobs} \ - "$@" || echo "#unmatched" + "$@" || echo "#unmatched" $? } | { err= while read mode sha1 stage just_cloned sm_path do - die_if_unmatched "$mode" + die_if_unmatched "$mode" "$sha1" name=$(git submodule--helper name "$sm_path") || exit url=$(git config submodule."$name".url) - branch=$(get_submodule_config "$name" branch master) if ! test -z "$update" then update_module=$update @@ -624,7 +601,7 @@ cmd_update() fi fi - displaypath=$(relative_path "$prefix$sm_path") + displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") if test $just_cloned -eq 1 then @@ -638,10 +615,11 @@ cmd_update() if test -n "$remote" then + branch=$(git submodule--helper remote-branch "$sm_path") if test -z "$nofetch" then # Fetch remote before determining tracking $sha1 - (sanitize_submodule_env; cd "$sm_path" && git-fetch) || + fetch_in_submodule "$sm_path" $depth || die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")" fi remote_name=$(sanitize_submodule_env; cd "$sm_path" && get_default_remote) @@ -664,13 +642,13 @@ cmd_update() # Run fetch only if $sha1 isn't present or it # is not reachable from a ref. is_tip_reachable "$sm_path" "$sha1" || - fetch_in_submodule "$sm_path" || + fetch_in_submodule "$sm_path" $depth || die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")" # Now we tried the usual fetch, but $sha1 may # not be reachable from any of the refs is_tip_reachable "$sm_path" "$sha1" || - fetch_in_submodule "$sm_path" "$sha1" || + fetch_in_submodule "$sm_path" $depth "$sha1" || die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain \$sha1. Direct fetching of that commit failed.")" fi @@ -718,7 +696,7 @@ cmd_update() if test -n "$recursive" then ( - prefix=$(relative_path "$prefix$sm_path/") + prefix=$(git submodule--helper relative-path "$prefix$sm_path/" "$wt_prefix") wt_prefix= sanitize_submodule_env cd "$sm_path" && @@ -728,7 +706,7 @@ cmd_update() if test $res -gt 0 then die_msg="$(eval_gettext "Failed to recurse into submodule path '\$displaypath'")" - if test $res -eq 1 + if test $res -ne 2 then err="${err};$die_msg" continue @@ -902,7 +880,7 @@ cmd_summary() { ! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null && missing_dst=t - display_name=$(relative_path "$name") + display_name=$(git submodule--helper relative-path "$name" "$wt_prefix") total_commits= case "$missing_src,$missing_dst" in @@ -1014,13 +992,16 @@ cmd_status() shift done - git submodule--helper list --prefix "$wt_prefix" "$@" | + { + git submodule--helper list --prefix "$wt_prefix" "$@" || + echo "#unmatched" $? + } | while read mode sha1 stage sm_path do - die_if_unmatched "$mode" + die_if_unmatched "$mode" "$sha1" name=$(git submodule--helper name "$sm_path") || exit url=$(git config submodule."$name".url) - displaypath=$(relative_path "$prefix$sm_path") + displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") if test "$stage" = U then say "U$sha1 $displaypath" @@ -1092,10 +1073,13 @@ cmd_sync() esac done cd_to_toplevel - git submodule--helper list --prefix "$wt_prefix" "$@" | + { + git submodule--helper list --prefix "$wt_prefix" "$@" || + echo "#unmatched" $? + } | while read mode sha1 stage sm_path do - die_if_unmatched "$mode" + die_if_unmatched "$mode" "$sha1" name=$(git submodule--helper name "$sm_path") url=$(git config -f .gitmodules --get submodule."$name".url) @@ -1120,7 +1104,7 @@ cmd_sync() if git config "submodule.$name.url" >/dev/null 2>/dev/null then - displaypath=$(relative_path "$prefix$sm_path") + displaypath=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix") say "$(eval_gettext "Synchronizing submodule url for '\$displaypath'")" git config submodule."$name".url "$super_config_url" |