Skip to content

Treat gitignore segments of three or more asterisks as a globstar - #167

Merged
cpburnz merged 1 commit into
cpburnz:masterfrom
manoj-1407:fix-star-runs
Oct 23, 2026
Merged

cpburnz merged 1 commit into
cpburnz:masterfrom
manoj-1407:fix-star-runs

Conversation

@manoj-1407

Copy link
Copy Markdown
Contributor

Git's wildmatch treats a run of three or more asterisks that makes up a whole path segment the same as **. pathspec treats it as a single *, so patterns like ***/x don't match what git matches.

Example, checked against git check-ignore:

pattern  ***/x
git:       x, a/x, a/b/x   ignored
pathspec:  only x          (a/x and a/b/x not matched)

Same for a/***, a/***/b and ****/x.

This collapses such segments to ** before the pattern is translated, in both GitIgnoreBasicPattern and GitIgnoreSpecPattern, via a small _collapse_star_runs helper in gitignore/base.py. A run of asterisks inside a segment with other characters (a***b) is unchanged and still acts like *.

Added tests/test_10_gitignore_star_runs.py, which covers both pattern classes and GitIgnoreSpec.from_lines. Full suite passes (290 tests). I also added a line under Bug fixes in CHANGES_1.in.rst.

I searched the open issues and PRs for ***, "asterisk" and "globstar" and didn't find one for this case. #45 and #164 look related but are about other globstar cases.

Git's wildmatch treats a run of asterisks that spans a whole path segment as a single globstar, so '***/x' behaves like '**/x'. Those segments were handled as a single '*', so 'x' and 'a/b/x' were not matched by '***/x'. Collapse such segments to '**' in both pattern classes.
@cpburnz

cpburnz commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Thanks for finding and fixing this!

@cpburnz
cpburnz merged commit a858bb5 into cpburnz:master Oct 23, 2026
5 of 7 checks passed
@manoj-1407
manoj-1407 deleted the fix-star-runs branch October 23, 2026 11:22
cpburnz added a commit that referenced this pull request Oct 23, 2026
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