When computing whether a file is ignored, we simply search for the first matching rule and return whether it is a positive ignore rule (the file is really ignored) or whether it is a negative ignore rule (the file is being unignored). Each rule has a set of flags which are being passed to `fnmatch`, depending on what kind of rule it is. E.g. in case it is a negative ignore we add a flag `GIT_ATTR_FNMATCH_NEGATIVE`, in case it contains a glob we set the `GIT_ATTR_FNMATCH_HASGLOB` flag. One of these flags is the `GIT_ATTR_FNMATCH_LEADINGDIR` flag, which is always set in case the pattern has a trailing "/*" or in case the pattern is negative. The flag causes the `fnmatch` function to return a match in case a string is a leading directory of another, e.g. "dir/" matches "dir/foo/bar.c". In case of negative patterns, this is wrong in certain cases. Take the following simple example of a gitignore: dir/ !dir/ The `LEADINGDIR` flag causes "!dir/" to match "dir/foo/bar.c", and we correctly unignore the directory. But take this example: *.test !dir/* We expect everything in "dir/" to be unignored, but e.g. a file in a subdirectory of dir should be ignored, as the "*" does not cross directory hierarchies. With `LEADINGDIR`, though, we would just see that "dir/" matches and return that the file is unignored, even if it is contained in a subdirectory. Instead, we want to ignore leading directories here and check "*.test". Afterwards, we have to iterate up to the parent directory and do the same checks. To fix the issue, disallow matching against leading directories in gitignore files. This can be trivially done by just adding the `GIT_ATTR_FNMATCH_NOLEADINGDIR` to the spec passed to `git_attr_fnmatch__parse`. Due to a bug in that function, though, this flag is being ignored for negative patterns, which is fixed in this commit, as well. As a last fix, we need to ignore rules that are supposed to match a directory when our path itself is a file. All together, these changes fix the described error case.
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
hash | Loading commit data... | |
streams | Loading commit data... | |
transports | Loading commit data... | |
unix | Loading commit data... | |
win32 | Loading commit data... | |
xdiff | Loading commit data... | |
CMakeLists.txt | Loading commit data... | |
annotated_commit.c | Loading commit data... | |
annotated_commit.h | Loading commit data... | |
apply.c | Loading commit data... | |
apply.h | Loading commit data... | |
array.h | Loading commit data... | |
attr.c | Loading commit data... | |
attr.h | Loading commit data... | |
attr_file.c | Loading commit data... | |
attr_file.h | Loading commit data... | |
attrcache.c | Loading commit data... | |
attrcache.h | Loading commit data... | |
bitvec.h | Loading commit data... | |
blame.c | Loading commit data... | |
blame.h | Loading commit data... | |
blame_git.c | Loading commit data... | |
blame_git.h | Loading commit data... | |
blob.c | Loading commit data... | |
blob.h | Loading commit data... | |
branch.c | Loading commit data... | |
branch.h | Loading commit data... | |
buf_text.c | Loading commit data... | |
buf_text.h | Loading commit data... | |
buffer.c | Loading commit data... | |
buffer.h | Loading commit data... | |
cache.c | Loading commit data... | |
cache.h | Loading commit data... | |
cc-compat.h | Loading commit data... | |
checkout.c | Loading commit data... | |
checkout.h | Loading commit data... | |
cherrypick.c | Loading commit data... | |
clone.c | Loading commit data... | |
clone.h | Loading commit data... | |
commit.c | Loading commit data... | |
commit.h | Loading commit data... | |
commit_list.c | Loading commit data... | |
commit_list.h | Loading commit data... | |
common.h | Loading commit data... | |
config.c | Loading commit data... | |
config.h | Loading commit data... | |
config_cache.c | Loading commit data... | |
config_file.c | Loading commit data... | |
config_file.h | Loading commit data... | |
config_parse.c | Loading commit data... | |
config_parse.h | Loading commit data... | |
crlf.c | Loading commit data... | |
date.c | Loading commit data... | |
delta.c | Loading commit data... | |
delta.h | Loading commit data... | |
describe.c | Loading commit data... | |
diff.c | Loading commit data... | |
diff.h | Loading commit data... | |
diff_driver.c | Loading commit data... | |
diff_driver.h | Loading commit data... | |
diff_file.c | Loading commit data... | |
diff_file.h | Loading commit data... | |
diff_generate.c | Loading commit data... | |
diff_generate.h | Loading commit data... | |
diff_parse.c | Loading commit data... | |
diff_parse.h | Loading commit data... | |
diff_print.c | Loading commit data... | |
diff_stats.c | Loading commit data... | |
diff_tform.c | Loading commit data... | |
diff_tform.h | Loading commit data... | |
diff_xdiff.c | Loading commit data... | |
diff_xdiff.h | Loading commit data... | |
errors.c | Loading commit data... | |
features.h.in | Loading commit data... | |
fetch.c | Loading commit data... | |
fetch.h | Loading commit data... | |
fetchhead.c | Loading commit data... | |
fetchhead.h | Loading commit data... | |
filebuf.c | Loading commit data... | |
filebuf.h | Loading commit data... | |
fileops.c | Loading commit data... | |
fileops.h | Loading commit data... | |
filter.c | Loading commit data... | |
filter.h | Loading commit data... | |
fnmatch.c | Loading commit data... | |
fnmatch.h | Loading commit data... | |
global.c | Loading commit data... | |
global.h | Loading commit data... | |
graph.c | Loading commit data... | |
hash.c | Loading commit data... | |
hash.h | Loading commit data... | |
hashsig.c | Loading commit data... | |
ident.c | Loading commit data... | |
idxmap.c | Loading commit data... | |
idxmap.h | Loading commit data... | |
ignore.c | Loading commit data... | |
ignore.h | Loading commit data... | |
index.c | Loading commit data... | |
index.h | Loading commit data... | |
indexer.c | Loading commit data... | |
indexer.h | Loading commit data... | |
integer.h | Loading commit data... | |
iterator.c | Loading commit data... | |
iterator.h | Loading commit data... | |
khash.h | Loading commit data... | |
map.h | Loading commit data... | |
merge.c | Loading commit data... | |
merge.h | Loading commit data... | |
merge_driver.c | Loading commit data... | |
merge_driver.h | Loading commit data... | |
merge_file.c | Loading commit data... | |
message.c | Loading commit data... | |
message.h | Loading commit data... | |
mwindow.c | Loading commit data... | |
mwindow.h | Loading commit data... | |
netops.c | Loading commit data... | |
netops.h | Loading commit data... | |
notes.c | Loading commit data... | |
notes.h | Loading commit data... | |
object.c | Loading commit data... | |
object.h | Loading commit data... | |
object_api.c | Loading commit data... | |
odb.c | Loading commit data... | |
odb.h | Loading commit data... | |
odb_loose.c | Loading commit data... | |
odb_mempack.c | Loading commit data... | |
odb_pack.c | Loading commit data... | |
offmap.c | Loading commit data... | |
offmap.h | Loading commit data... | |
oid.c | Loading commit data... | |
oid.h | Loading commit data... | |
oidarray.c | Loading commit data... | |
oidarray.h | Loading commit data... | |
oidmap.c | Loading commit data... | |
oidmap.h | Loading commit data... | |
pack-objects.c | Loading commit data... | |
pack-objects.h | Loading commit data... | |
pack.c | Loading commit data... | |
pack.h | Loading commit data... | |
parse.c | Loading commit data... | |
parse.h | Loading commit data... | |
patch.c | Loading commit data... | |
patch.h | Loading commit data... | |
patch_generate.c | Loading commit data... | |
patch_generate.h | Loading commit data... | |
patch_parse.c | Loading commit data... | |
patch_parse.h | Loading commit data... | |
path.c | Loading commit data... | |
path.h | Loading commit data... | |
pathspec.c | Loading commit data... | |
pathspec.h | Loading commit data... | |
pool.c | Loading commit data... | |
pool.h | Loading commit data... | |
posix.c | Loading commit data... | |
posix.h | Loading commit data... | |
pqueue.c | Loading commit data... | |
pqueue.h | Loading commit data... | |
proxy.c | Loading commit data... | |
proxy.h | Loading commit data... | |
push.c | Loading commit data... | |
push.h | Loading commit data... | |
rebase.c | Loading commit data... | |
refdb.c | Loading commit data... | |
refdb.h | Loading commit data... | |
refdb_fs.c | Loading commit data... | |
refdb_fs.h | Loading commit data... | |
reflog.c | Loading commit data... | |
reflog.h | Loading commit data... | |
refs.c | Loading commit data... | |
refs.h | Loading commit data... | |
refspec.c | Loading commit data... | |
refspec.h | Loading commit data... | |
remote.c | Loading commit data... | |
remote.h | Loading commit data... | |
repo_template.h | Loading commit data... | |
repository.c | Loading commit data... | |
repository.h | Loading commit data... | |
reset.c | Loading commit data... | |
revert.c | Loading commit data... | |
revparse.c | Loading commit data... | |
revwalk.c | Loading commit data... | |
revwalk.h | Loading commit data... | |
settings.c | Loading commit data... | |
sha1_lookup.c | Loading commit data... | |
sha1_lookup.h | Loading commit data... | |
signature.c | Loading commit data... | |
signature.h | Loading commit data... | |
sortedcache.c | Loading commit data... | |
sortedcache.h | Loading commit data... | |
stash.c | Loading commit data... | |
status.c | Loading commit data... | |
status.h | Loading commit data... | |
stream.h | Loading commit data... | |
strmap.c | Loading commit data... | |
strmap.h | Loading commit data... | |
strnlen.h | Loading commit data... | |
submodule.c | Loading commit data... | |
submodule.h | Loading commit data... | |
sysdir.c | Loading commit data... | |
sysdir.h | Loading commit data... | |
tag.c | Loading commit data... | |
tag.h | Loading commit data... | |
thread-utils.c | Loading commit data... | |
thread-utils.h | Loading commit data... | |
trace.c | Loading commit data... | |
trace.h | Loading commit data... | |
trailer.c | Loading commit data... | |
transaction.c | Loading commit data... | |
transaction.h | Loading commit data... | |
transport.c | Loading commit data... | |
tree-cache.c | Loading commit data... | |
tree-cache.h | Loading commit data... | |
tree.c | Loading commit data... | |
tree.h | Loading commit data... | |
tsort.c | Loading commit data... | |
userdiff.h | Loading commit data... | |
util.c | Loading commit data... | |
util.h | Loading commit data... | |
varint.c | Loading commit data... | |
varint.h | Loading commit data... | |
vector.c | Loading commit data... | |
vector.h | Loading commit data... | |
worktree.c | Loading commit data... | |
worktree.h | Loading commit data... | |
zstream.c | Loading commit data... | |
zstream.h | Loading commit data... |