submodule--helper: offer a consistent API
authorStefan Beller <sbeller@google.com>
Tue, 31 May 2016 23:59:33 +0000 (16:59 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Jun 2016 18:31:49 +0000 (11:31 -0700)
In 48308681 (2016-02-29, git submodule update: have a dedicated helper
for cloning), the helper communicated errors back only via exit code,
and dance with printing '#unmatched' in case of error was left to
git-submodule.sh as it uses the output of the helper and pipes it into
shell commands. This change makes the helper consistent by never
printing '#unmatched' in the helper but always handling these piping
issues in the actual shell script.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/submodule--helper.c
git-submodule.sh
index 8da263f0b0b086a74e23c2a5854bfa66623f70df..f0b2c4fe0bb4b71b3ccd7002702191ea4f46469e 100644 (file)
@@ -287,10 +287,8 @@ static int module_list(int argc, const char **argv, const char *prefix)
        argc = parse_options(argc, argv, prefix, module_list_options,
                             git_submodule_helper_usage, 0);
 
-       if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) {
-               printf("#unmatched\n");
+       if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0)
                return 1;
-       }
 
        for (i = 0; i < list.nr; i++) {
                const struct cache_entry *ce = list.entries[i];
index 5a4dec050b2ebdbe8f9674666ddaabb4c0e193f2..fadbe5d3e0181faf6f3b972723387e242fd6a0a1 100755 (executable)
@@ -345,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"
@@ -453,7 +456,10 @@ 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"
@@ -1013,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"
@@ -1091,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"