Coder Social home page Coder Social logo

Fail to match directory about python-pathspec HOT 3 CLOSED

cpburnz avatar cpburnz commented on July 18, 2024
Fail to match directory

from python-pathspec.

Comments (3)

cpburnz avatar cpburnz commented on July 18, 2024 1

I'm closing this due to inactivity. If you're still interested in this issue, please comment.

from python-pathspec.

cpburnz avatar cpburnz commented on July 18, 2024

@ant31

Just in case this wasn't a typo when you were writing your question, the PathSpec.from_lines() method should be given a list (or some iterable) of strings for the lines, not a string directly.

The problem is the pattern cargo/ should match that directory, and any files underneath it, but not a file named cargo. By supplying the path cargo it's interpreted as being a file and thus it is not matched which is consistent with how .gitignore works to my understanding.

E.g., If you have the directory structure:

cargo/
cargo/a

A .gitignore of:

cargo/

git will ignore the cargo directory.

However, if you have just the file:

cargo

git will not ignore the cargo file.

So, to get around this the solution would be to append a / to the directory paths. I.e.,

>>> spec = pathspec.PathSpec.from_lines('gitwildmatch', ['cargo/'])
>>> spec.match_file('cargo')
False
>>> spec.match_file('cargo/')
True

Currently, the PathSpec.match_tree() method only considers files. I could extend it with an optional argument to also consider directories if you're using that method.

from python-pathspec.

cpburnz avatar cpburnz commented on July 18, 2024

@ant31 Or are you trying to ignore cargo/? If that's the case, I think you want something more like:

>>> patterns = ['**', '!cargo/']
>>> spec = pathspec.PathSpec.from_lines('gitwildmatch', patterns)
>>> spec.match_file('cargo')
True
>>> spec.match_file('cargo/a')
False

from python-pathspec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.