summaryrefslogtreecommitdiff
path: root/tests/attr
Commit message (Collapse)AuthorAgeFilesLines
* path: separate git-specific path functions from utilEdward Thomson2021-11-091-1/+1
| | | | | | Introduce `git_fs_path`, which operates on generic filesystem paths. `git_path` will be kept for only git-specific path functionality (for example, checking for `.git` in a path).
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-13/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
* attr_file: don't take the `repo` as an argethomson/attr_longpathsEdward Thomson2021-09-261-3/+3
| | | | The `repo` argument is now unnecessary. Remove it.
* attr: introduce `git_attr_options` for extended queriesEdward Thomson2021-07-221-1/+1
| | | | | | | Allow more advanced attribute queries using a `git_attr_options`, and extended functions to use it. Presently there is no additional configuration in a `git_attr_options` beyond the flags, but this is for future growth.
* attr: the attr source is now a structEdward Thomson2021-07-221-1/+2
| | | | | We may want to extend the attribute source; use a structure instead of an enum.
* attr: rename internal attr file source enumEdward Thomson2021-07-221-6/+6
| | | | | | The enum `git_attr_file_source` is better suffixed with a `_t` since it's a type-of source. Similarly, its members should have a matching name.
* attr: validate workdir paths for attribute filesEdward Thomson2021-04-281-3/+3
| | | | | | We should allow attribute files - inside working directories - to have names longer than MAX_PATH when core.longpaths is set. `git_attr_path__init` takes a repository to validate the path with.
* attr: Update definition of binary macroLaurence McGlashan2019-12-121-4/+6
|
* fileops: rename to "futils.h" to match function signaturesPatrick Steinhardt2019-07-201-1/+1
| | | | | | | | | Our file utils functions all have a "futils" prefix, e.g. `git_futils_touch`. One would thus naturally guess that their definitions and implementation would live in files "futils.h" and "futils.c", respectively, but in fact they live in "fileops.h". Rename the files to match expectations.
* attr_file: ignore macros defined in subdirectoriesPatrick Steinhardt2019-07-122-1/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now, we are unconditionally applying all macros found in a gitatttributes file. But quoting gitattributes(5): Custom macro attributes can be defined only in top-level gitattributes files ($GIT_DIR/info/attributes, the .gitattributes file at the top level of the working tree, or the global or system-wide gitattributes files), not in .gitattributes files in working tree subdirectories. The built-in macro attribute "binary" is equivalent to: So gitattribute files in subdirectories of the working tree may explicitly _not_ contain macro definitions, but we do not currently enforce this limitation. This patch introduces a new parameter to the gitattributes parser that tells whether macros are allowed in the current file or not. If set to `false`, we will still parse macros, but silently ignore them instead of adding them to the list of defined macros. Update all callers to correctly determine whether the to-be-parsed file may contain macros or not. Most importantly, when walking up the directory hierarchy, we will only set it to `true` once it reaches the root directory of the repo itself. Add a test that verifies that we are indeed not applying macros from subdirectories. Previous to these changes, the test would've failed.
* tests: attr: verify that in-memory macros are respectedPatrick Steinhardt2019-07-121-0/+55
| | | | | Add some tests to ensure that the `git_attr_add_macro` function works as expected.
* tests: attr: implement tests to verify attribute rewriting behaviourPatrick Steinhardt2019-07-122-0/+85
| | | | | Implement some tests that verify that we are correctly updating gitattributes when rewriting or unlinking the corresponding files.
* tests: attr: extract macro tests into their own suitePatrick Steinhardt2019-07-122-70/+91
| | | | | | As macros are a specific functionality in the gitattributes code, it makes sense to extract them into their own test suite, too. This makes finding macro-related tests easier.
* tests: attr: add tests for system-level attributesPatrick Steinhardt2019-07-041-0/+45
| | | | | | | | | | | There were no tests that verified that system-level gitattributes files get handled correctly. In fact, we have recently introduced a regression that caused us to abort if there was a system-level gitattributes file available. Add two tests that verify that we're able to handle system-level gitattributes files. The test attr::repo::sysdir_with_session would've failed without the fix to the described regression.
* attr: rename constants and macros for consistencyethomson/attrEdward Thomson2019-06-165-63/+63
| | | | | Our enumeration values are not generally suffixed with `T`. Further, our enumeration names are generally more descriptive.
* tests: unify ignore tests into their own dirPatrick Steinhardt2019-06-071-461/+0
| | | | | | | | | | | | | We had several occasions where tests for the gitignore had been added to status::ignore instead of the easier-to-handle attr::ignore test suite. This most likely resulted from the fact that the attr::ignore test suite is not easy to discover inside of the attr folder. Furthermore, ignore being part of the attributes code is an implementation detail, only, and thus shouldn't be stressed as much. Improve this by moving both attr::ignore and status::ignore tests into a new ignore test suite.
* ignore: handle escaped trailing whitespacePatrick Steinhardt2019-06-061-0/+46
| | | | | | | | | | The gitignore's pattern format specifies that "Trailing spaces are ignored unless they are quoted with backslash ("\")". We do not honor this currently and will treat a pattern "foo\ " as if it was "foo\" only and a pattern "foo\ \ " as "foo\ \". Fix our code to handle those special cases and add tests to avoid regressions.
* attr: ensure regular attr files can have whitespaceethomson/ignore_spacesEdward Thomson2019-05-241-6/+25
| | | | | | Unlike ignore files, gitattribute files can have flexible whitespace at the beginning of the line. Ensure that by adding new ignore rules that we have not impeded correct parsing of attribute files.
* ignore: treat paths with trailing "/" as directoriesPatrick Steinhardt2019-04-051-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* ignore: move tests from status to attr ignore suiteSteven King Jr2019-03-201-0/+25
|
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-1/+1
|
* attr_file: fix handling of directory patterns with trailing spacesPatrick Steinhardt2018-04-121-0/+16
| | | | | | | | | | | | | | | | 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.
* Ignore trailing whitespace in .gitignore files (as git itself does)David Turner2017-10-291-0/+10
|
* ignore: honor case insensitivity for negative ignoresPatrick Steinhardt2017-08-251-0/+34
| | | | | | | | | | | | | | | | 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.
* ignore: keep negative rules containing wildcardsPatrick Steinhardt2017-08-251-0/+9
| | | | | | | | | | | | | | | | | | | | | | 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.
* Fix issue with directory glob ignore in subdirectoriesRobert Gay2017-05-171-0/+12
|
* `cl_git_exec` -> `cl_git_expect`ethomson/clar_messagesEdward Thomson2017-02-171-1/+1
|
* tests: provide better pass/failure error messagesEdward Thomson2017-02-171-2/+2
| | | | | | 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.
* ignore: fix directory limits when searching for star-starCarlos Martín Nieto2016-04-191-0/+12
| | | | | | | | | | | | 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.
* Add more tests for path matching with globs and path delimitersAntonio Scandurra2016-04-181-0/+14
|
* ignore: don't use realpath to canonicalize pathcmn/ignore-symlinkCarlos Martín Nieto2016-04-021-0/+13
| | | | | | 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.
* attr tests: make explicit our dir/file match testsEdward Thomson2015-05-131-12/+24
|
* attr test: test a file beneath ignored folderEdward Thomson2015-05-121-1/+1
|
* attr: test that a file is not ignored for a folderEdward Thomson2015-05-121-0/+17
| | | | | When a .gitignore specifies some folder "foo/", ensure that a file with the same name "foo" is not ignored.
* attr: regression tests for ignore matchingEdward Thomson2015-05-121-0/+32
| | | | | | 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).
* Improvements to ignore performance on Windows.J Wyman2015-04-281-3/+3
| | | | Minimizing the number directory and file opens, minimizes the amount of IO thus reducing the overall cost of performing ignore operations.
* Add failing subdirectory gitignore attr test.Mike McQuaid2015-04-231-0/+18
|
* attr: Add an extra test for files under a subfolderThe rugged tests are fragile2014-09-171-0/+7
|
* Fix attribute lookup in index for bare reposrb/attr-with-bareRussell Belfer2014-09-151-0/+36
| | | | | | | | | | | | | | | | When using a bare repo with an index, libgit2 attempts to read files from the index. It caches those files based on the path to the file, specifically the path to the directory that contains the file. If there is no working directory, we use `git_path_dirname_r` to get the path to the containing directory. However, for the `.gitattributes` file in the root of the repository, this ends up normalizing the containing path to `"."` instead of the empty string and the lookup the `.gitattributes` data fails. This adds a test of attribute lookups on bare repos and also fixes the problem by simply rewriting `"."` to be `""`.
* Some further sandboxing cleanups to testsRussell Belfer2014-05-021-5/+0
| | | | | Trying to find other issues where tests may not clean up quite properly when they are through...
* Improve handling of fake home directoryRussell Belfer2014-05-021-3/+2
| | | | | | | | | | 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.
* Make ** pattern eat trailing slashrb/fix-starstar-againRussell Belfer2014-05-011-0/+18
| | | | This allows "foo/**/*.html" to match "foo/file.html"
* Preload attribute files that may contain macrosRussell Belfer2014-04-181-39/+64
| | | | | | | | | There was a latent bug where files that use macro definitions could be parsed before the macro definitions were loaded. Because of attribute file caching, preloading files that are going to be used doesn't add a significant amount of overhead, so let's always preload any files that could contain macros before we assemble the actual vector of files to scan for attributes.
* Cleanup tests with helper functionsRussell Belfer2014-04-181-1/+1
|
* Fix broken logic for attr cache invalidationRussell Belfer2014-04-173-10/+13
| | | | | | | The checks to see if files were out of date in the attibute cache was wrong because the cache-breaker data wasn't getting stored correctly. Additionally, when the cache-breaker triggered, the old file data was being leaked.
* Attribute file cache refactorRussell Belfer2014-04-172-16/+16
| | | | | | | This is a big refactoring of the attribute file cache to be a bit simpler which in turn makes it easier to enforce a lock around any updates to the cache so that it can be used in a threaded env. Tons of changes to the attributes and ignores code.
* Fix core.excludesfile named .gitignorerb/fix-leading-slash-ignoresRussell Belfer2014-04-141-12/+9
| | | | | | | | | | | | | | | | | 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.
* More ** tests for pattern rulesRussell Belfer2014-04-061-4/+50
|
* Add support for ** matches in ignoresRussell Belfer2014-04-041-0/+13
| | | | | This is an experimental addition to add ** support to fnmatch pattern matching in libgit2. It needs more testing.
* index: rename an entry's id to 'id'Carlos Martín Nieto2014-01-251-1/+1
| | | | This was not converted when we converted the rest, so do it now.