Subject: Re: Relative paths don't work in .gitignore as would be expected.

From: Junio C Hamano <[email-masked]>
Date: Tue, 03 Feb 2015 12:11:37 -0800

Stefan Beller <[email-masked]> writes:

> 2015-02-02 11:15 GMT-08:00 Junio C Hamano <[email-masked]>:
>
>> Isn't gitignore(5) documentation reasonably clear?
>> ...
>>  - A leading slash matches the beginning of the pathname. For
>>    example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
>>
>>> That's true, though you'd never (barely?) git version control an entire
>>> file system?
>>
>> When you have the entire file system under /.git, "/var/" still
>> would be the right way to spell a pattern to match ...
>> ... and lives in the root level of the filesystem (because of the
>> leading '/' anchors
>> the pattern to the same level as the file the pattern appears in,
>> i.e. /.gitignore) and no other place.
>
> ... Now I realize git treats the repository
> root literally as the root and hence absolute paths starting with "/"
> make totally sense inside git as the world stops for git outside its
> work directory.

Only when the pattern appears in .gitignore at the top-level of the
project, you can say: "/*.js" matches files with ".js" suffix at the
root level of the project because '/' means 'root'.

But that explanation breaks down for "t/.gitignore" that has entries
like "/.prove".  It is not excluding ".prove" at the top-level of
the project.  It is excluding those that appear at the same level as
that ignore file in question lives in, i.e. the "t/" directory.  It
excludes "t/.prove", it excludes neither ".prove" at the top-level
nor "t/tt/ttt/.prove".

In hindsight, using '/' prefix as a way to anchor the patter to the
same directory the .gitignore file appears in was suboptimal,
exactly because it would invite the above reaction.  But I do not
know if using "./" as the prefix to denote the same thing would have
been better.