question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrectly (?) matches files inside directories that do match

See original GitHub issue

Hello @cpburnz, I’ve looked existing issues but couldn’t find this one. It was initially reported in yamllint issues: https://github.com/adrienverge/yamllint/issues/334 (yamllint uses pathspec).

Considering these files:

file.yaml
dir/
└── dir/file.sql
dir.yaml/
└── dir.yaml/file.sql        ← problem here

pathspec.PathSpec.from_lines('gitwildmatch', ['*.yaml']) does match file.yaml, dir.yaml, but also dir.yaml/file.sql. The latter isn’t what I would expect, because *.yaml feels like “files that end with .yaml”, not “any file in any path that contains .yaml”.

Is it the expected behavior? If yes, what is the correct pattern for “files that end with .yaml”?

Looking forward to your answer, and thanks for this very useful project 👍

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
cpburnzcommented, Aug 31, 2022

There will be a way to handle this scenario in the v0.10.0 release. The new class, GitIgnoreSpec, will need to be used. It will prioritize patterns that directly match the file over an ancestor directory. It can be used as:

# The "gitwildmatch" pattern factory is assumed by GitIgnoreSpec.
p = pathspec.GitIgnoreSpec.from_lines(['*.yaml', '!*.yaml/'])
p.match_file('dir/file.yaml')       # True
p.match_file('dir.yaml/file.yaml')  # True
0reactions
adrienvergecommented, Aug 31, 2022

Thanks @cpburnz!

Read more comments on GitHub >

github_iconTop Results From Across the Web

recursive glob([**]) incorrectly matches files in subpackages ...
When subdirectories contain subpackages using a BUILD file, the glob does not match, as expected (and documented).
Read more >
Test if there are files matching a pattern in order to execute a ...
With zsh , the test for are there files matching a pattern can be written using an anonymous function and the N (for...
Read more >
List files not matching a pattern? - bash - Stack Overflow
I guess it happens because the branches expand the outputs of the command inside them. So it becomes an argument list with about...
Read more >
How to list files based on matching only part of their filename?
From this directory, I want to know how I could use grep to display files based on part of their filename - for...
Read more >
Tips for writing glob patterns in DeepSource configuration
The glob pattern to match all files under the /src/tests/ directory should be written as */tests** — where */ denotes matching a string...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found