Re: bug report
From: Paul Smith <hidden>
Date: 2021-11-12 14:27:24
On Fri, 2021-11-12 at 01:59 -0500, Theodore Li wrote:
Yes, though other patterns like !/*/ don't need the quotes. I thought it worked the same way without the quotes in earlier versions, but after testing with version 2.32.0, it seems like the behavior is the same. Guess I remembered wrong.
It's important to realize that in a POSIX-style shell (as you'll find on GNU/Linux or MacOS, or in the Git for Windows shell), wildcard expansion is performed _by the shell_ before the program is even invoked. It's not performed by the program itself (in this case, Git). In a POSIX-style shell it works like this (by default): first the shell will try to expand the wildcards in your command line by matching them for files. If any match, the wildcard expression is replaced on the command line. If no files match, then the wildcard expression is passed to the command without change. So if you run: git sparse-checkout /* then the shell will check if any files match the wildcard /*: since clearly you will get matches for this expression, they will be expanded and the shell will actually run: git sparse-checkout /bin /boot /cdrom /dev /... Note, Git does not receive any indication that there ever was a wildcard expression here! On the other hand if you run: git sparse-checkout /blah/*/blah (assuming you don't have any files on your system that match this wildcard) then it won't match and the shell will run: git sparse-checkout /blah/*/blah Now Git can examine this wildcard and do an appropriate thing with it. In short, if you want to be _sure_ that a wildcard expression is passed to the command and not expanded by the shell, you must always quote it: git sparse-checkout "/*" If you don't quote it then it may or may not do what you intended, depending on whether the wildcard happens to match any files.