Fix core.excludesfile named .gitignore #2269
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ignore rules with slashes in them are matched using
FNM_PATHNAME
and use the path to the.gitignore
file from the root of the repository along with the path fragment (including slashes) in the ignore file itself. Unfortunately, the relative path to the.gitignore
file was being applied to the globalcore.excludesfile
if that also happened to be named ".gitignore".This fixes that with more precise matching and includes test for ignore rules with leading slashes (which were the primary example of this being broken in the real world).
This also backports an improvement to the file context logic from the threadsafe-iterators branch (i.e. PR #2108) so we don't rely on mutating the key of the attribute file name to generate the context path. Instead, the matching rule parser just expects a trailing filename and strips it off when it parses the rule.
This is an alternate fix for Issue #2266 to PR #2267 - sorry @robrix, once I wrote the tests, it was easier just to write the fix for this as well...