git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: BUG: mergetool fails on gitignore:d files

From
Jeff King <peff@peff.net>
Date
May 30, 2009, 21:54 UTC
Message-ID
<20090530215418.GA19241@coredump.intra.peff.net>
In-Reply-To
<e87cdfda0905300830t6b332533g9a4298f6b8005b9e@mail.gmail.com>
On Sat, May 30, 2009 at 05:30:52PM +0200, Erik Sandberg wrote:
Show 11 quoted lines
> If a version-controlled file is ignored by git, and a conflict arises
> on the file, and I use mergetool to resolve the conflict, then
> mergetool fails with a message like:
> 
> The following paths are ignored by one of your .gitignore files:
> a
> Use -f if you really want to add them.
> 
> The problem disappears if I edit the git-mergetool script to always
> pass -f to "git add", but I'm not sure if that's the right fix; I have
> a vague feeling that "git-update-index --add" could be more correct.

Actually, I think the problem is not in mergetool at all, but with the dir.c code underlying "git add". "git add" really should not be complaining, because you are not adding a new path at all, but are rather adding content to a tracked path.

So this should work (and does):
  $ echo file >.gitignore
  $ echo content >file
  $ git add -f file ;# need -f because we are adding new path
  $ echo more content >>file
  $ git add file ;# don't need -f; it is not actually an "other" file

This is handled under the hood by the COLLECT_IGNORED option to read_directory. When that code finds an ignored file, it checks the index to make sure it is not actually a tracked file. However, the test it uses does not take into account unmerged entries, and considers them to still be ignored. "git ls-files" uses a more elaborate test and gets the right answer. So I think we want to use the same test:

---
diff --git a/dir.c b/dir.c
index 0e6b752..bbfcb56 100644
--- a/dir.c
+++ b/dir.c
@@ -396,7 +396,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathna
 
 static struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)
 {
-	if (cache_name_pos(pathname, len) >= 0)
+	if (!cache_name_is_other(pathname, len))
 		return NULL;
 
 	ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc);
Previous: Markus HeidelbergNext: Jeff King
Message 3 of 5 in “BUG: mergetool fails on gitignore:d files”
  1. Erik SandbergMay 30, 2009
  2. Markus HeidelbergMay 30, 2009
  3. Jeff KingMay 30, 2009
  4. Jeff KingJun 1, 2009
  5. Junio C HamanoJun 1, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.