i18n: simplify numeric error reporting
[gitweb.git] / git-submodule.sh
index 4ec7546f1eb5617b85169cb6e926b9f490e1d6dc..b57f87de658b627c48ec672faaab3dc6aac3b505 100755 (executable)
@@ -49,7 +49,7 @@ die_if_unmatched ()
 {
        if test "$1" = "#unmatched"
        then
-               exit 1
+               exit ${2:-1}
        fi
 }
 
@@ -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,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".
@@ -423,11 +421,11 @@ cmd_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")
@@ -481,7 +479,8 @@ fetch_in_submodule () (
        '')
                git fetch ;;
        *)
-               git fetch $(get_default_remote) "$2" ;;
+               shift
+               git fetch $(get_default_remote) "$@" ;;
        esac
 )
 
@@ -581,16 +580,15 @@ 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)
-               branch=$(get_submodule_config "$name" branch master)
                if ! test -z "$update"
                then
                        update_module=$update
@@ -616,10 +614,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
-                               fetch_in_submodule "$sm_path" ||
+                               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)
@@ -642,13 +641,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
 
@@ -994,11 +993,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")
@@ -1075,11 +1074,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)