threads / bug / 56876

bug report

Subject: bug report

## tl;dr

4 messages between Nov 12, 2021 and Nov 12, 2021.

replies: 3people: 3as markdown or json

Theodore Li· Nov 12, 2021, 04:22 UTC · lore

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue) After cloning a remote repository with the --no-checkout option and executing git sparse-checkout init, the bug occurs with any sparse-checkout command with the /* pattern (i.e. git sparse-checkout set /*).

What did you expect to happen? (Expected behavior) The contents of .git/info/sparse-checkout and the output of git sparse-checkout list should be '/*'

What happened instead? (Actual behavior) Instead, the output is the contents of the user's local root directory (i.e. /bin, /boot, /cdrom, etc.).

What's different between what you expected and what actually happened? It should set sparse-checkout to the pattern /*, corresponding to the remote repository's root directory instead of adding all the folders and files in the root directory of the user's local machine.

Anything else you want to add:

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.33.1 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh compiler info: gnuc: 9.3 libc info: glibc: 2.31 $SHELL (typically, interactive shell): /bin/bash

[Enabled Hooks]
Junio C Hamano· Nov 12, 2021, 04:29 UTC · re: Theodore Li · lore

Re: bug report

Theodore Li <teddy.litheodore@gmail.com> writes:
Show 16 quoted lines
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
>
> What did you do before the bug happened? (Steps to reproduce your issue)
> After cloning a remote repository with the --no-checkout option and
> executing git sparse-checkout init, the bug occurs with any
> sparse-checkout command with the /* pattern (i.e. git sparse-checkout
> set /*).
>
> What did you expect to happen? (Expected behavior)
> The contents of .git/info/sparse-checkout and the output of git
> sparse-checkout list should be '/*'
>
> What happened instead? (Actual behavior)
> Instead, the output is the contents of the user's local root directory
> (i.e. /bin, /boot, /cdrom, etc.).

A blind guess, as I do not use sparse patterns, but perhaps you did not quote the "/*' pattern, i.e. you typed

    $ git sparse-checkout set /*
where you would have got a better behaviour if you typed
    $ git sparse-checkout set "/*"
?
Theodore Li· Nov 12, 2021, 06:59 UTC · re: Junio C Hamano · lore

Re: bug report

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.

On Thu, Nov 11, 2021 at 11:30 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 30 quoted lines
>
> Theodore Li <teddy.litheodore@gmail.com> writes:
>
> > Thank you for filling out a Git bug report!
> > Please answer the following questions to help us understand your issue.
> >
> > What did you do before the bug happened? (Steps to reproduce your issue)
> > After cloning a remote repository with the --no-checkout option and
> > executing git sparse-checkout init, the bug occurs with any
> > sparse-checkout command with the /* pattern (i.e. git sparse-checkout
> > set /*).
> >
> > What did you expect to happen? (Expected behavior)
> > The contents of .git/info/sparse-checkout and the output of git
> > sparse-checkout list should be '/*'
> >
> > What happened instead? (Actual behavior)
> > Instead, the output is the contents of the user's local root directory
> > (i.e. /bin, /boot, /cdrom, etc.).
>
> A blind guess, as I do not use sparse patterns, but perhaps you did
> not quote the "/*' pattern, i.e. you typed
>
>     $ git sparse-checkout set /*
>
> where you would have got a better behaviour if you typed
>
>     $ git sparse-checkout set "/*"
>
> ?
Paul Smith· Nov 12, 2021, 14:05 UTC · re: Theodore Li · lore

Re: bug report

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.

← back to recent threads