Skip to content

fix: expand attribute macros only when set#2641

Merged
Sebastian Thiel (Byron) merged 2 commits into
mainfrom
fix-2639
Jun 16, 2026
Merged

fix: expand attribute macros only when set#2641
Sebastian Thiel (Byron) merged 2 commits into
mainfrom
fix-2639

Conversation

@Byron

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

Copy link
Copy Markdown
Member

Tasks


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

Summary

Fixes #2639.

gix-attributes previously expanded a macro whenever a matching rule referenced the macro name, even when the matched assignment unset it, reset it to unspecified, or assigned a value. This now expands macro attributes only when the matched macro state is exactly Set.

Git Baseline

Git gates macro expansion in attr.c::fill_one on item->macro && item->value == ATTR__TRUE. I checked this in the local git.git reference checkout at 7760f83b59.

Validation

  • cargo test -p gix-attributes macro_attributes_expand_only_when_macro_is_set
  • cargo test -p gix-attributes
  • cargo fmt --check
  • codex review --commit d20eff7b07d681169efb4189fedea1b3d5457754

`gix_attributes::Search` expanded macro attributes whenever a matching pattern
referenced a macro name, even if the match unset the macro, reset it to
unspecified, or assigned a value.

Match Git behavior by expanding a macro only when its matched assignment
state is exactly `Set`. This follows the reference implementation in git.git
`attr.c::fill_one`, which queues a macro only when `item->macro && item->value
== ATTR__TRUE` (checked at git.git 7760f83b59).

Co-authored-by: Sebastian Thiel <[email protected]>
@Byron
Sebastian Thiel (Byron) marked this pull request as ready for review June 16, 2026 01:33
Copilot AI review requested due to automatic review settings June 16, 2026 01:33

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

Adjusts gix-attributes macro expansion behavior to match git check-attr: macro sub-assignments are expanded only when the macro is set (not unset/unspecified/value).

Changes:

  • Gate macro expansion in Outcome::fill_attributes() on State::Set.
  • Add a new baseline fixture (macro-expansion) covering Set, Unset, Unspecified, and Value macro states.
  • Add a regression test asserting parity with git check-attr -a for the new fixture.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
gix-attributes/src/search/outcome.rs Restricts macro expansion to State::Set to match git’s behavior.
gix-attributes/tests/search/mod.rs Adds a regression test comparing results against a git-generated baseline.
gix-attributes/tests/fixtures/make_attributes_baseline.sh Adds a new fixture repository and baseline generation for macro state cases.

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

Comment thread gix-attributes/tests/fixtures/make_attributes_baseline.sh
@Byron
Sebastian Thiel (Byron) merged commit d8b64fa into main Jun 16, 2026
32 checks passed
@Byron
Sebastian Thiel (Byron) deleted the fix-2639 branch June 16, 2026 02:14
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.

gix-attributes: macros expand even when the matching rule unsets them, diverging from git check-attr

3 participants