# git sparse checkout exclusions not working?

3 messages from 2011-04-27 to 2011-04-30. Participants: skillzero@gmail.com, Nguyen Thai Ngoc Duy.
Thread: https://gitlist.dev/t/27202

## skillzero@gmail.com, 2011-04-27 16:35

Subject: git sparse checkout exclusions not working?
Message-ID: <BANLkTinPg_jaxiF8yFtnf4BrT4fx-BQ=+A@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTinPg_jaxiF8yFtnf4BrT4fx-BQ%3D%2BA%40mail.gmail.com

```
It seems like ! patterns in the sparse-checkout file don't exclude
individual files in a directory. Here's what I did:

git init
mkdir test1
echo "test1" test1/file1.txt
echo "test2" test1/file2.txt
echo "test3" test1/file3.txt
mkdir test2
echo "test2" test2/file1.txt
echo "test2" test2/file2.txt
echo "test2" test2/file3.txt
git add .
git commit -m "test"
git config core.sparseCheckout true

echo 'test1/' > .git/info/sparse-checkout
echo '!test1/file2.txt' >> .git/info/sparse-checkout
git checkout master --

The end result is like this:

test1
test1/file1.txt
test1/file2.txt
test1/file3.txt

The "test1" directory was included, but "test1/file2.txt" wasn't
excluded even though I added a ! pattern for it. The test2 directory
was correctly excluded so that makes me think sparse was working in
general, but just not respecting the ! pattern in this case.

Is this a bug or am I doing something wrong?

```

## Nguyen Thai Ngoc Duy, 2011-04-29 12:10

Subject: Re: git sparse checkout exclusions not working?
Message-ID: <BANLkTi=m4hcs7pVgn0rkQktmZaqK_ORxaA@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTi%3Dm4hcs7pVgn0rkQktmZaqK_ORxaA%40mail.gmail.com
In-Reply-To: <BANLkTinPg_jaxiF8yFtnf4BrT4fx-BQ=+A@mail.gmail.com>

```
On Wed, Apr 27, 2011 at 11:35 PM,  <skillzero@gmail.com> wrote:
> It seems like ! patterns in the sparse-checkout file don't exclude
> individual files in a directory. Here's what I did:
>
> ...
>
> The "test1" directory was included, but "test1/file2.txt" wasn't
> excluded even though I added a ! pattern for it. The test2 directory
> was correctly excluded so that makes me think sparse was working in
> general, but just not respecting the ! pattern in this case.
>
> Is this a bug or am I doing something wrong?

I can reproduce it too. It looks like a regression from
whole-directory matching. If a directory is matched, all files inside
are considered "in". Let's see if I can come up with something this
weekend.
-- 
Duy

```

## Nguyen Thai Ngoc Duy, 2011-04-30 10:06

Subject: Re: git sparse checkout exclusions not working?
Message-ID: <BANLkTikU_Qjs9jo2MmPdbwVNBj1V9vJJSw@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTikU_Qjs9jo2MmPdbwVNBj1V9vJJSw%40mail.gmail.com
In-Reply-To: <BANLkTi=m4hcs7pVgn0rkQktmZaqK_ORxaA@mail.gmail.com>

```
On Fri, Apr 29, 2011 at 7:10 PM, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> On Wed, Apr 27, 2011 at 11:35 PM,  <skillzero@gmail.com> wrote:
>> It seems like ! patterns in the sparse-checkout file don't exclude
>> individual files in a directory. Here's what I did:
>>
>> ...
>>
>> The "test1" directory was included, but "test1/file2.txt" wasn't
>> excluded even though I added a ! pattern for it. The test2 directory
>> was correctly excluded so that makes me think sparse was working in
>> general, but just not respecting the ! pattern in this case.
>>
>> Is this a bug or am I doing something wrong?
>
> I can reproduce it too. It looks like a regression from
> whole-directory matching. If a directory is matched, all files inside
> are considered "in". Let's see if I can come up with something this
> weekend.

sparse checkout rules are not the only ones falling for this trap.
.gitignore has the same problem:

pclouds@do /tmp/z $ cat .gitignore
t
!t/1
pclouds@do /tmp/z $ ls t
1  2  3
pclouds@do /tmp/z $ git init
Initialized empty Git repository in /tmp/z/.git/
pclouds@do /tmp/z $ ~/w/git/git add .
pclouds@do /tmp/z $ git ls-files
.gitignore

I wonder if we can convert struct exclude to struct pathspec and solve
the problem all at the same place. Granted .gitignore's '*' is
different from pathspec's '*' (ie. FNM_PATHNAME vs no flag to
fnmatch), but struct pathspec can be taught to do it both ways and the
pathspec magic can expose FNM_PATHNAME to users too.
-- 
Duy

```
