Radish alpha
r
rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt
Git libraries for Radicle
Radicle
Git
ref-format: Relax first component of namespaced
Lorenz Leutgeb committed 7 months ago
commit 24237552ec452c892f6a589b2a56c5acfec44ede
parent 786248a
2 files changed +14 -2
modified radicle-git-ext/git-ref-format/core/src/deriv.rs
@@ -267,9 +267,10 @@ impl Display for Qualified<'_> {
/// A [`Qualified`] ref under a git namespace.
///
/// A ref is namespaced if it starts with "refs/namespaces/", another path
-
/// component, and "refs/". Eg.
+
/// component, and "refs" or "HEAD". Eg.
///
///     refs/namespaces/xyz/refs/heads/main
+
///     refs/namespaces/xyz/HEAD
///
/// Note that namespaces can be nested, so the result of
/// [`Namespaced::strip_namespace`] may be convertible to a [`Namespaced`]
@@ -365,7 +366,7 @@ impl<'a> From<&'a RefStr> for Option<Namespaced<'a>> {
    fn from(rs: &'a RefStr) -> Self {
        let mut cs = rs.iter();
        match (cs.next()?, cs.next()?, cs.next()?, cs.next()?) {
-
            ("refs", "namespaces", _, "refs") => Some(Namespaced(Cow::from(rs))),
+
            ("refs", "namespaces", _, "refs" | "HEAD") => Some(Namespaced(Cow::from(rs))),

            _ => None,
        }
modified radicle-git-ext/t/src/git_ref_format/tests.rs
@@ -157,6 +157,17 @@ fn namespaced() {
}

#[test]
+
fn namespaced_head() {
+
    assert_eq!(
+
        "refs/namespaces/foo/HEAD",
+
        refname!("refs/namespaces/foo/HEAD")
+
            .to_namespaced()
+
            .unwrap()
+
            .as_str()
+
    )
+
}
+

+
#[test]
fn not_namespaced() {
    assert!(name::REFS_HEADS_MAIN.to_namespaced().is_none())
}