fetch_refs_via_pack: call report_unmatched_refs
"git fetch" currently doesn't bother to check that it got all refs it sought, because the common case of requesting a nonexistent ref triggers a die() in get_fetch_map. However, there's at least one case that slipped through: "git fetch REMOTE SHA1" if the server doesn't allow requests for unadvertised objects. Make fetch_refs_via_pack (which is on the "git fetch" code path) call report_unmatched_refs so that we at least get an error message in that case. Signed-off-by: Matt McCutchen <matt@mattmccutchen.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matt McCutchen committed
Feb 22, 2017 at 11:02 UTC
e70a65c5d89e4543491082d4b361398fd87433db
2 files changed
+11
-6
t/t5516-fetch-push.sh
+2
-1
@@ -1098,7 +1098,8 @@ test_expect_success 'fetch exact SHA1' '
1098
test_must_fail git cat-file -t $the_commit &&
1099
1100
# fetching the hidden object should fail by default
1101
- test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy &&
1101
+ test_must_fail git fetch -v ../testrepo $the_commit:refs/heads/copy 2>err &&
1102
+ test_i18ngrep "no such remote ref" err &&
1103
test_must_fail git rev-parse --verify refs/heads/copy &&
1104
1105
# the server side can allow it to succeed
transport.c
+9
-5
@@ -204,6 +204,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
204
static int fetch_refs_via_pack(struct transport *transport,
205
int nr_heads, struct ref **to_fetch)
206
{
207
+ int ret = 0;
208
struct git_transport_data *data = transport->data;
209
struct ref *refs;
210
char *dest = xstrdup(transport->url);
@@ -241,19 +242,22 @@ static int fetch_refs_via_pack(struct transport *transport,
242
&transport->pack_lockfile);
243
close(data->fd[0]);
244
close(data->fd[1]);
244
- if (finish_connect(data->conn)) {
245
- free_refs(refs);
246
- refs = NULL;
247
- }
245
+ if (finish_connect(data->conn))
246
+ ret = -1;
247
data->conn = NULL;
248
data->got_remote_heads = 0;
249
data->options.self_contained_and_connected =
250
args.self_contained_and_connected;
251
252
+ if (refs == NULL)
253
+ ret = -1;
254
+ if (report_unmatched_refs(to_fetch, nr_heads))
255
+ ret = -1;
256
+
257
free_refs(refs_tmp);
258
free_refs(refs);
259
free(dest);
256
- return (refs ? 0 : -1);
260
+ return ret;
261
}
262
263
static int push_had_errors(struct ref *ref)