Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes from special Git attributes files not reported correctly #5175

Open
chrisd8088 opened this issue Nov 10, 2022 · 0 comments
Open
Labels
attributes Related to attribute handling bug

Comments

@chrisd8088
Copy link
Member

chrisd8088 commented Nov 10, 2022

Describe the bug

In addition to .gitattributes files in any directory in a repository, Git also supports several types of special attributes files, including $GIT_DIR/info/attributes, which has the highest priority of any attributes file, and the global and system-wide Git attributes files, which have the lowest priority. The gitattributes(5) manual page describes these in detail.

The git lfs track command parses all of these special attributes files, and when no command options are given, it outputs a list of all file patterns with a filter attribute defined with the value lfs.

However, this listing has a number of inconsistencies and errors when file patterns are defined in any Git attributes file other than a .gitattributes one.

To Reproduce

This example assumes Git was installed under /usr/local and that no /usr/local/etc/gitattributes file exists. Note the need to use PREFIX=/usr/local so that git lfs track finds the system-wide Git attributes file.

$ git init test
$ cd test

$ echo "*.boo filter=lfs diff=lfs merge=lfs -text" >.git/info/attributes
$ echo "*.yoo filter=lfs diff=lfs merge=lfs -text" >~/.config/git/attributes
$ sudo echo "*.zoo filter=lfs diff=lfs merge=lfs -text" >/usr/local/etc/gitattributes

$ mkdir dir thisisalongdir
$ echo "*.foo filter=lfs diff=lfs merge=lfs -text" >.gitattributes
$ echo "*.goo filter=lfs diff=lfs merge=lfs -text" >dir/.gitattributes
$ echo "*.moo filter=lfs diff=lfs merge=lfs -text" >thisisalongdir/.gitattributes

$ PREFIX=/usr/local git lfs track
Listing tracked patterns
    thisisalongdir/*.moo (thisisalongdir/.gitattributes)
    .git/info/*.boo (.git/info/attributes)
    dir/*.goo (dir/.gitattributes)
    *.foo (.gitattributes)
    *.yoo ()
    *.zoo ()
Listing excluded patterns

Expected behaviour

The file pattern from the $GIT_DIR/info/attributes file should not be listed as .git/info/<pattern> but just <pattern>.

The file pattern from the global Git attributes file (i.e., $HOME/.config/git/attributes or equivalent, such as $XDG_CONFIG_HOME/git/attributes) and the system-wide Git attributes file should have their source file names listed instead of just ().

The file patterns should be listed with their relative priority as a first sorting principle, so the $GIT_DIR/info/attributes one should be listed first. At the moment they are listed by the length of the file path, so it sorts between a longer directory name and a shorter one.

In summary, we should expect a listing something like the following, assuming that .gitattributes file paths are sorted alphanumerically as in a normal file listing:

$ PREFIX=/usr/local git lfs track
Listing tracked patterns
    *.boo (.git/info/attributes)
    dir/*.goo (dir/.gitattributes)
    thisisalongdir/*.moo (thisisalongdir/.gitattributes)
    *.foo (.gitattributes)
    *.yoo (<path to user home dir>/.config/git/attributes)
    *.zoo (<prefix>/etc/gitattributes)
Listing excluded patterns

System environment

The example above is performed on macOS with Git installed under /usr/local, but applies to any system with appropriate choice of $prefix for the commands which touch $prefix/etc/gitattributes.

Output of git lfs env

git-lfs/3.2.0 (GitHub; darwin amd64; go 1.19.1; git b64865c0)
git version 2.33.0

Additional context

As noted in PR #3076, no distinction is made between patterns defined in local .gitattributes files and the other special Git attributes files:

In the future, we might consider adding a denotation in the output of git-lfs-track(1) when listing a pattern that comes from outside the repository-local .gitattributes file, but we presently are unable to do this since it would involve a breaking change in the formatting of git-lfs-track(1).

See #3076 and #3070 for previous work on support for reading special Git attributes files.

@chrisd8088 chrisd8088 added the bug label Nov 11, 2022
@bk2204 bk2204 added the attributes Related to attribute handling label Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attributes Related to attribute handling bug
Projects
None yet
Development

No branches or pull requests

2 participants