From: Danial Alihosseini <danial.alihosseini@gmail.com>
To: Derrick Stolee <stolee@gmail.com>
Cc: Jeff King <peff@peff.net>, Derrick Stolee <dstolee@microsoft.com>,
git@vger.kernel.org
Subject: Re: git 2.34.0: Behavior of `**` in gitignore is different from previous versions.
Date: Fri, 19 Nov 2021 07:31:45 +0330 [thread overview]
Message-ID: <CACLOEFbY3LwMa2uhc=9jmcGFf0mvWzEM=YityLyFcuGWXVmqbw@mail.gmail.com> (raw)
In-Reply-To: <2bd2269f-c7f1-7afb-7052-48fac148dffd@gmail.com>
Thanks for your follow-up.
I wanted to ignore all files in the "data" folder except ".txt" ones.
As mentioned in the gitignore doc, there should be a difference
between "**" and "**/".
> A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth.
and,
>
> A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
and also,
>
> It is not possible to re-include a file if a parent directory of that file is excluded.
So, I excluded all files by "data/**", re-included just directories
(at any depth) by "!data/**/" and, re-included ".txt" files (at any
depth) by "!data/**/*.txt".
However, if I wanted to re-include a directory and all of its
contents, I could use something like "!data/data1/**", without
trailing slash.
As I see, there is no separation between "**" and "**/" in the current version.
I think there is another point that the previous behavior test case
should be like this:
test_expect_success 'directories and ** matches' '
cat >.gitignore <<-\EOF &&
data/**
!data/**/
!data/**/*.txt
EOF
git check-ignore file \
data/file data/data1/file1 data/data1/file1.txt \
data/data2/file2 data/data2/file2.txt >actual &&
cat >expect <<-\EOF &&
data/file
data/data1/file1
data/data2/file2
EOF
test_cmp expect actual
'
Thanks
Danial
On Fri, Nov 19, 2021 at 1:40 AM Derrick Stolee <stolee@gmail.com> wrote:
>
> On 11/18/2021 12:04 PM, Jeff King wrote:
> > On Thu, Nov 18, 2021 at 08:11:04PM +0330, Danial Alihosseini wrote:
> >
> >> What did you do before the bug happened? (Steps to reproduce your issue)
> >> Consider the following project structure
> >> - data
> >> - data1
> >> - file1
> >> - file1.txt
> >> - data2
> >> - file2
> >> - file2.txt
> >> - .gitignore
> >>
> >>
> >> `.gitignore` is as follows:
> >> ```
> >> data/**
> >> !data/**/
> >> !data/**/*.txt
> >> ```
> >> What did you expect to happen? (Expected behavior)
> >>
> >> I expect all files in `data` folder to be ignored except `.txt` files.
> >>
> >> What happened instead? (Actual behavior)
> >>
> >> `file1` and `file2` are not ignored.
> >> Here is the `check-ignore` output:
> >> ```
> >> $ git check-ignore -v data/data1/file1
> >> .gitignore:2:!/data/**/ data/data1/file1
> >> ```
> >
> > Thanks for an easy reproduction. It looks like this changed in
> > f6526728f9 (dir: select directories correctly, 2021-09-24). Author cc'd.
>
> Thanks for the bisect and CC.
>
> > The key thing seems to be that the second line of your .gitignore should
> > match only directories (because of the trailing slash), but no longer
> > does.
>
> Doesn't "matching only directories" mean it would match everything
> within that directory? (It also means that "data/file" is not matched,
> which is still correct.)
>
> My interpretation of these patterns is that everything in data/data1/
> and data/data2/ should not be ignored, making it seem like the change
> fixed a bug (it definitely changed behavior).
>
> Just for extra clarity, this test currently passes:
>
> test_expect_success 'directories and ** matches' '
> cat >.gitignore <<-\EOF &&
> data/**
> !data/**/
> !data/**/*.txt
> EOF
> git check-ignore file \
> data/file data/data1/file1 data/data1/file1.txt \
> data/data2/file2 data/data2/file2.txt >actual &&
> cat >expect <<-\EOF &&
> data/file
> EOF
> test_cmp expect actual
> '
>
> but the previous behavior would have passed this test:
>
> test_expect_success 'directories and ** matches' '
> cat >.gitignore <<-\EOF &&
> data/**
> !data/**/
> !data/**/*.txt
> EOF
> git check-ignore file \
> data/file data/data1/file1.txt \
> data/data2/file2.txt >actual &&
> cat >expect <<-\EOF &&
> data/file
> EOF
> test_cmp expect actual
> '
>
> I seek more clarity on this. Specifically: if we match a directory
> then should we not also match the contents within?
>
> Thanks,
> -Stolee
next prev parent reply other threads:[~2021-11-19 4:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 16:41 git 2.34.0: Behavior of `**` in gitignore is different from previous versions Danial Alihosseini
2021-11-18 17:04 ` Jeff King
2021-11-18 22:09 ` Derrick Stolee
2021-11-19 4:01 ` Danial Alihosseini [this message]
2021-11-19 14:51 ` Derrick Stolee
2021-11-19 17:06 ` Danial Alihosseini
2021-11-19 20:05 ` Johannes Sixt
2021-11-19 20:33 ` Derrick Stolee
2021-11-19 20:57 ` Ævar Arnfjörð Bjarmason
2021-11-20 22:41 ` Chris Torek
2021-11-21 0:46 ` Junio C Hamano
2021-11-23 12:21 ` Philip Oakley
2021-11-23 21:13 ` Danial Alihosseini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACLOEFbY3LwMa2uhc=9jmcGFf0mvWzEM=YityLyFcuGWXVmqbw@mail.gmail.com' \
--to=danial.alihosseini@gmail.com \
--cc=dstolee@microsoft.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=stolee@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).