Skip to content

Commit 014ade7

Browse files
peffgitster
authored andcommitted
upload-pack: send ERR packet for non-tip objects
Commit bdb31ea (upload-pack: report "not our ref" to client, 2017-02-23) catches the case where a client asks for an object we don't have, and issues a message that the client can show to the user (in addition to dying and writing to stderr). There's a similar case (with the same message) when the client asks for an object which we _do_ have, but which isn't a ref tip (or isn't reachable, when uploadpack.allowReachableSHA1InWant is true). Let's give that one the same treatment, for the same reason (namely that it's more informative to the client than just hanging up, since they won't see our stderr over some protocols). There are two tests here. We cover it most directly in t5530 by invoking upload-pack, which matches the existing "not our ref" test. But a more end-to-end check is that "git fetch" actually shows the message to the client. We're already checking in t5516 that this case fails, so we can just check stderr there, too. Note that even after we started ignoring SIGPIPE in 8bf4bec, this could in theory still be racy as described in that commit (because we die() on write failures before pumping the connection for any ERR packets). In practice this should be OK for this case. The server will not actually check reachability until it has received our whole group of "want" lines. And since we have no objects in the repository, we won't send any "have" lines, meaning we're always waiting to read the server response. Note also that this case cannot happen in the v2 protocol, since it allows any available object to be requested. However, we don't have to take any steps to protect against the upcoming GIT_TEST_PROTOCOL_VERSION in our tests: - the tests in t5516 would already need to be skipped under v2, and that is covered by ab0c5f5 (tests: always test fetch of unreachable with v0, 2019-02-25) - the tests in t5530 invoke upload-pack directly, which will continue to default to v0. Eventually we may have a test setting which uses v2 even for bare upload-pack calls, but we can't override it here until we know what the setting looks like. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6963a4e commit 014ade7

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

t/t5516-fetch-push.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,8 @@ do
12401240
test_must_fail git cat-file commit $SHA1_2 &&
12411241
git fetch ../testrepo/.git $SHA1_2 &&
12421242
git cat-file commit $SHA1_2 &&
1243-
test_must_fail git fetch ../testrepo/.git $SHA1_3
1243+
test_must_fail git fetch ../testrepo/.git $SHA1_3 2>err &&
1244+
test_i18ngrep "remote error:.*not our ref" err
12441245
)
12451246
'
12461247
done

t/t5530-upload-pack-error.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test_expect_success 'upload-pack fails due to error in rev-list' '
5757
grep "bad tree object" output.err
5858
'
5959

60-
test_expect_success 'upload-pack error message when bad ref requested' '
60+
test_expect_success 'upload-pack fails due to bad want (no object)' '
6161
6262
printf "0045want %s multi_ack_detailed\n00000009done\n0000" \
6363
"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" >input &&
@@ -67,6 +67,17 @@ test_expect_success 'upload-pack error message when bad ref requested' '
6767
! grep multi_ack_detailed output.err
6868
'
6969

70+
test_expect_success 'upload-pack fails due to bad want (not tip)' '
71+
72+
oid=$(echo an object we have | git hash-object -w --stdin) &&
73+
printf "0045want %s multi_ack_detailed\n00000009done\n0000" \
74+
"$oid" >input &&
75+
test_must_fail git upload-pack . <input >output 2>output.err &&
76+
grep "not our ref" output.err &&
77+
grep "ERR" output &&
78+
! grep multi_ack_detailed output.err
79+
'
80+
7081
test_expect_success 'upload-pack fails due to error in pack-objects enumeration' '
7182
7283
printf "0032want %s\n00000009done\n0000" \

upload-pack.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ static int has_unreachable(struct object_array *src)
592592
return 1;
593593
}
594594

595-
static void check_non_tip(struct object_array *want_obj)
595+
static void check_non_tip(struct object_array *want_obj,
596+
struct packet_writer *writer)
596597
{
597598
int i;
598599

@@ -611,9 +612,13 @@ static void check_non_tip(struct object_array *want_obj)
611612
/* Pick one of them (we know there at least is one) */
612613
for (i = 0; i < want_obj->nr; i++) {
613614
struct object *o = want_obj->objects[i].item;
614-
if (!is_our_ref(o))
615+
if (!is_our_ref(o)) {
616+
packet_writer_error(writer,
617+
"upload-pack: not our ref %s",
618+
oid_to_hex(&o->oid));
615619
die("git upload-pack: not our ref %s",
616620
oid_to_hex(&o->oid));
621+
}
617622
}
618623
}
619624

@@ -936,7 +941,7 @@ static void receive_needs(struct packet_reader *reader, struct object_array *wan
936941
* by another process that handled the initial request.
937942
*/
938943
if (has_non_tip)
939-
check_non_tip(want_obj);
944+
check_non_tip(want_obj, &writer);
940945

941946
if (!use_sideband && daemon_mode)
942947
no_progress = 1;

0 commit comments

Comments
 (0)