From: Yohei Endo <yoheie@gmail.com>
To: git@vger.kernel.org
Subject: Wrong gitignore precedence?
Date: Wed, 22 Apr 2015 15:05:58 +0900 [thread overview]
Message-ID: <20150422150558.6326cb6152a306f028fb6ad3@gmail.com> (raw)
Hello All,
I read the document of gitignore (http://git-scm.com/docs/gitignore),
and learned that $GIT_DIR/info/exclude has higher precedence than
the file specified by core.excludesfile.
But I noticed that patterns in core.excludesfile override patterns in
$GIT_DIR/info/exclude.
I tested as below:
1. Make a new git repository for test, and move into the repository.
$ git init testrepo
$ cd testrepo
2. Change core.excludesfile configuration.
$ touch ../core_excludesfile
$ git config core.excludesfile `realpath ../core_excludesfile`
3. Create test~. In each step I check if the file is ignored or not.
$ touch test~
4. See git status. In this case I expect that test~ should not be ignored.
$ git status --ignored
5. Change settings in .git/info/exclude.
$ echo '*~' > .git/info/exclude
6. See git status. In this case I expect that test~ should be ignored.
$ git status --ignored
7. Change settings in .git/info/exclude and core.excludesfile.
$ echo '*~' > ../core_excludesfile
$ echo '!*~' > .git/info/exclude
8. See git status. In this case I expect that test~ should not be ignored.
$ git status --ignored
9. Change settings in .git/info/exclude and core.excludesfile
$ echo '!*~' > ../core_excludesfile
$ echo '*~' > .git/info/exclude
10. See git status. In this case I expect that test~ should be ignored.
$ git status --ignored
Steps 4. and 6. worked as I expected, but 8. and 10. didn't.
I read the source code of Git, and found out the point that seems to
cause the problem.
In dir.c, setup_standard_excludes() adds patterns in .git/info/exclude to
the excludes list first, and patterns in core.excludesfile are added next.
In last_exclude_matching_from_list(), pattern is searched from the end of
the list, and the first matching pattern is used. Therefore the patterns
in core.excludesfile are used in precedence to .git/info/exclude.
To meet the precedence described in the document of gitignore, I guess
setup_standard_excludes() should be fixed so that patterns in
core.excludesfile are added to the list before those in
.git/info/ecdlude are added.
Thanks
--
遠藤 陽平 (Yohei Endo)
yoheie@gmail.com
next reply other threads:[~2015-04-22 6:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-22 6:05 Yohei Endo [this message]
2015-04-22 18:59 ` Wrong gitignore precedence? Junio C Hamano
2015-04-23 12:11 ` Yohei Endo
2015-04-22 21:39 ` [PATCH] ignore: info/exclude should trump core.excludesfile Junio C Hamano
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=20150422150558.6326cb6152a306f028fb6ad3@gmail.com \
--to=yoheie@gmail.com \
--cc=git@vger.kernel.org \
/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).