fetch/transport/ls_refs: Post-filter of references

The Git protocol specification states about `ls-refs`[^1]:

>    ref-prefix <prefix>
> When specified, only references having a prefix matching one of
> the provided prefixes are displayed. Multiple instances may be
> given, in which case references matching any prefix will be
> shown. Note that this is purely for optimization; a server MAY
> show refs not matching the prefix if it chooses, and clients
> should filter the result themselves.

The `ref-prefix` arguments should not be relied on and post-filtering
after the ls-refs invocation should also be performed.

[^1]: https://git-scm.com/docs/protocol-v2#_ls_refs
This commit is contained in:
Fintan Halpenny 2026-02-16 11:32:17 +00:00
parent 980ed56186
commit 8070f98a5b
1 changed files with 14 additions and 0 deletions

View File

@ -67,5 +67,19 @@ where
false, /* trace packetlines */ false, /* trace packetlines */
)?; )?;
// Even though we sent `ref-prefix`, listed refs must still be
// filtered, since `ref-prefix` is just an optimization hint.
// See <https://git-scm.com/docs/protocol-v2#_ls_refs>.
let refs = refs
.into_iter()
.filter(|r| {
let (refname, _, _) = r.unpack();
config
.prefixes
.iter()
.any(|prefix| refname.starts_with(prefix))
})
.collect();
Ok(refs) Ok(refs)
} }