diff --git a/builtin/fetch.c b/builtin/fetch.c index 95fd0018b9..f142756441 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1766,6 +1766,14 @@ static int do_fetch(struct transport *transport, branch->merge[i]->src); } } + + /* + * If there are no refs specified to fetch, then we just + * fetch HEAD; mention that to narrow the advertisement. + */ + if (!transport_ls_refs_options.ref_prefixes.nr) + strvec_push(&transport_ls_refs_options.ref_prefixes, + "HEAD"); } if (tags == TAGS_SET || tags == TAGS_DEFAULT) { diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index cea8f92a3d..2f0a52a72d 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -679,6 +679,21 @@ test_expect_success 'default refspec is used to filter ref when fetching' ' grep "ref-prefix refs/tags/" log ' +test_expect_success 'set up parent for prefix tests' ' + git init prefix-parent && + git -C prefix-parent commit --allow-empty -m foo && + git -C prefix-parent branch unrelated-branch +' + +test_expect_success 'empty refspec filters refs when fetching' ' + git init configless-child && + + test_when_finished "rm -f log" && + GIT_TRACE_PACKET="$(pwd)/log" \ + git -C configless-child fetch ../prefix-parent && + test_grep ! unrelated-branch log +' + test_expect_success 'fetch supports various ways of have lines' ' rm -rf server client trace && git init server &&