Skip to content

Commit c5dbfd4

Browse files
committed
submodule status: propagate SIGPIPE
It has been reported than running git submodule status --recurse | grep -q ^+ results in an unexpected error message fatal: failed to recurse into submodule $submodule When "git submodule--helper" recurses into a submodule it creates a child process. If that process fails then the error message above is displayed by the parent. In the case above the child in killed by SIGPIPE as grep exits as soon as it sees the first match. Fix this by propagating SIGPIPE so that it is visible to the process running git. We could propagate other signals but I'm not sure there is much value in doing that. In the common case of the user pressing Ctrl-C or Ctrl-\ then SIGINT or SIGQUIT will be sent to the foreground process group and so the parent process will receive the same signal as the child. Reported-by: Matt Liberty <[email protected]> Signed-off-by: Phillip Wood <[email protected]>
1 parent ed15518 commit c5dbfd4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

builtin/submodule--helper.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "advice.h"
3131
#include "branch.h"
3232
#include "list-objects-filter-options.h"
33+
#include <signal.h>
3334

3435
#define OPT_QUIET (1 << 0)
3536
#define OPT_CACHED (1 << 1)
@@ -695,6 +696,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
695696

696697
if (flags & OPT_RECURSIVE) {
697698
struct child_process cpr = CHILD_PROCESS_INIT;
699+
int res;
698700

699701
cpr.git_cmd = 1;
700702
cpr.dir = path;
@@ -710,7 +712,10 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
710712
if (flags & OPT_QUIET)
711713
strvec_push(&cpr.args, "--quiet");
712714

713-
if (run_command(&cpr))
715+
res = run_command(&cpr);
716+
if (res == SIGPIPE + 128)
717+
raise(SIGPIPE);
718+
else if (res)
714719
die(_("failed to recurse into submodule '%s'"), path);
715720
}
716721

t/t7422-submodule-output.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,11 @@ do
167167
'
168168
done
169169

170+
test_expect_success !MINGW 'git submodule status --recursive propagates SIGPIPE' '
171+
{ git submodule status --recursive 2>err; echo $?>status; } |
172+
grep -q X/S &&
173+
test_must_be_empty err &&
174+
test_match_signal 13 "$(cat status)"
175+
'
176+
170177
test_done

0 commit comments

Comments
 (0)