Skip to content

Commit a4f062b

Browse files
committed
Merge branch 'jk/diag-unexpected-remote-helper-death'
When a remote-helper dies before Git writes to it, SIGPIPE killed Git silently. We now explain the situation a bit better to the end user in our error message. * jk/diag-unexpected-remote-helper-death: print an error when remote helpers die during capabilities
2 parents 31a1742 + 6e7fac9 commit a4f062b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

t/t5801-remote-helpers.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,15 @@ test_expect_success 'fetch tag' '
344344
compare_refs local v1.0 server v1.0
345345
'
346346

347+
test_expect_success 'totally broken helper reports failure message' '
348+
write_script git-remote-broken <<-\EOF &&
349+
read cap_cmd
350+
exit 1
351+
EOF
352+
test_must_fail \
353+
env PATH="$PWD:$PATH" \
354+
git clone broken://example.com/foo.git 2>stderr &&
355+
grep aborted stderr
356+
'
357+
347358
test_done

transport-helper.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,18 @@ static int recvline(struct helper_data *helper, struct strbuf *buffer)
8989
return recvline_fh(helper->out, buffer);
9090
}
9191

92-
static void write_constant(int fd, const char *str)
92+
static int write_constant_gently(int fd, const char *str)
9393
{
9494
if (debug)
9595
fprintf(stderr, "Debug: Remote helper: -> %s", str);
9696
if (write_in_full(fd, str, strlen(str)) < 0)
97+
return -1;
98+
return 0;
99+
}
100+
101+
static void write_constant(int fd, const char *str)
102+
{
103+
if (write_constant_gently(fd, str) < 0)
97104
die_errno(_("full write to remote helper failed"));
98105
}
99106

@@ -168,13 +175,16 @@ static struct child_process *get_helper(struct transport *transport)
168175
die_errno(_("can't dup helper output fd"));
169176
data->out = xfdopen(duped, "r");
170177

171-
write_constant(helper->in, "capabilities\n");
178+
sigchain_push(SIGPIPE, SIG_IGN);
179+
if (write_constant_gently(helper->in, "capabilities\n") < 0)
180+
die("remote helper '%s' aborted session", data->name);
181+
sigchain_pop(SIGPIPE);
172182

173183
while (1) {
174184
const char *capname, *arg;
175185
int mandatory = 0;
176186
if (recvline(data, &buf))
177-
exit(128);
187+
die("remote helper '%s' aborted session", data->name);
178188

179189
if (!*buf.buf)
180190
break;

0 commit comments

Comments
 (0)