threads / bug / 25244

.gitignore Bug Report on the behavior of *

Subject: .gitignore Bug Report on the behavior of *

## tl;dr

5 messages between Sep 25, 2010 and Sep 25, 2010.

replies: 4people: 4as markdown or json

Seth Robertson· Sep 25, 2010, 19:23 UTC · lore

I'm not sure if this is a documentation bug, an actual bug, or my mis-interpretation of what is supposed to happen, however, this behavior was not expected by other people as well. This was tested using git 1.7.2.3 and 1.7.3

My sample configuration: ---------------------------------------------------------------------- mkdir foo; cd foo; git init; echo A > A; mkdir B; echo B > B/B git add .; git commit -a -m "initial" ----------------------------------------------------------------------

# Properly shows X and B/XX as untracked, as I expected echo X > X; echo XX > B/XX; git status

# I expected B/XX to show up as untracked rm -f .gitignore B/.gitignore echo '*' > .gitignore; echo '!*' > B/.gitignore; git status

# I expected B/XX to show up as untracked rm -f .gitignore B/.gitignore echo '/*' > .gitignore; git status

# Works as I expected rm -f .gitignore B/.gitignore echo '/*X' > .gitignore; git status

# Works as I expected rm -f .gitignore B/.gitignore echo '*X' > .gitignore; echo '!*X' > B/.gitignore; git status

# Works as I expected rm -f .gitignore B/.gitignore echo -e '/*\n!/B' > .gitignore; git status

					-Seth Robertson
Johannes Sixt· Sep 25, 2010, 20:03 UTC · re: Seth Robertson · lore

Re: .gitignore Bug Report on the behavior of *

On Samstag, 25. September 2010, Seth Robertson wrote:
Show 6 quoted lines
> # Properly shows X and B/XX as untracked, as I expected
> echo X > X; echo XX > B/XX; git status
>
> # I expected B/XX to show up as untracked
> rm -f .gitignore B/.gitignore
> echo '*' > .gitignore; echo '!*' > B/.gitignore; git status
You should update your expectations to match what you got. ;-)

To show why your expectations are wrong, consider a *huge* and *deep* directory with thousands and thousands of subdirectories, call it "usr", that should be ignored. The .gitignore at the top-level would just say:

  /usr

Do you really expect git to walk down this ignored directory, just to make double-sure that really, really down there does nowhere exist a .gitignore that says "oh, wait, don't ignore *this* file"?

-- Hannes
Seth Robertson· Sep 25, 2010, 20:40 UTC · re: Johannes Sixt · lore

[PATCH] Re: .gitignore Bug Report on the behavior of *

In message <201009252203.48820.j6t@kdbg.org>, Johannes Sixt writes:
    On Samstag, 25. September 2010, Seth Robertson wrote:
    > # Properly shows X and B/XX as untracked, as I expected
    > echo X > X; echo XX > B/XX; git status
    >
    > # I expected B/XX to show up as untracked
    > rm -f .gitignore B/.gitignore
    > echo '*' > .gitignore; echo '!*' > B/.gitignore; git status
    You should update your expectations to match what you got. ;-)
    To show why your expectations are wrong, consider a *huge* and
    *deep* directory with thousands and thousands of subdirectories,
    call it "usr", that should be ignored. The .gitignore at the
    top-level would just say:
      /usr
    Do you really expect git to walk down this ignored directory, just to make
    double-sure that really, really down there does nowhere exist a .gitignore
    that says "oh, wait, don't ignore *this* file"?

Hmm. No, not really, but having a .gitignore in a directory which has tracked git files in it seems somehow different, and at least to me the documentation of .gitignore suggests a different algorithm. How about this for a documentation patch?

Signed-off-by: Seth Robertson <in-gitvger@baka.org>
----------------------------------------------------------------------
diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 7dc2e8b..4f825d8 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -33,6 +33,8 @@ precedence, the last matching pattern decides the outcome):
    as the path, or in any parent directory, with patterns in the
    higher level files (up to the toplevel of the work tree) being overridden
    by those in lower level files down to the directory containing the file.
+   Any pattern causing a directory to be ignored will cause
+   any `.gitignore` file under that dirctory to be ignored.
    These patterns match relative to the location of the
    `.gitignore` file.  A project normally includes such
    `.gitignore` files in its repository, containing patterns for
Ævar Arnfjörð Bjarmason· Sep 25, 2010, 20:53 UTC · re: Johannes Sixt · lore

Re: .gitignore Bug Report on the behavior of *

On Sat, Sep 25, 2010 at 20:03, Johannes Sixt <j6t@kdbg.org> wrote:
Show 19 quoted lines
> On Samstag, 25. September 2010, Seth Robertson wrote:
>> # Properly shows X and B/XX as untracked, as I expected
>> echo X > X; echo XX > B/XX; git status
>>
>> # I expected B/XX to show up as untracked
>> rm -f .gitignore B/.gitignore
>> echo '*' > .gitignore; echo '!*' > B/.gitignore; git status
>
> You should update your expectations to match what you got. ;-)
>
> To show why your expectations are wrong, consider a *huge* and *deep*
> directory with thousands and thousands of subdirectories, call it "usr", that
> should be ignored. The .gitignore at the top-level would just say:
>
>  /usr
>
> Do you really expect git to walk down this ignored directory, just to make
> double-sure that really, really down there does nowhere exist a .gitignore
> that says "oh, wait, don't ignore *this* file"?

That wouldn't be so expensive if the expectation that the .gitignore in /usr would only be considered if it had already been commited. Then we'd just have to check if we have a tree for /usr, and whether there's a gitignore there.

But doing this in the top-level .gitignore if possible is the best solution.

Sverre Rabbelier· Sep 25, 2010, 23:27 UTC · re: Johannes Sixt · lore

Re: .gitignore Bug Report on the behavior of *

Heya,
<threadjacking rant>
On Sat, Sep 25, 2010 at 22:03, Johannes Sixt <j6t@kdbg.org> wrote:
> Do you really expect git to walk down this ignored directory, just to make
> double-sure that really, really down there does nowhere exist a .gitignore
> that says "oh, wait, don't ignore *this* file"?

Yet when I (recursively for all files) 'git update-index --assume-unchanged some-dir' it will still looking at all the bloody .gitignore making it slow as moleasses.

</rant>

Of course, the above is an insane setup with a .gitignore file in each and every directory. But it would be so nice if git Just Worked even in insane cases!

-- 
Cheers,

Sverre Rabbelier

← back to recent threads