git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <stefanbeller@gmail.com>
Cc: "\/#!\/JoePea" <trusktr@gmail.com>, git@vger.kernel.org
Subject: Re: Relative paths don't work in .gitignore as would be expected.
Date: Mon, 02 Feb 2015 11:15:46 -0800	[thread overview]
Message-ID: <xmqqsieot999.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <54CF11CA.6000308@gmail.com> (Stefan Beller's message of "Sun, 01 Feb 2015 21:57:30 -0800")

Stefan Beller <stefanbeller@gmail.com> writes:

> On 01.02.2015 14:51, /#!/JoePea wrote:
>> I have this in my .gitignore:
>> 
>>   ./*.js
>> 
>> I would expect that to cause git to ignore .js files in the same
>> folder as .gitignore, but it doesn't do anything. However, this works:
>> 
>>   /*.js
>> 
>> I'm not sure what this actually means because a leading slash is the
>> root of some filesystem, 

Isn't gitignore(5) documentation reasonably clear?

 - If the pattern ends with a slash, it is removed for the purpose
   of the following description, but it would only find a match with
   a directory. In other words, foo/ will match a directory foo and
   paths underneath it, but will not match a regular file or a
   symbolic link foo (this is consistent with the way how pathspec
   works in general in Git).

 - If the pattern does not contain a slash /, Git treats it as a
   shell glob pattern and checks for a match against the pathname
   relative to the location of the .gitignore file (relative to the
   toplevel of the work tree if not from a .gitignore file).

 - 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 only a directory
(because of the trailing '/') whose name matches 'var' 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.

> (from man gitignore, though reading that and not finding a './' it may
> need improvement

We do not allow relative pathname traversal with "." or "..", do we?

I would be very hesitant to special case "./*.js" to mean "*.js
files in the same directory as .gitignore appears", as I think it
risks intelligent readers to infer "../foo/*.js" or "../*.js" would
take effect, when placed in "bar/.gitignore".  A design that spreads
an incorrect assumption/expectation is not a good one, I would have
to say.

  reply	other threads:[~2015-02-02 19:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-01 22:51 Relative paths don't work in .gitignore as would be expected /#!/JoePea
2015-02-02  5:57 ` Stefan Beller
2015-02-02 19:15   ` Junio C Hamano [this message]
2015-02-03  2:18     ` Stefan Beller
2015-02-03 20:11       ` Junio C Hamano
     [not found] <CAKU1PAXgofoOqtFMrLYyRoFqNp3Poj-PO35eh1ukxR=h29FPfQ@mail.gmail.com>
2015-02-12  6:28 ` /#!/JoePea

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqsieot999.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=stefanbeller@gmail.com \
    --cc=trusktr@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.
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 NNTP newsgroup(s).