Skip to content

Commit 6e7fac9

Browse files
peffgitster
authored andcommitted
print an error when remote helpers die during capabilities
The transport-helper code generally relies on the remote-helper to provide an informative message to the user when it encounters an error. In the rare cases where the helper does not do so, the output can be quite confusing. E.g.: $ git clone https://example.com/foo.git Cloning into 'foo'... $ echo $? 128 $ ls foo /bin/ls: cannot access foo: No such file or directory We tried to address this with 81d340d (transport-helper: report errors properly, 2013-04-10). But that makes the common case much more confusing. The remote helper protocol's method for signaling normal errors is to simply hang up. So when the helper does encounter a routine error and prints something to stderr, the extra error message is redundant and misleading. So we dropped it again in 266f1fd (transport-helper: be quiet on read errors from helpers, 2013-06-21). This puts the uncommon case right back where it started. We may be able to do a little better, though. It is common for the helper to die during a "real" command, like fetching the list of remote refs. It is not common for it to die during the initial "capabilities" negotiation, right after we start. Reporting failure here is likely to catch fundamental problems that prevent the helper from running (and reporting errors) at all. Anything after that is the responsibility of the helper itself to report. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dbecc61 commit 6e7fac9

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
@@ -321,4 +321,15 @@ test_expect_success 'fetch tag' '
321321
compare_refs local v1.0 server v1.0
322322
'
323323

324+
test_expect_success 'totally broken helper reports failure message' '
325+
write_script git-remote-broken <<-\EOF &&
326+
read cap_cmd
327+
exit 1
328+
EOF
329+
test_must_fail \
330+
env PATH="$PWD:$PATH" \
331+
git clone broken://example.com/foo.git 2>stderr &&
332+
grep aborted stderr
333+
'
334+
324335
test_done

transport-helper.c

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

86-
static void write_constant(int fd, const char *str)
86+
static int write_constant_gently(int fd, const char *str)
8787
{
8888
if (debug)
8989
fprintf(stderr, "Debug: Remote helper: -> %s", str);
9090
if (write_in_full(fd, str, strlen(str)) < 0)
91+
return -1;
92+
return 0;
93+
}
94+
95+
static void write_constant(int fd, const char *str)
96+
{
97+
if (write_constant_gently(fd, str) < 0)
9198
die_errno(_("full write to remote helper failed"));
9299
}
93100

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

164-
write_constant(helper->in, "capabilities\n");
171+
sigchain_push(SIGPIPE, SIG_IGN);
172+
if (write_constant_gently(helper->in, "capabilities\n") < 0)
173+
die("remote helper '%s' aborted session", data->name);
174+
sigchain_pop(SIGPIPE);
165175

166176
while (1) {
167177
const char *capname, *arg;
168178
int mandatory = 0;
169179
if (recvline(data, &buf))
170-
exit(128);
180+
die("remote helper '%s' aborted session", data->name);
171181

172182
if (!*buf.buf)
173183
break;

0 commit comments

Comments
 (0)