Skip to content

Commit e2f41a0

Browse files
jonathantanmygitster
authored andcommitted
ls-refs: filter refs using namespace-stripped name
If a user fetches refs/heads/master from a repo with namespace "ns", the remote is expected to (1) not send the real refs/heads/master, and (2) send refs/namespaces/ns/refs/heads/master with the name refs/heads/master. (1) indeed happens now, but not (2) - Git only sends refs that have the user-given prefix, but it checks them against the full name of the ref (the one starting with refs/namespaces), and not the namespace-stripped one. This is demonstrated by the patch in the test. Currently, it results in "fatal: couldn't find remote ref refs/heads/master" despite both unnamespaced and namespaced master being present. With the code change, it produces the expected result. Check the ref prefixes against the namespace-stripped name. This bug was discovered through applying patches [1] that override protocol.version to 2 in repositories when running tests, allowing us to notice differences in behavior across different protocol versions. [1] https://public-inbox.org/git/cover.1547677183.git.jonathantanmy@google.com/ Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7755635 commit e2f41a0

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

ls-refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
4040
const char *refname_nons = strip_namespace(refname);
4141
struct strbuf refline = STRBUF_INIT;
4242

43-
if (!ref_match(&data->prefixes, refname))
43+
if (!ref_match(&data->prefixes, refname_nons))
4444
return 0;
4545

4646
strbuf_addf(&refline, "%s %s", oid_to_hex(oid), refname_nons);

t/t5702-protocol-v2.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,27 @@ test_expect_success 'fetch with http:// using protocol v2' '
514514
grep "git< version 2" log
515515
'
516516

517+
test_expect_success 'fetch from namespaced repo respects namespaces' '
518+
test_when_finished "rm -f log" &&
519+
520+
git init "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" &&
521+
test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" one &&
522+
test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" two &&
523+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" \
524+
update-ref refs/namespaces/ns/refs/heads/master one &&
525+
526+
GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
527+
fetch "$HTTPD_URL/smart_namespace/nsrepo" \
528+
refs/heads/master:refs/heads/theirs &&
529+
530+
# Server responded using protocol v2
531+
grep "fetch< version 2" log &&
532+
533+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/nsrepo" rev-parse one >expect &&
534+
git -C http_child rev-parse theirs >actual &&
535+
test_cmp expect actual
536+
'
537+
517538
test_expect_success 'push with http:// and a config of v2 does not request v2' '
518539
test_when_finished "rm -f log" &&
519540
# Till v2 for push is designed, make sure that if a client has

0 commit comments

Comments
 (0)