Skip to content

fix: allow negative fetch refspec patterns#2661

Merged
Sebastian Thiel (Byron) merged 1 commit into
mainfrom
negative-refspec-parsing
Jun 21, 2026
Merged

fix: allow negative fetch refspec patterns#2661
Sebastian Thiel (Byron) merged 1 commit into
mainfrom
negative-refspec-parsing

Conversation

@Byron

@Byron Sebastian Thiel (Byron) commented Jun 21, 2026

Copy link
Copy Markdown
Member

Tasks

This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.

  • refackiew

Everything below this line was generated by Codex GPT-5.

Created by Codex on behalf of Byron. Byron will review before this is ready to merge.

Summary

Fixes #2210.

Repositories can configure negative fetch refspec patterns such as ^refs/heads/*-deploy and ^refs/tags/*-deploy. Git accepts those single-asterisk negative refspec patterns, but gix-refspec rejected all negative glob patterns while parsing remote configuration.

This change allows negative refspecs with a full refs/... source and one *, while preserving rejection of empty negative specs, object IDs, destinations, partial names, unsupported multi-asterisk patterns, and invalid refname-pattern syntax. It also makes reverse fetch matching apply negative source filters to the derived source ref, so tracking-branch reverse lookup honors the same exclusions.

Git Baseline

Checked against Git's refspec.c::parse_refspec() behavior and t/t5582-fetch-negative-refspec.sh, which covers negative fetch refspecs. Added a Git-baseline fixture case with an actual deploy-deploy branch so ^refs/heads/*-deploy is tested as an exclusion, not only as a parse case.

Validation

  • GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix-refspec --test refspec
  • cargo test -p gix-refspec --test refspec
  • cargo fmt
  • cargo test -p gix-refspec
  • cargo check -p gix-refspec --no-default-features --features sha1
  • cargo fmt --check
  • codex review --commit 0efd26e2131ab0167d6181e2f4e99786c3c5a79c

@Byron
Sebastian Thiel (Byron) marked this pull request as ready for review June 21, 2026 08:26
Copilot AI review requested due to automatic review settings June 21, 2026 08:26
@Byron
Sebastian Thiel (Byron) marked this pull request as draft June 21, 2026 08:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates gix-refspec to accept Git-compatible negative fetch refspec patterns like ^refs/heads/*-deploy (full refs/... source with a single *), and ensures reverse fetch mapping honors these negative source exclusions (fixes #2210).

Changes:

  • Allow negative refspecs with a single-asterisk pattern when the source is a full refname (refs/...) (still rejecting empty negatives, object IDs, destinations, partial names, multi-asterisk patterns, and invalid refname-pattern syntax).
  • Apply negative source filters correctly during reverse fetch matching (tracking ref → derived remote ref).
  • Extend parsing/matching tests and Git-baseline fixtures to cover the new allowed negative pattern behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
gix-refspec/src/parse.rs Permits and validates negative single-asterisk refs/... patterns via validate_negative_pattern().
gix-refspec/src/match_group/mod.rs Fixes reverse fetch negation filtering to match against derived LHS (remote source) rather than RHS.
gix-refspec/tests/refspec/parse/fetch.rs Updates negative parsing expectations and adds acceptance tests for ^refs/heads/*-deploy / ^refs/tags/*-deploy.
gix-refspec/tests/refspec/parse/push.rs Aligns negative parsing expectation and adds acceptance test for ^refs/heads/*-deploy (push exclude).
gix-refspec/tests/refspec/parse/invalid.rs Adds negative-pattern invalid cases (multi-asterisk + invalid refname-pattern syntax).
gix-refspec/tests/refspec/match_group.rs Adds baseline coverage for negative patterns and a focused reverse-mapping regression test.
gix-refspec/tests/fixtures/match_baseline.sh Adds a deploy-deploy branch and baseline scenario to ensure negative *-deploy exclusions are exercised.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Issue #2210 reports that repositories with configured fetch refspecs like
`^refs/heads/*-deploy` fail to open because gix-refspec rejects all negative
glob patterns during parsing.

Git accepts negative refspecs that name a full ref or a single-asterisk refspec
pattern, while still rejecting empty negative specs, object IDs, destinations,
partial names, and patterns with multiple asterisks. The Git reference points
are `refspec.c::parse_refspec()` and `t/t5582-fetch-negative-refspec.sh`, which
exercises negative fetch patterns.

Co-authored-by: Sebastian Thiel <[email protected]>
@Byron
Sebastian Thiel (Byron) marked this pull request as ready for review June 21, 2026 11:14
@Byron
Sebastian Thiel (Byron) merged commit a507ee0 into main Jun 21, 2026
32 checks passed
@Byron
Sebastian Thiel (Byron) deleted the negative-refspec-parsing branch June 21, 2026 12:24
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.

Negative fetch refspec causes NegativeGlobPattern parsing error

3 participants