Skip to content

Match globs with :(glob) pathspecs: **/*.md now includes root files - #28

Merged
ndbroadbent merged 3 commits into
mainfrom
fix/glob-pathspec
Dec 4, 2026
Merged

ndbroadbent merged 3 commits into
mainfrom
fix/glob-pathspec

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

A false-skip fix. Globs were passed to git ls-files as plain pathspecs, and retried with :(glob) only when nothing matched. Without glob magic, **/ can't match zero directories:

Glob Before (plain pathspec) After (gitignore rules)
**/*.md d/a.md d/sub/b.md, not README.md README.md d/a.md d/sub/b.md
d/**/*.md d/sub/b.md, not d/a.md d/a.md d/sub/b.md
*.md every .md in every directory every .md in every directory (unchanged)
/*.md nothing README.md only
d/*.md d/a.md d/sub/b.md d/a.md only

So a commit that only changed README.md skipped a job whose inputs were **/*.md. Two live examples: bootstrap's cspell job (found while converting its CI for a case study), and cigen's own .cigen/**/*.yml, which missed .cigen/config.yml.

The fix: src/pathspec.rs is now the one place globs are matched, for job and group inputs, module inputs and cigen hash --pattern, with gitignore's rules, which err towards including: a glob with no / matches at any depth (*.md is **/*.md), a leading / or ./ anchors it to the root, and a glob with a / elsewhere is matched from the root with * staying in one directory. Each pattern becomes two root-relative globs, <glob> and <glob>/**, so a glob that matches a directory brings every file under it. In git they go to git ls-files -z as :(glob) pathspecs (tracked files only, LC_ALL=C so "not a git repository" is recognised). Outside git the same two globs are applied to the files on disk with globset (literal_separator). globwalk is removed.

A file name with no / now matches in every directory: Cargo.lock includes tools/Cargo.lock. That's over-inclusive, the safe direction. The rust module's root inputs (Cargo.lock when path: .) are affected the same way; anchoring them with / is a possible follow-up.

I checked for the same bug class elsewhere. Derived inputs list local actions with walkdir and use no globs, no provider emits hashFiles, and mockci's globset only simulates GitHub's own filters.

Hashes change. Many globs now match different files, so most job hashes change once, and every job with inputs runs again on its first push after upgrading. That's the safe direction. STATUS records it as known problem 20 (resolved). The inputs docs have a table of the rules.

Tests: tests/glob_inputs.rs checks each rule twice, in a git repository and in a plain directory, and requires the two to agree. Each case changes one file and checks whether the job's hash changes: *.md at depth, /*.md and ./*.md at the root only, docs/*.md not matching docs/guide/b.md, and a bare directory name at any depth. A unit test pins how each pattern is rewritten. The **/ tests fail on the old matching; hash --pattern already matched root files through globwalk, and that test now pins it to the same rules as inputs.

task ci passes with no warnings.

Note for #14 (cigen explain): src/hashing/files.rs carries a copy of the old list_files. On rebase it should call cigen::pathspec::list_files instead.

Container jobs (second commit). CI's container jobs (rust:latest) failed at the hash step: git ls-files refused with "detected dubious ownership", because the checkout belongs to another uid. Every user with a container job would hit it. src/git.rs now builds every git command cigen runs with -c safe.directory=<repository root>. git accepts that on the command line (checked with git 2.47.3 in rust:latest) but matches it against the repository's top level, not the directory git runs in, so cigen finds the nearest directory holding .git; the project root alone fails when the project is a subdirectory.

The old matching hid this: when git ls-files failed for any reason it silently globbed the files on disk, untracked files and build output included, so container jobs hashed a different file list. STATUS records that as known problem 21 (resolved). Any other git error now fails with git's message.

tests/git_ownership.rs reproduces the failure with git's own GIT_TEST_ASSUME_DIFFERENT_OWNER (honoured by 2.47 and 2.56), at the repository root and with the project in a subdirectory, and checks the hash matches the owner's. Both tests fail without the fix with the same error CI showed. A unit test pins the -c safe.directory argument.

ndbroadbent added a commit that referenced this pull request Dec 4, 2026
Globs were passed to git ls-files as plain pathspecs and retried with
:(glob) only when nothing matched. Without glob magic, **/ can't match zero
directories, so **/*.md missed README.md and docs/**/*.md missed docs/a.md
whenever a deeper file matched: a change to those files skipped the job. Plain
pathspecs also let * cross directories, so *.md matched every directory.

src/pathspec.rs now matches every glob cigen hashes (inputs, groups, module
inputs, hash --pattern) one way: git ls-files -z with :(glob), or, outside
git, the same rules over the files on disk with globset. globwalk is gone.

This changes which files many globs match, so most job hashes change once:
every job with inputs runs again on its first push after upgrading. Found
converting a real project's CI. tests/glob_inputs.rs checks each rule inside
and outside git, and fails on the old matching.
…he root only

A glob with no slash matches at any depth and a leading / or ./ anchors it, as in gitignore,
so the rules err towards including. git gets two :(glob) pathspecs, the glob and <glob>/**, so
a glob that matches a directory brings every file under it; the disk fallback uses the same two
globs. Tests cover *.md at depth, /*.md at the root only and docs/*.md missing docs/sub/x.md.
…rks in container jobs

In a CI container job the checkout is owned by another user, and git refuses with
"detected dubious ownership". git accepts safe.directory on the command line and matches
it against the repository's top level, so src/git.rs finds the nearest directory holding
.git and every git command cigen runs goes through it.

The old matching hid this: when git ls-files failed it silently globbed the files on disk.
STATUS records that as known problem 21 (resolved). tests/git_ownership.rs reproduces the
failure with git's GIT_TEST_ASSUME_DIFFERENT_OWNER, at the root and in a subdirectory.
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.

1 participant