use gitattributes filepath matching for migrate filter options #4758
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
--includeand--exclude(-Iand-X) options to thegit lfs migratecommand allow the user to specify filepath filters which select matching files to migrate and which are also used to populate any.gitattributesfiles written by the import or export operations.This latter functionality implies that we need to parse any filepath patterns supplied by these options using
gitattributes(5)rules, since the patterns will be copied directly into.gitattributesfiles. (See the use of thetrackedFromFilter()andtrackedFromExportFilter()functions in particular.)However, all other Git LFS commands which parse
--includeand--excludeoptions, such asgit lfs fetchandgit lfs ls-files, expect to treat any supplied patterns according togitignore(5)rules. (This aligns with, for instance, how the-xoption togit ls-filesworks.)We therefore introduce a
buildFilepathFilterWithPatternType()function which thegit lfs migratecommand can use to specify thefilepathfilter.GitAttributesmatching mode for its filter, while the other commands continue to use thefilepathfilter.GitIgnoremode.Note that this change change will have several consequences. On one hand, patterns such as
*.binwill only match against files, not directories, which will restore the behaviour ofgit lfs migratein this regard prior to v3.0.0 and the changes from PR #4556.On the other hand, patterns such as
foowill no longer recursively match everything inside a directory, andfoo/**must be used instead. This is in line with how Git's nativegitattributes(5)matching works.We therefore adjust one existing test to use a directory match of the form
foo/**instead offoo, and add one new test which confirms that only files named*.txtmatch a pattern of that form, instead of all files in any directory whose name has that form, such as a file likefoo.txt/bar.md. This new test fails without the changes to thegit lfs migratecommand introduced in this commit.And we add a note in the
git-lfs-migrateman page that the filepath filter matching mode for that command's--includeand--excludeoptions differs from all other Git LFS commands' mode; i.e., it uses thegitattributes(5)matching mode instead of thegitignore(5)mode used elsewhere.Fixes #4751.
/cc @rolandas-rimkus as reporter.