Ignore: only treat one leading slash as a root identifier - #5074
Conversation
For compatibility with git, only skip the first leading slash in an ignore file. That is: `/a.txt` indicates to ignore a file named `a.txt` at the root. However `//b.txt` does not indicate that a file named `b.txt` at the root should be ignored.
|
This is weird and contrary to how most other tools handle this. Are we sure this is expected behaviour in git.git? |
Shockingly, yes. |
|
|
Well, sometimes there's a mismatch between how git.git works and how it's intended to work :P Do you know if it is documented in any way? If not, I think we shouldn't blindly assume this to be intended and instead ask for clarification on the mailing list. I'd definitely volunteer instead of pushing this additional work on you. |
I'm happy if you want to chase this down. :D But even if this wasn't intended, I think they're probably stuck with this behavior now. |
I don't know. It's obviously broken, if you ask me, as such a pattern cannot ever match anything given that files cannot contain slashes. |
|
@pks-t did you end up asking on the mailing list? |
|
On Wed, Jun 05, 2019 at 10:05:04AM -0700, Edward Thomson wrote:
@pks-t did you end up asking on the mailing list?
Not yet, sorry about that. I finally have two days of hacking
time available today and tomorrow, so I'll dig into git.git
now and will try to come up with a patch that "fixes" old
behaviour to get the discussion going.
|
pks-t
left a comment
There was a problem hiding this comment.
So I didn't send out an email, but I did investigate the issue a bit further and dug into git.git's code. During that I read gitignore(5) several times, at last realizing that the behaviour we're seeing is in fact specified:
Otherwise, Git treats the pattern as a shell glob: "*" matches
anything except "/", "?" matches any one character except "/" and
"[]" matches one character in a selected range. See fnmatch(3) and
the FNM_PATHNAME flag for a more detailed description.A leading slash matches the beginning of the pathname. For example,
"/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
So the second part is quite clear in that it says "A leading slash" in singular, and the first part essentially says "If none of our custom pattern format rules apply, please have a look at fnmatch(3)". And neither fnmatch("x//x", "x/x", FNM_PATHNAME) nor fnmatch("x/x", "x/xx", FNM_PATHNAME) will in fact match.
Thus I think we should live with the situation, as gitignore(5) does in fact specify this weird behaviour.
|
By the way, I naturally found some different edge cases which we fail to handle correctly while reading gitignore(5) :D I'll dig into those |
|
Ah, yes, thanks, I should have quoted the docs which do shed light on the fact that this insanity is... well, at least it's documented, if not expected. |
Per #5070, we should not treat multiple leading slashes as identical to a single leading slash. One leading slash indicates the directory root, but only the first should indicate that.
Fixes #5070