Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
radicle/id: always return default branch as cref
Open 2color opened 1 month ago

This fixes a bug where the canonical_refs method wouldn’t return the default branch if the repo had no canonical refs defined in the paylaod key of the id document

1 file changed +10 -12 e9245b63 5f358c1b
modified crates/radicle/src/identity/doc.rs
@@ -921,21 +921,19 @@ impl crefs::GetCanonicalRefs for Doc {
    type Error = CanonicalRefsError;

    fn canonical_refs(&self) -> Result<Option<CanonicalRefs>, Self::Error> {
-
        self.raw_canonical_refs().and_then(|raw| {
-
            raw.map(|raw| {
+
        let mut crefs = self
+
            .raw_canonical_refs()?
+
            .map(|raw| {
                raw.try_into_canonical_refs(&mut || self.delegates.clone())
                    .map_err(CanonicalRefsError::from)
-
                    .and_then(|mut crefs| {
-
                        self.default_branch_rule()
-
                            .map_err(CanonicalRefsError::from)
-
                            .map(|rule| {
-
                                crefs.extend([rule]);
-
                                crefs
-
                            })
-
                    })
            })
-
            .transpose()
-
        })
+
            .transpose()?
+
            .unwrap_or_else(|| std::iter::empty().collect());
+

+
        let rule = self.default_branch_rule()?;
+
        crefs.extend([rule]);
+

+
        Ok(Some(crefs))
    }

    fn raw_canonical_refs(&self) -> Result<Option<RawCanonicalRefs>, Self::Error> {