/** A branch glob: `*` matches within one path segment, `**` matches across segments. Everything else is literal. */ export class BranchPattern { readonly source: string; readonly #regex: RegExp; constructor(source: string) { this.source = source; let body = ""; for (let i = 0; i < source.length; i++) { const char = source[i]; if (char === "*" && source[i + 1] === "*") { body += ".*"; i++; } else if (char === "*") body += "[^/]*"; else body += char.replace(/[.+?^${}()|[\]\\]/g, "\\$&"); } this.#regex = new RegExp(`^${body}$`); } matches(branch: string): boolean { return this.#regex.test(branch); } } export function matchesAny(patterns: readonly string[], branch: string): boolean { return patterns.length === 0 || patterns.some((pattern) => new BranchPattern(pattern).matches(branch)); }