tests/attr/ignore.c


Log

Author Commit Date CI Message
Patrick Steinhardt 9d117e20 2019-04-05T10:22:46 ignore: treat paths with trailing "/" as directories The function `git_ignore_path_is_ignored` is there to test the ignore status of paths that need not necessarily exist inside of a repository. This has the implication that for a given path, we cannot always decide whether it references a directory or a file, and we need to distinguish those cases because ignore rules may treat those differently. E.g. given the following gitignore file: * !/**/ we'd only want to unignore directories, while keeping files ignored. But still, calling `git_ignore_path_is_ignored("dir/")` will say that this directory is ignored because it treats "dir/" as a file path. As said, the `is_ignored` function cannot always decide whether the given path is a file or directory, and thus it may produce wrong results in some cases. While this is unfixable in the general case, we can do better when we are being passed a path name with a trailing path separator (e.g. "dir/") and always treat them as directories.
Steven King Jr d87441f2 2019-03-20T13:24:07 ignore: move tests from status to attr ignore suite
Patrick Steinhardt 251d8771 2018-04-06T12:24:10 attr_file: fix handling of directory patterns with trailing spaces When comparing whether a path matches a directory rule, we pass the both the path and directory name to `fnmatch` with `GIT_ATTR_FNMATCH_DIRECTORY` being set. `fnmatch` expects the pattern to contain no trailing directory '/', which is why we try to always strip patterns of trailing slashes. We do not handle that case correctly though when the pattern itself has trailing spaces, causing the match to fail. Fix the issue by stripping trailing spaces and tabs for a rule previous to checking whether the pattern is a directory pattern with a trailing '/'. This replaces the whitespace-stripping in our ignore file parsing code, which was stripping whitespaces too late. Add a test to catch future breakage.
David Turner 5cb6a2c9 2017-10-29T12:28:43 Ignore trailing whitespace in .gitignore files (as git itself does)
Patrick Steinhardt 2d9ff8f5 2017-07-10T09:36:19 ignore: honor case insensitivity for negative ignores When computing negative ignores, we throw away any rule which does not undo a previous rule to optimize. But on case insensitive file systems, we need to keep in mind that a negative ignore can also undo a previous rule with different case, which we did not yet honor while determining whether a rule undoes a previous one. So in the following example, we fail to unignore the "/Case" directory: /case !/Case Make both paths checking whether a plain- or wildcard-based rule undo a previous rule aware of case-insensitivity. This fixes the described issue.
Patrick Steinhardt b8922fc8 2017-07-07T13:27:27 ignore: keep negative rules containing wildcards Ignore rules allow for reverting a previously ignored rule by prefixing it with an exclamation mark. As such, a negative rule can only override previously ignored files. While computing all ignore patterns, we try to use this fact to optimize away some negative rules which do not override any previous patterns, as they won't change the outcome anyway. In some cases, though, this optimization causes us to get the actual ignores wrong for some files. This may happen whenever the pattern contains a wildcard, as we are unable to reason about whether a pattern overrides a previous pattern in a sane way. This happens for example in the case where a gitignore file contains "*.c" and "!src/*.c", where we wouldn't un-ignore files inside of the "src/" subdirectory. In this case, the first solution coming to mind may be to just strip the "src/" prefix and simply compare the basenames. While that would work here, it would stop working as soon as the basename pattern itself is different, like for example with "*x.c" and "!src/*.c. As such, we settle for the easier fix of just not optimizing away rules that contain a wildcard.
Robert Gay c3b8e8b3 2017-05-14T10:28:05 Fix issue with directory glob ignore in subdirectories
Edward Thomson c52480fd 2017-02-17T13:01:49 `cl_git_exec` -> `cl_git_expect`
Edward Thomson a1dcc830 2017-02-17T12:13:35 tests: provide better pass/failure error messages Provide more detailed messages when conditions pass or fail unexpectedly. In particular, this provides the error messages when a test fails with a different error code than was expected.
Carlos Martín Nieto 1c3018eb 2016-04-18T13:34:18 ignore: fix directory limits when searching for star-star In order to match the star-star, we disable the flag that's looking for a single path element, but that leads to searching for the pattern in the middle of elements in the input string. Mark when we're handing a star-star so we jump over the elements in our attempt to match the part of the pattern that comes after the star-star. While here, tighten up the check so we don't allow invalid rules through.
Antonio Scandurra 0f362716 2016-03-31T17:38:40 Add more tests for path matching with globs and path delimiters
Carlos Martín Nieto d364dc8b 2016-04-01T14:33:42 ignore: don't use realpath to canonicalize path If we're looking for a symlink, realpath will give us the resolved path, which is not what we're after, but a canonicalized version of the path the user asked for.
Edward Thomson 882cc37f 2015-05-13T10:56:55 attr tests: make explicit our dir/file match tests
Edward Thomson 9486d203 2015-05-12T13:07:59 attr test: test a file beneath ignored folder
Edward Thomson 97fb9ac7 2015-05-12T13:54:28 attr: test that a file is not ignored for a folder When a .gitignore specifies some folder "foo/", ensure that a file with the same name "foo" is not ignored.
Edward Thomson adad5181 2015-05-12T13:52:47 attr: regression tests for ignore matching Ensure that when examining a .gitignore in a subdirectory, we do not erroneously apply the paths contained therein to the root of the repository. (Fixed in c02a0e4).
Mike McQuaid c6bf03b4 2015-03-28T18:37:15 Add failing subdirectory gitignore attr test.
Russell Belfer 0f603132 2014-05-01T14:47:33 Improve handling of fake home directory There are a few tests that set up a fake home directory and a fake GLOBAL search path so that we can test things in global ignore or attribute or config files. This cleans up that code to work more robustly even if there is a test failure. This also fixes some valgrind warnings where scanning search paths for separators could end up doing a little bit of sketchy data access when coming to the end of search list.
Russell Belfer d19b2f9f 2014-05-01T12:46:46 Make ** pattern eat trailing slash This allows "foo/**/*.html" to match "foo/file.html"
Russell Belfer 50e46d60 2014-04-18T10:58:01 Cleanup tests with helper functions
Russell Belfer a9528b8f 2014-04-14T15:59:48 Fix core.excludesfile named .gitignore 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 global core.excludesfile if that was also 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 where we don't rely on mutating the key of the attribute file name to generate the context path.
Russell Belfer c8c91433 2014-04-06T10:42:26 More ** tests for pattern rules
Russell Belfer 2b6b85f1 2014-04-04T17:02:12 Add support for ** matches in ignores This is an experimental addition to add ** support to fnmatch pattern matching in libgit2. It needs more testing.
Ben Straub 17820381 2013-11-14T14:05:52 Rename tests-clar to tests