Skip to content

Conversation

@chrisd8088
Copy link
Member

The --include and --exclude (-I and -X) options to the git lfs migrate command allow the user to specify filepath filters which select matching files to migrate and which are also used to populate any .gitattributes files 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 .gitattributes files. (See the use of the trackedFromFilter() and trackedFromExportFilter() functions in particular.)

However, all other Git LFS commands which parse --include and --exclude options, such as git lfs fetch and git lfs ls-files, expect to treat any supplied patterns according to gitignore(5) rules. (This aligns with, for instance, how the -x option to git ls-files works.)

We therefore introduce a buildFilepathFilterWithPatternType() function which the git lfs migrate command can use to specify the filepathfilter.GitAttributes matching mode for its filter, while the other commands continue to use the filepathfilter.GitIgnore mode.

Note that this change change will have several consequences. On one hand, patterns such as *.bin will only match against files, not directories, which will restore the behaviour of git lfs migrate in this regard prior to v3.0.0 and the changes from PR #4556.

On the other hand, patterns such as foo will no longer recursively match everything inside a directory, and foo/** must be used instead. This is in line with how Git's native gitattributes(5) matching works.

We therefore adjust one existing test to use a directory match of the form foo/** instead of foo, and add one new test which confirms that only files named *.txt match a pattern of that form, instead of all files in any directory whose name has that form, such as a file like foo.txt/bar.md. This new test fails without the changes to the git lfs migrate command introduced in this commit.

And we add a note in the git-lfs-migrate man page that the filepath filter matching mode for that command's --include and --exclude options differs from all other Git LFS commands' mode; i.e., it uses the gitattributes(5) matching mode instead of the gitignore(5) mode used elsewhere.

Fixes #4751.
/cc @rolandas-rimkus as reporter.

The --include and --exclude (-I and -X) options to the
"git lfs migrate" command allow the user to specify filepath
filters which select matching files to migrate and which are
also used to populate any .gitattributes files 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 .gitattributes files.  (See the use of the
trackedFromFilter() and trackedFromExportFilter() functions
in particular.)

However, all other Git LFS commands which parse --include
and --exclude options, such as "git lfs fetch" and
"git lfs ls-files", expect to treat any supplied patterns
according to gitignore(5) rules.  (This aligns with, for
instance, how the -x option to "git ls-files" works.)

We therefore introduce a buildFilepathFilterWithPatternType()
function which the "git lfs migrate" command can use to
specify the filepathfilter.GitAttributes parsing mode for
its filter, while the other commands continue to use the
filepathfilter.GitIgnore mode.

Note that this change change will have several consequences.
On one hand, patterns such as "*.bin" will only match against
files, not directories, which will restore the behaviour of
"git lfs migrate" in this regard prior to v3.0.0 and the
changes from PR git-lfs#4556.

On the other hand, patterns such as "foo" will no longer
recursively match everything inside a directory, and "foo/**"
must be used instead.  This is in line with how Git's native
gitattributes(5) matching works.

We therefore adjust one existing test to use a directory
match of the form "foo/**" instead of "foo", and add one new
test which confirms that only files named "*.txt" match a
pattern of that form, instead of all files in any directory
whose name has that form, such as a file like "foo.txt/bar.md".
This new test fails without the changes to the "git lfs migrate"
command introduced in this commit.
Add a note in the git-lfs-migrate man page that the filepath
filter matching mode for that command's --include and --exclude
options differs from all other Git LFS commands' mode; i.e.,
it uses the gitattributes(5) matching mode instead of the
gitignore(5) mode used elsewhere.
@chrisd8088 chrisd8088 requested a review from a team December 3, 2021 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git lfs migrate import include filter issue starting with version 3.0.1

2 participants