Skip to content

Commit e70a65c

Browse files
mattmccutchengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e860d96 commit e70a65c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

t/t5516-fetch-push.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,8 @@ test_expect_success 'fetch exact SHA1' '
10981098
test_must_fail git cat-file -t $the_commit &&
10991099
11001100
# 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 &&
11021103
test_must_fail git rev-parse --verify refs/heads/copy &&
11031104
11041105
# the server side can allow it to succeed

transport.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
204204
static int fetch_refs_via_pack(struct transport *transport,
205205
int nr_heads, struct ref **to_fetch)
206206
{
207+
int ret = 0;
207208
struct git_transport_data *data = transport->data;
208209
struct ref *refs;
209210
char *dest = xstrdup(transport->url);
@@ -241,19 +242,22 @@ static int fetch_refs_via_pack(struct transport *transport,
241242
&transport->pack_lockfile);
242243
close(data->fd[0]);
243244
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;
248247
data->conn = NULL;
249248
data->got_remote_heads = 0;
250249
data->options.self_contained_and_connected =
251250
args.self_contained_and_connected;
252251

252+
if (refs == NULL)
253+
ret = -1;
254+
if (report_unmatched_refs(to_fetch, nr_heads))
255+
ret = -1;
256+
253257
free_refs(refs_tmp);
254258
free_refs(refs);
255259
free(dest);
256-
return (refs ? 0 : -1);
260+
return ret;
257261
}
258262

259263
static int push_had_errors(struct ref *ref)

0 commit comments

Comments
 (0)