Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle/identity: Return default branch as cref
✗ CI failure Daniel Norman committed 2 months ago
commit c683a1df9aa7b34327483380498d700b06111e77
parent e9245b630d728672d2b3d6ff9265fa4f1a86f13a
1 failed 1 pending (2 total) View logs
3 files changed +25 -13
modified crates/radicle/src/identity/crefs.rs
@@ -77,7 +77,7 @@ impl RawCanonicalRefs {
///
/// [`CanonicalRefs`] can be converted into a [`Payload`] using its [`From`]
/// implementation.
-
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
+
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CanonicalRefs {
    rules: Rules,
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_default();
+

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

+
        Ok(Some(crefs))
    }

    fn raw_canonical_refs(&self) -> Result<Option<RawCanonicalRefs>, Self::Error> {
modified crates/radicle/src/identity/doc/update.rs
@@ -372,4 +372,18 @@ mod test {
            "Default branch rule is missing!"
        );
    }
+

+
    #[test]
+
    fn default_branch_rule_exists_without_payload() {
+
        let raw = arbitrary::gen::<RawDoc>(1);
+
        let branch = git::fmt::Qualified::from(git::fmt::lit::refs_heads(
+
            raw.project().unwrap().default_branch(),
+
        ));
+
        let verified = super::verify(raw).unwrap();
+
        let crefs = verified.canonical_refs().unwrap().unwrap();
+
        assert!(
+
            crefs.rules().matches(&branch).next().is_some(),
+
            "Default branch rule is missing!"
+
        );
+
    }
}