Merge branch 'jt/tag-following-with-proto-v2-fix'

The wire-protocol v2 relies on the client to send "ref prefixes" to
limit the bandwidth spent on the initial ref advertisement.  "git
fetch $remote branch:branch" that asks tags that point into the
history leading to the "branch" automatically followed sent to
narrow prefix and broke the tag following, which has been fixed.

* jt/tag-following-with-proto-v2-fix:
  fetch: send "refs/tags/" prefix upon CLI refspecs
  t5702: test fetch with multiple refspecs at a time
This commit is contained in:
Junio C Hamano 2018-08-15 15:08:25 -07:00
commit d6628c99fa
2 changed files with 69 additions and 4 deletions

View File

@ -1192,7 +1192,7 @@ static int do_fetch(struct transport *transport,
refspec_ref_prefixes(&transport->remote->fetch, &ref_prefixes);
if (ref_prefixes.argc &&
(tags == TAGS_SET || (tags == TAGS_DEFAULT && !rs->nr))) {
(tags == TAGS_SET || (tags == TAGS_DEFAULT))) {
argv_array_push(&ref_prefixes, "refs/tags/");
}

View File

@ -209,6 +209,7 @@ test_expect_success 'ref advertisment is filtered during fetch using protocol v2
test_when_finished "rm -f log" &&
test_commit -C file_parent three &&
git -C file_parent branch unwanted-branch three &&
GIT_TRACE_PACKET="$(pwd)/log" git -C file_child -c protocol.version=2 \
fetch origin master &&
@ -217,9 +218,8 @@ test_expect_success 'ref advertisment is filtered during fetch using protocol v2
git -C file_parent log -1 --format=%s >expect &&
test_cmp expect actual &&
! grep "refs/tags/one" log &&
! grep "refs/tags/two" log &&
! grep "refs/tags/three" log
grep "refs/heads/master" log &&
! grep "refs/heads/unwanted-branch" log
'
test_expect_success 'server-options are sent when fetching' '
@ -364,6 +364,71 @@ test_expect_success 'default refspec is used to filter ref when fetchcing' '
grep "ref-prefix refs/tags/" log
'
test_expect_success 'fetch supports various ways of have lines' '
rm -rf server client trace &&
git init server &&
test_commit -C server dwim &&
TREE=$(git -C server rev-parse HEAD^{tree}) &&
git -C server tag exact \
$(git -C server commit-tree -m a "$TREE") &&
git -C server tag dwim-unwanted \
$(git -C server commit-tree -m b "$TREE") &&
git -C server tag exact-unwanted \
$(git -C server commit-tree -m c "$TREE") &&
git -C server tag prefix1 \
$(git -C server commit-tree -m d "$TREE") &&
git -C server tag prefix2 \
$(git -C server commit-tree -m e "$TREE") &&
git -C server tag fetch-by-sha1 \
$(git -C server commit-tree -m f "$TREE") &&
git -C server tag completely-unrelated \
$(git -C server commit-tree -m g "$TREE") &&
git init client &&
GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
fetch "file://$(pwd)/server" \
dwim \
refs/tags/exact \
refs/tags/prefix*:refs/tags/prefix* \
"$(git -C server rev-parse fetch-by-sha1)" &&
# Ensure that the appropriate prefixes are sent (using a sample)
grep "fetch> ref-prefix dwim" trace &&
grep "fetch> ref-prefix refs/heads/dwim" trace &&
grep "fetch> ref-prefix refs/tags/prefix" trace &&
# Ensure that the correct objects are returned
git -C client cat-file -e $(git -C server rev-parse dwim) &&
git -C client cat-file -e $(git -C server rev-parse exact) &&
git -C client cat-file -e $(git -C server rev-parse prefix1) &&
git -C client cat-file -e $(git -C server rev-parse prefix2) &&
git -C client cat-file -e $(git -C server rev-parse fetch-by-sha1) &&
test_must_fail git -C client cat-file -e \
$(git -C server rev-parse dwim-unwanted) &&
test_must_fail git -C client cat-file -e \
$(git -C server rev-parse exact-unwanted) &&
test_must_fail git -C client cat-file -e \
$(git -C server rev-parse completely-unrelated)
'
test_expect_success 'fetch supports include-tag and tag following' '
rm -rf server client trace &&
git init server &&
test_commit -C server to_fetch &&
git -C server tag -a annotated_tag -m message &&
git init client &&
GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \
fetch "$(pwd)/server" to_fetch:to_fetch &&
grep "fetch> ref-prefix to_fetch" trace &&
grep "fetch> ref-prefix refs/tags/" trace &&
grep "fetch> include-tag" trace &&
git -C client cat-file -e $(git -C client rev-parse annotated_tag)
'
# Test protocol v2 with 'http://' transport
#
. "$TEST_DIRECTORY"/lib-httpd.sh