Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
radicle/crefs/rules: Exact patterns for branches
Lorenz Leutgeb committed 22 days ago
commit e822623dc1018390697d0a2d8c41ac03362d5c68
parent bfb2858
2 files changed +8 -3
modified crates/radicle/src/git/canonical/rules.rs
@@ -81,6 +81,13 @@ impl<'a> TryFrom<Qualified<'a>> for Pattern {
}

impl Pattern {
+
    /// Construct a [`Pattern`] that matches a branch exactly.
+
    ///
+
    /// The resulting [`Pattern`] will match `refs/heads/<name>`.
+
    pub fn refs_heads_exact(name: &git::fmt::RefStr) -> Self {
+
        Self(QualifiedPattern::from(git::refs::branch(name)))
+
    }
+

    /// Check if the `refname` matches the rule's `refspec`.
    pub fn matches(&self, refname: &Qualified) -> bool {
        // N.b. Git's refspecs do not quite match with glob-star semantics. A
modified crates/radicle/src/identity/doc.rs
@@ -76,8 +76,6 @@ impl DocError {

#[derive(Debug, Error)]
pub enum DefaultBranchRuleError {
-
    #[error("could not create rule due to the reference name being invalid: {0}")]
-
    Pattern(#[from] rules::PatternError),
    #[error("could not load `xyz.radicle.project` to get default branch name: {0}")]
    Payload(#[from] PayloadError),
}
@@ -746,7 +744,7 @@ impl Doc {
    pub fn default_branch_rule(
        &self,
    ) -> Result<(rules::Pattern, rules::ValidRule), DefaultBranchRuleError> {
-
        let pattern = rules::Pattern::try_from(self.default_branch()?.to_owned())?;
+
        let pattern = rules::Pattern::refs_heads_exact(self.project()?.default_branch());
        let rule = rules::Rule::new(
            rules::ResolvedDelegates::Delegates(self.delegates.clone()),
            self.threshold,