git: match patterns, not file names, for tracked files #5423
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.
Right now, when we run
git lfs track, we warn the user if the pattern they've provided matches an existing file name. However, when we invoke that command with--filenameand a pattern with brackets on Windows, we get an error because the escaped pattern contains backslashes, which results in broken behaviour on Windows.The real cause of this problem, however, is that we're ultimately asking for a file name and not a pattern. Our invocation happens to work on Unix, but we need it to also work on Windows. To solve this, let's instead ask for ignored cached files and specify a single pattern. Since we've asked for a pattern, this results in a different behaviour from before and avoids the error.
We would have caught this on Windows if our weird file name code had worked there, but since we included asterisks and question marks, which are not valid on Windows, the test couldn't run there. Instead, let's leave the brackets and run the test on all platforms. We still have the test below which does the same thing with spaces on Unix, so we're not really regressing our tests there.
In addition, since we don't have any tests for this verbose logging that prints the messages that trigger the problem, let's add some, both with more common patterns and some unusual ones as well.
Fixes #5409
/cc @zhoushaokun as reporter