Skip to content

Commit 81d340d

Browse files
felipecgitster
authored andcommitted
transport-helper: report errors properly
If a push fails because the remote-helper died (with fast-export), the user may not see any error message. We do correctly die with a failed exit code, as we notice that the helper has died while reading back the ref status from the helper. However, we don't print any message. This is OK if the helper itself printed a useful error message, but we cannot count on that; let's let the user know that the helper failed. In the long run, it may make more sense to propagate the error back up to push, so that it can present the usual status table and give a nicer message. But this is a much simpler fix that can help immediately. While we're adding tests, let's also confirm that the remote-helper dying is also detected when importing refs. We currently do so robustly when the helper uses the "done" feature (and that is what we test). We cannot do so reliably when the helper does not use the "done" feature, but it is not even worth testing; the right solution is for the helper to start using "done". Suggested-by: Jeff King <[email protected]> Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Jeff King <[email protected]> Acked-by: Sverre Rabbelier <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 52a3e01 commit 81d340d

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

git-remote-testgit

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,31 @@ do
6161
echo "feature import-marks=$gitmarks"
6262
echo "feature export-marks=$gitmarks"
6363
fi
64+
65+
if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
66+
then
67+
echo "feature done"
68+
exit 1
69+
fi
70+
6471
echo "feature done"
6572
git fast-export "${testgitmarks_args[@]}" $refs |
6673
sed -e "s#refs/heads/#${prefix}/heads/#g"
6774
echo "done"
6875
;;
6976
export)
77+
if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
78+
then
79+
# consume input so fast-export doesn't get SIGPIPE;
80+
# git would also notice that case, but we want
81+
# to make sure we are exercising the later
82+
# error checks
83+
while read line; do
84+
test "done" = "$line" && break
85+
done
86+
exit 1
87+
fi
88+
7089
before=$(git for-each-ref --format='%(refname) %(objectname)')
7190

7291
git fast-import "${testgitmarks_args[@]}" --quiet

t/t5801-remote-helpers.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,24 @@ test_expect_success 'push ref with existing object' '
166166
compare_refs local dup server dup
167167
'
168168

169+
test_expect_success 'proper failure checks for fetching' '
170+
(GIT_REMOTE_TESTGIT_FAILURE=1 &&
171+
export GIT_REMOTE_TESTGIT_FAILURE &&
172+
cd local &&
173+
test_must_fail git fetch 2> error &&
174+
cat error &&
175+
grep -q "Error while running fast-import" error
176+
)
177+
'
178+
179+
test_expect_success 'proper failure checks for pushing' '
180+
(GIT_REMOTE_TESTGIT_FAILURE=1 &&
181+
export GIT_REMOTE_TESTGIT_FAILURE &&
182+
cd local &&
183+
test_must_fail git push --all 2> error &&
184+
cat error &&
185+
grep -q "Reading from remote helper failed" error
186+
)
187+
'
188+
169189
test_done

transport-helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int recvline_fh(FILE *helper, struct strbuf *buffer)
5454
if (strbuf_getline(buffer, helper, '\n') == EOF) {
5555
if (debug)
5656
fprintf(stderr, "Debug: Remote helper quit.\n");
57-
exit(128);
57+
die("Reading from remote helper failed");
5858
}
5959

6060
if (debug)

0 commit comments

Comments
 (0)