git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Philip Oakley <philipoakley@iee.email>
To: Paul Jackson <mailnew4ster@gmail.com>, git@vger.kernel.org
Subject: Re: gitignore + commit with excludes = bug
Date: Tue, 4 May 2021 13:55:26 +0100	[thread overview]
Message-ID: <e4c3d482-03b4-141c-e47b-cb3e175da3ab@iee.email> (raw)
In-Reply-To: <CAGKR6vKwojz8_bs9oRasQPCamZJ-4mrmBKBZQCJKhX=8w+SzDg@mail.gmail.com>

Hi Paul,

On 01/05/2021 19:37, Paul Jackson wrote:
> Hello,
>
> I stumbled upon what I believe is a bug in git.
> See the following reproduction steps:
>
> mkdir test
> cd test
> git init
> echo 1 > ignored
> echo 1 > not-ignored
> echo ignored > .gitignore
> git add -A -- ':!ignored' || echo 'ERROR!!!'
>
> In these steps, I ignore the "ignored" file twice - first time in
> .gitignore, and second time in the "git add" command. I didn't expect
> this to be a problem, but I'm getting the following error message:
>
> The following paths are ignored by one of your .gitignore files:
> ignored
>
> It looks as if git thinks I wanted to include, not exclude "ignored"
> in "git add".
I was intrigued by this. The man pages can be hard to decipher, and it
may be an 'as designed' feature, but still not intuitive

It took a while to find the relevant parts of the man pages.

The `-A` option of `add` is under
https://git-scm.com/docs/git-add#Documentation/git-add.txt---no-ignore-removal
which has caveats for whether a pathspec is given.

The `exclude` magic pathspec is under
https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-exclude
and again has caveats and a double negative regarding whether the
`exclude` pathspec counts as a path spec.

I _think_ that it is saying that the `exclude` pathspec is ignored for
the purpose of the `-A` (all) condition for git add.
The `git add` then decides that the the set of files to be added is just
the single 'not-ignored' file, having already used the `.gitignore` to
"exclude" the 'ignored' file from that set of files to add.

Now your "exclude" pathspec comes into play and tries remove the named
"exclude" file from the set, and doesn't find it. Or at least that's how
I read it as a plausible explanation. That said, I haven't looked at the
code, so that could be all wrong.

A possible place to start is the
https://gitlab.cecs.anu.edu.au/comp8440/git/commit/ef79b1f8704668a6cdf4278f9255e03ca785bfb4
patch (google..) or
https://github.com/git/git/commit/ef79b1f8704668a6cdf4278f9255e03ca785bfb4

Also locate where the error message is generated. It maybe just a warning.

--
Philip





  reply	other threads:[~2021-05-04 12:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-01 18:37 Paul Jackson
2021-05-04 12:55 ` Philip Oakley [this message]
2021-05-04 14:06   ` Matheus Tavares
2021-05-09  6:21     ` Paul Jackson
2021-05-10 16:20       ` Philip Oakley
2021-05-10 19:27     ` Elijah Newren
2021-05-10 19:37       ` Matheus Tavares Bernardino
2021-05-10 22:34         ` Elijah Newren
2021-05-11  2:23           ` Matheus Tavares Bernardino

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=e4c3d482-03b4-141c-e47b-cb3e175da3ab@iee.email \
    --to=philipoakley@iee.email \
    --cc=git@vger.kernel.org \
    --cc=mailnew4ster@gmail.com \
    --subject='Re: gitignore + commit with excludes = bug' \
    /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

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.version-control.git
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.version-control.git
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git