Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

Addresses issue #2237. One-sided refspecs (no destination) can now use complex glob patterns like refs/*/foo/* or refs/*/*/branch without requiring valid ref name structure. Two-sided refspecs retain existing validation.

Changes

  • Parsing logic (gix-refspec/src/parse.rs):

    • Modified validated() to accept is_one_sided parameter
    • Skip ref name validation for globbed one-sided refspecs
    • Allow multiple asterisks in one-sided refspecs
    • Disable pattern balance check for one-sided refspecs
  • Matching logic (gix-refspec/src/match_group/util.rs):

    • Implemented Needle::Pattern variant for full glob matching using gix_glob::wildmatch
    • Added is_complex_pattern() helper to intelligently choose between simple and complex pattern matching
    • Simple single-asterisk patterns (e.g., refs/heads/*) use efficient Needle::Glob
    • Complex patterns (multiple *, [...], ?, \) use Needle::Pattern with full wildmatch support
    • Added pattern handling in to_bstr_replace() method
  • Tests:

    • Added tests for complex glob pattern parsing (refs/*/foo/*, refs/*/*/bar)
    • Added tests verifying two-sided refspecs still reject multiple asterisks
    • Updated baseline test to accommodate intentional behavior change
    • Extracted is_one_sided_glob_pattern() helper for readability

Example

// Now allowed - one-sided with complex glob
let spec = gix_refspec::parse("refs/*/foo/*".into(), Operation::Fetch)?;

// Still rejected - two-sided with multiple asterisks
let spec = gix_refspec::parse("refs/*/foo/*:refs/remotes/*".into(), Operation::Fetch)?;
// Error: PatternUnsupported

// Complex patterns with character classes work
let spec = gix_refspec::parse("refs/tags/v[0-9]*".into(), Operation::Fetch)?;
// Matches: refs/tags/v1.0, refs/tags/v2.5, etc.

Pattern Matching

The implementation provides full glob support while maintaining performance:

  • Simple patterns (refs/heads/*): Use fast substring matching via Needle::Glob
  • Complex patterns (refs/*/foo/*, refs/tags/v[0-9]*): Use full wildmatch via Needle::Pattern

Complex patterns are automatically detected when they contain:

  • Multiple asterisks
  • Character classes [...]
  • Question marks ?
  • Backslashes \ for escaping
Original prompt

#2237 When parsing refspecs in gix-refspec/src/parse.rs, and the glob looks like a more complex pattern than refs/heads/*:refs/remotes/origin/*, then let the refspec not be a valid ref, allowing any glob in the process, as long as it's just a one-sided refspec.
Be sure to have tests for pattern matching, which should work with this kind of globbed, single-sided refspec.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Update refspec parsing to support complex one-sided patterns Allow complex glob patterns in one-sided refspecs Oct 27, 2025
Copilot AI requested a review from Byron October 27, 2025 04:12
Copilot finished work on behalf of Byron October 27, 2025 04:12
Copilot AI and others added 2 commits November 2, 2025 15:06
- Modified validated() function to skip strict ref name validation for one-sided refspecs with globs
- Allow multiple asterisks in one-sided refspecs (no destination)
- Two-sided refspecs still require balanced patterns and reject multiple asterisks
- Added tests for complex glob pattern parsing and simple glob matching
- Updated existing tests to reflect the new behavior

Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
@Byron Byron force-pushed the copilot/update-refspec-parsing-logic branch from d95f372 to bb84248 Compare November 2, 2025 14:11
@Byron
Copy link
Member

Byron commented Nov 2, 2025

@copilot Add the implementation for Needle::Pattern so full globs are supported in one-sided refspecs.

- Added Pattern matching case in Needle::matches() using gix_glob::wildmatch
- Added Pattern handling in to_bstr_replace() method
- Added is_complex_pattern() helper to detect patterns requiring wildmatch
- Only use Needle::Pattern for complex patterns (multiple asterisks or [, ], ?, \)
- Simple single-asterisk globs continue using efficient Needle::Glob
- Fixed test pattern from v[0.9]* to v[0-9]* to match v1.0 correctly

Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 2, 2025

@copilot Add the implementation for Needle::Pattern so full globs are supported in one-sided refspecs.

Implemented Needle::Pattern support in commit d6835f2. The implementation uses gix_glob::wildmatch for complex patterns while keeping the efficient Needle::Glob for simple single-asterisk patterns. Complex patterns (multiple *, [...], ?, \) now work correctly with one-sided refspecs.

Copilot AI changed the title Allow complex glob patterns in one-sided refspecs Allow complex glob patterns in one-sided refspecs with full wildmatch support Nov 2, 2025
Copilot finished work on behalf of Byron November 2, 2025 14:56
@Byron Byron force-pushed the copilot/update-refspec-parsing-logic branch from ff7b748 to ba2301f Compare November 4, 2025 05:21
@Byron Byron marked this pull request as ready for review November 4, 2025 05:21
@Byron Byron enabled auto-merge November 4, 2025 05:21
@Byron Byron merged commit c2c1a61 into main Nov 4, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants