git-lfs/git
Chris Darroch b8d97e3dd7 git/gitattr,t: handle unspecified macro attributes
In commit 1ff52542da97d6418689a5528112b57e37536014 of PR #3391 we
introduced the MacroProcessor type and methods to support the use of
macro attributes in .gitattributes files.

However, we do not currently support the case where a macro attributes
is specified with a "!" prefix, which Git handles by setting all
attributes defined by the macro attribute back to the unspecified state.
(Note that the "-" prefix is not supported by Git for macro attributes,
only the "!" one.)

To mimic the same behaviour in Git LFS we add a check for a macro
attribute with its Unspecified bool set to "true", and when this is
detected we iterate through the set of attributes defined by the macro
attribute and set them all to the same unspecified state.

We also add tests to confirm this new handling works as expected, both
a new Go test and a new "fsck does not detect invalid pointers with
negated macro patterns" test in t/t-fsck.sh that will not succeed without
the changes to the MacroProcessor in this commit.  Without these changes,
any patterns that reference a macro attribute with the "!" prefix are not
processed as making the macro's attributes all unspecified again, and so
non-pointer files matching those patterns are reported as invalid Git LFS
pointers.

In the new test in t/t-fsck.sh we include comments describing how the
"git lfs fsck" command currently processes .gitattributes files in
the order returned by "git ls-tree", and so a .gitattributes file in
a subdirectory such as .dir/ will be parsed before the top-level
.gitattributes one because it appears first in the "git ls-tree" output.
The result is that any macro attribute references in the
.dir/.gitattributes file will not be resolved properly, and so our
test succeeds but not quite for the right reasons.

We also add a new "macros with unspecified flag" test in the
t/t-attributes.sh test script, but this test ultimately is only a
placeholder as it can not actually test that the "git lfs track" command
will not overwrite a pattern in a .gitattributes file in a subdirectory
if it references a macro attribute defined in the top-level .gitattributes
file and the reference has the "!" prefix.  This is due to the fact that
the "git lfs track" command parses .gitattributes files in the order
of the length of their full paths, from longest to shortest, and so
macro attribute references can not be resolved except within the top-level
.gitattributes file (with some caveats regarding the .git/info/attributes
file and the global and system attributes files).

For now we defer resolution of both this issue and the one described
regarding the "git lfs fsck" command to the future.
2022-11-08 01:07:05 -08:00
..
gitattr git/gitattr,t: handle unspecified macro attributes 2022-11-08 01:07:05 -08:00
githistory update inline comments to Go v1.19 doc format 2022-09-25 18:15:31 -07:00
attribs.go post-checkout: don't modify permissions of untracked files 2021-12-06 13:44:33 +00:00
config_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
config.go subprocess: report errors when finding executables 2022-04-19 09:45:20 -07:00
filter_process_scanner_test.go git: use pktline repository 2021-07-20 18:37:31 +00:00
filter_process_scanner.go update inline comments to Go v1.19 doc format 2022-09-25 18:15:31 -07:00
filter_process_status.go make additional message strings translatable 2022-01-29 22:36:19 -08:00
git_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
git.go update inline comments to Go v1.19 doc format 2022-09-25 18:15:31 -07:00
ls_files.go subprocess: report errors when finding executables 2022-04-19 09:45:20 -07:00
ls_tree_scanner_test.go commands/fsck: exit 1 on failed fsck 2021-07-14 18:15:31 +00:00
ls_tree_scanner.go fsck: don't detect symlinks as invalid pointers 2021-10-20 20:51:41 +00:00
object_scanner.go update more comments for catFileBatch() functions 2022-10-31 22:15:22 -07:00
refs_test.go commands,git,lfs: rename left/right RefUpdate vars 2022-02-06 21:32:27 -08:00
refs.go commands,git,lfs: rename left/right RefUpdate vars 2022-02-06 21:32:27 -08:00
rev_list_scanner_test.go git: rename left/right ref args in comments 2022-02-06 21:32:27 -08:00
rev_list_scanner.go subprocess: report errors when finding executables 2022-04-19 09:45:20 -07:00
version.go Set package version to v3 2021-09-02 20:41:08 +00:00