Merge branch 'sb/submodule-helper-list-signal-unmatch-via-exit-status'
[gitweb.git] / git-submodule.sh
index 14d02cc4bc2d55c63f5a49fa78b599e8e649e6a3..fadbe5d3e0181faf6f3b972723387e242fd6a0a1 100755 (executable)
@@ -8,7 +8,7 @@ dashless=$(basename "$0" | sed -e 's/-/ /')
 USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] init [--] [<path>...]
-   or: $dashless [--quiet] deinit [-f|--force] [--] <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] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
    or: $dashless [--quiet] foreach [--recursive] <command>
@@ -124,9 +124,10 @@ isnumber()
 # of the settings from GIT_CONFIG_PARAMETERS.
 sanitize_submodule_env()
 {
-       sanitized_config=$(git submodule--helper sanitize-config)
+       save_config=$GIT_CONFIG_PARAMETERS
        clear_local_git_env
-       GIT_CONFIG_PARAMETERS=$sanitized_config
+       GIT_CONFIG_PARAMETERS=$save_config
+       export GIT_CONFIG_PARAMETERS
 }
 
 #
@@ -344,7 +345,10 @@ 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"
@@ -415,6 +419,7 @@ cmd_init()
 cmd_deinit()
 {
        # parse $args after "submodule ... deinit".
+       deinit_all=
        while test $# -ne 0
        do
                case "$1" in
@@ -424,6 +429,9 @@ cmd_deinit()
                -q|--quiet)
                        GIT_QUIET=1
                        ;;
+               --all)
+                       deinit_all=t
+                       ;;
                --)
                        shift
                        break
@@ -438,12 +446,20 @@ cmd_deinit()
                shift
        done
 
-       if test $# = 0
+       if test -n "$deinit_all" && test "$#" -ne 0
+       then
+               echo >&2 "$(eval_gettext "pathspec and --all are incompatible")"
+               usage
+       fi
+       if test $# = 0 && test -z "$deinit_all"
        then
-               die "$(eval_gettext "Use '.' if you really want to deinitialize all submodules")"
+               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"
@@ -1003,7 +1019,10 @@ 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"
@@ -1081,7 +1100,10 @@ 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"