diff --git a/crates/radicle/src/git/canonical/rules.rs b/crates/radicle/src/git/canonical/rules.rs index ca9353b0..e99a6efd 100644 --- a/crates/radicle/src/git/canonical/rules.rs +++ b/crates/radicle/src/git/canonical/rules.rs @@ -81,6 +81,13 @@ impl<'a> TryFrom> for Pattern { } impl Pattern { + /// Construct a [`Pattern`] that matches a branch exactly. + /// + /// The resulting [`Pattern`] will match `refs/heads/`. + 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 diff --git a/crates/radicle/src/identity/doc.rs b/crates/radicle/src/identity/doc.rs index 22b304e3..74fca7ed 100644 --- a/crates/radicle/src/identity/doc.rs +++ b/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,