Skip to content

feat: warn when --full-path --glob pattern lacks path anchor (fixes #1650)#1999

Open
leno23 wants to merge 2 commits into
sharkdp:masterfrom
leno23:warn/full-path-glob-anchor-1650
Open

feat: warn when --full-path --glob pattern lacks path anchor (fixes #1650)#1999
leno23 wants to merge 2 commits into
sharkdp:masterfrom
leno23:warn/full-path-glob-anchor-1650

Conversation

@leno23
Copy link
Copy Markdown

@leno23 leno23 commented May 16, 2026

Summary

With --glob and --full-path, patterns match the entire absolute path (from /). Patterns like foo.txt or bar/**/foo.txt often match nothing because they do not anchor to the path root.

This adds a stderr warning when the pattern does not start with / or *, as suggested by @tavianator on #1650.

Does not change matching behavior (orthogonal to #1993).

Test plan

  • cargo test test_warn_when_full_path_glob_missing_leading_anchor
  • cargo clippy -- -D warnings

Fixes #1650

Made with Cursor

Patterns with -p -g match the whole absolute path; warn if the
pattern does not start with '/' or '*' to help avoid empty results (sharkdp#1650).

Co-authored-by: Cursor <cursoragent@cursor.com>
…1997

Co-authored-by: Cursor <cursoragent@cursor.com>
@leno23

This comment was marked as low quality.

@leno23

This comment was marked as low quality.

leno23 added a commit to leno23/fd that referenced this pull request May 16, 2026
The warning test belongs to sharkdp#1650 / sharkdp#1999, not the multi search-path
exclude fix.

Co-authored-by: Cursor <cursoragent@cursor.com>
@leno23

This comment was marked as low quality.

Copy link
Copy Markdown
Collaborator

@tmccombs tmccombs left a comment

Choose a reason for hiding this comment

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

I think this should be done in a way that works across operating systems. I'm not sure entirely sure what a robust way to determine if a glob pattern is absolute on windows, largely due to my lack of windows expertise, but I'm confident this isn't adequate.

Also, @leno23 it looks like you may be using an AI agent (perhaps OpenClaw or similar?) that is generating a lot of comments and pull requests, including duplicate pull requests.

Although the use of AI isn't entirely prohibited, we ask that you have a human in the loop reviewing the changes before opening pull requests, and don't automatically add comments. See our contribution policy.

In particular, comments like #1999 (comment) and #1999 (comment) and similar ones on related issues are not useful, and create noise and extra work for maintainers. Similarly with duplicate PRs.

Comment thread src/main.rs
let Some(first) = opts.pattern.chars().next() else {
return;
};
if first == '/' || first == '*' {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is only correct on unix systems. On windows an absolute path could start with a letter (for example it could start with "c:\").

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.

[BUG] Glob pattern that uses ** does not seem to work

2 participants