Merge branch 'jt/namespaced-ls-refs-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:15 +0000 (14:26 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:15 +0000 (14:26 -0800)
Fix namespace support in protocol v2.

* jt/namespaced-ls-refs-fix:
ls-refs: filter refs using namespace-stripped name

ls-refs.c
t/t5702-protocol-v2.sh
index 9c9a7c647f26249d68319786449eefd7d6de1eba..0a7dbc6442fad37fd9e2ce72866b04b134818181 100644 (file)
--- a/ls-refs.c
+++ b/ls-refs.c
@@ -44,7 +44,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
        if (ref_is_hidden(refname_nons, refname))
                return 0;
 
-       if (!ref_match(&data->prefixes, refname))
+       if (!ref_match(&data->prefixes, refname_nons))
                return 0;
 
        strbuf_addf(&refline, "%s %s", oid_to_hex(oid), refname_nons);
index 7ca1aab6b58bf405cfaf585ddd06d8b02393fe24..db4ae09f2f81ff77b9c29b99c21363e66c81f222 100755 (executable)
@@ -561,6 +561,27 @@ test_expect_success 'fetch with http:// using protocol v2' '
        grep "git< version 2" log
 '
 
+test_expect_success 'fetch from namespaced repo respects namespaces' '
+       test_when_finished "rm -f log" &&
+
+       git init "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" &&
+       test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" one &&
+       test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" two &&
+       git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" \
+               update-ref refs/namespaces/ns/refs/heads/master one &&
+
+       GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
+               fetch "$HTTPD_URL/smart_namespace/nsrepo" \
+               refs/heads/master:refs/heads/theirs &&
+
+       # Server responded using protocol v2
+       grep "fetch< version 2" log &&
+
+       git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" rev-parse one >expect &&
+       git -C http_child rev-parse theirs >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'push with http:// and a config of v2 does not request v2' '
        test_when_finished "rm -f log" &&
        # Till v2 for push is designed, make sure that if a client has