Merge branch 'sb/submodule-clone-retry'
authorJunio C Hamano <gitster@pobox.com>
Thu, 4 Aug 2016 21:39:17 +0000 (14:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 4 Aug 2016 21:39:17 +0000 (14:39 -0700)
An earlier tweak to make "submodule update" retry a failing clone
of submodules was buggy and caused segfault, which has been fixed.

* sb/submodule-clone-retry:
submodule-helper: fix indexing in clone retry error reporting path
git-submodule: forward exit code of git-submodule--helper more faithfully

1  2 
git-submodule.sh
diff --combined git-submodule.sh
index 2b23ce6e250e37288084e82e27b1c60bce8604b8,d8765361c5ca34d0540ce7a9d10aa1d7d2b08891..c90dc335d145fa0a16efbe41873a525b596b806d
@@@ -16,6 -16,7 +16,6 @@@ USAGE="[--quiet] add [-b <branch>] [-f|
  OPTIONS_SPEC=
  SUBDIRECTORY_OK=Yes
  . git-sh-setup
 -. git-sh-i18n
  . git-parse-remote
  require_work_tree
  wt_prefix=$(git rev-parse --show-prefix)
@@@ -49,7 -50,7 +49,7 @@@ die_if_unmatched (
  {
        if test "$1" = "#unmatched"
        then
-               exit 1
+               exit ${2:-1}
        fi
  }
  
@@@ -239,15 -240,14 +239,15 @@@ Use -f if you really want to add it." >
                then
                        if test -z "$force"
                        then
 -                              echo >&2 "$(eval_gettext "A git directory for '\$sm_name' is found locally with remote(s):")"
 +                              eval_gettextln >&2 "A git directory for '\$sm_name' is found locally with remote(s):"
                                GIT_DIR=".git/modules/$sm_name" GIT_WORK_TREE=. git remote -v | grep '(fetch)' | sed -e s,^,"  ", -e s,' (fetch)',, >&2
 -                              echo >&2 "$(eval_gettext "If you want to reuse this local git directory instead of cloning again from")"
 -                              echo >&2 "  $realrepo"
 -                              echo >&2 "$(eval_gettext "use the '--force' option. If the local git directory is not the correct repo")"
 -                              die "$(eval_gettext "or you are unsure what this means choose another name with the '--name' option.")"
 +                              die "$(eval_gettextln "\
 +If you want to reuse this local git directory instead of cloning again from
 +  \$realrepo
 +use the '--force' option. If the local git directory is not the correct repo
 +or you are unsure what this means choose another name with the '--name' option.")"
                        else
 -                              echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")"
 +                              eval_gettextln "Reactivating local git directory for submodule '\$sm_name'."
                        fi
                fi
                git submodule--helper clone ${GIT_QUIET:+--quiet} --prefix "$wt_prefix" --path "$sm_path" --name "$sm_name" --url "$realrepo" ${reference:+"$reference"} ${depth:+"$depth"} || exit
@@@ -312,11 -312,11 +312,11 @@@ cmd_foreach(
  
        {
                git submodule--helper list --prefix "$wt_prefix" ||
-               echo "#unmatched"
+               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=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
@@@ -379,6 -379,8 +379,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".
  
        {
                git submodule--helper list --prefix "$wt_prefix" "$@" ||
-               echo "#unmatched"
+               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=$(git submodule--helper relative-path "$sm_path" "$wt_prefix")
                        # Protect submodules containing a .git directory
                        if test -d "$sm_path/.git"
                        then
 -                              echo >&2 "$(eval_gettext "Submodule work tree '\$displaypath' contains a .git directory")"
 -                              die "$(eval_gettext "(use 'rm -rf' if you really want to remove it including all of its history)")"
 +                              die "$(eval_gettext "\
 +Submodule work tree '\$displaypath' contains a .git directory
 +(use 'rm -rf' if you really want to remove it including all of its history)")"
                        fi
  
                        if test -z "$force"
@@@ -579,12 -580,12 +579,12 @@@ cmd_update(
                ${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)
                        remote_name=$(sanitize_submodule_env; cd "$sm_path" && get_default_remote)
                        sha1=$(sanitize_submodule_env; cd "$sm_path" &&
                                git rev-parse --verify "${remote_name}/${branch}") ||
 -                      die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
 +                      die "$(eval_gettext "Unable to find current \${remote_name}/\${branch} revision in submodule path '\$sm_path'")"
                fi
  
                if test "$subsha1" != "$sha1" || test -n "$force"
                                # not be reachable from any of the refs
                                is_tip_reachable "$sm_path" "$sha1" ||
                                fetch_in_submodule "$sm_path" "$sha1" ||
 -                              die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain $sha1. Direct fetching of that commit failed.")"
 +                              die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain \$sha1. Direct fetching of that commit failed.")"
                        fi
  
                        must_die_on_failure=
@@@ -992,11 -993,11 +992,11 @@@ cmd_status(
  
        {
                git submodule--helper list --prefix "$wt_prefix" "$@" ||
-               echo "#unmatched"
+               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=$(git submodule--helper relative-path "$prefix$sm_path" "$wt_prefix")
@@@ -1073,11 -1074,11 +1073,11 @@@ cmd_sync(
        cd_to_toplevel
        {
                git submodule--helper list --prefix "$wt_prefix" "$@" ||
-               echo "#unmatched"
+               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)