{"thread":{"id":"19606","subject":"BUG: mergetool fails on gitignore:d files","startedAt":"2009-05-30T15:30:52Z","lastAt":"2009-06-01T02:04:01Z","messageCount":5,"participants":["Erik Sandberg","Markus Heidelberg","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"115088","messageId":"e87cdfda0905300830t6b332533g9a4298f6b8005b9e@mail.gmail.com","threadId":"19606","inReplyTo":null,"subject":"BUG: mergetool fails on gitignore:d files","fromName":"Erik Sandberg","fromEmail":"mandolaerik@gmail.com","sentAt":"2009-05-30T15:30:52Z","receivedAt":"2009-05-30T15:30:52Z","isPatch":false,"sender":{"key":"mandolaerik@gmail.com","avatar":null},"body":"If a version-controlled file is ignored by git, and a conflict arises\non the file, and I use mergetool to resolve the conflict, then\nmergetool fails with a message like:\n\nThe following paths are ignored by one of your .gitignore files:\na\nUse -f if you really want to add them.\n\nThe problem disappears if I edit the git-mergetool script to always\npass -f to \"git add\", but I'm not sure if that's the right fix; I have\na vague feeling that \"git-update-index --add\" could be more correct.\n\nI have attached a script that reproduces the problem.\n"},{"id":"115091","messageId":"200905301838.09081.markus.heidelberg@web.de","threadId":"19606","inReplyTo":"e87cdfda0905300830t6b332533g9a4298f6b8005b9e@mail.gmail.com","subject":"Re: BUG: mergetool fails on gitignore:d files","fromName":"Markus Heidelberg","fromEmail":"markus.heidelberg@web.de","sentAt":"2009-05-30T16:38:08Z","receivedAt":"2009-05-30T16:38:08Z","isPatch":false,"sender":{"key":"markus.heidelberg@web.de","avatar":"https://avatars.githubusercontent.com/u/6334512?v=4"},"body":"Erik Sandberg, 30.05.2009:\n> If a version-controlled file is ignored by git, and a conflict arises\n> on the file, and I use mergetool to resolve the conflict, then\n> mergetool fails with a message like:\n> \n> The following paths are ignored by one of your .gitignore files:\n> a\n> Use -f if you really want to add them.\n> \n> The problem disappears if I edit the git-mergetool script to always\n> pass -f to \"git add\", but I'm not sure if that's the right fix; I have\n> a vague feeling that \"git-update-index --add\" could be more correct.\n> \n> I have attached a script that reproduces the problem.\n\nThe script would have been more readable if you haven't given both the\nfile and the branch name as well as the file content and the commit\nmessage the same string \"a\".\n\nApart from that I wonder if your real repo also ignores the file 'a'\nalthough it is tracked in every branch. If so, why do you ignore it?\n\nMarkus\n"},{"id":"115098","messageId":"20090530215418.GA19241@coredump.intra.peff.net","threadId":"19606","inReplyTo":"e87cdfda0905300830t6b332533g9a4298f6b8005b9e@mail.gmail.com","subject":"Re: BUG: mergetool fails on gitignore:d files","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-05-30T21:54:18Z","receivedAt":"2009-05-30T21:54:18Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, May 30, 2009 at 05:30:52PM +0200, Erik Sandberg wrote:\n\n> If a version-controlled file is ignored by git, and a conflict arises\n> on the file, and I use mergetool to resolve the conflict, then\n> mergetool fails with a message like:\n> \n> The following paths are ignored by one of your .gitignore files:\n> a\n> Use -f if you really want to add them.\n> \n> The problem disappears if I edit the git-mergetool script to always\n> pass -f to \"git add\", but I'm not sure if that's the right fix; I have\n> a vague feeling that \"git-update-index --add\" could be more correct.\n\nActually, I think the problem is not in mergetool at all, but with the\ndir.c code underlying \"git add\". \"git add\" really should not be\ncomplaining, because you are not adding a new path at all, but are\nrather adding content to a tracked path.\n\nSo this should work (and does):\n\n  $ echo file >.gitignore\n  $ echo content >file\n  $ git add -f file ;# need -f because we are adding new path\n  $ echo more content >>file\n  $ git add file ;# don't need -f; it is not actually an \"other\" file\n\nThis is handled under the hood by the COLLECT_IGNORED option to\nread_directory. When that code finds an ignored file, it checks the\nindex to make sure it is not actually a tracked file. However, the test\nit uses does not take into account unmerged entries, and considers them\nto still be ignored. \"git ls-files\" uses a more elaborate test and gets\nthe right answer. So I think we want to use the same test:\n\n---\ndiff --git a/dir.c b/dir.c\nindex 0e6b752..bbfcb56 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -396,7 +396,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathna\n \n static struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)\n {\n-\tif (cache_name_pos(pathname, len) >= 0)\n+\tif (!cache_name_is_other(pathname, len))\n \t\treturn NULL;\n \n \tALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc);\n"},{"id":"115173","messageId":"20090601020349.GA32740@coredump.intra.peff.net","threadId":"19606","inReplyTo":"20090530215418.GA19241@coredump.intra.peff.net","subject":"Re: BUG: mergetool fails on gitignore:d files","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-06-01T02:03:50Z","receivedAt":"2009-06-01T02:03:50Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, May 30, 2009 at 05:54:18PM -0400, Jeff King wrote:\n\n> diff --git a/dir.c b/dir.c\n> index 0e6b752..bbfcb56 100644\n> --- a/dir.c\n> +++ b/dir.c\n> @@ -396,7 +396,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathna\n>  \n>  static struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)\n>  {\n> -\tif (cache_name_pos(pathname, len) >= 0)\n> +\tif (!cache_name_is_other(pathname, len))\n>  \t\treturn NULL;\n>  \n>  \tALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc);\n\nI was all set to write a test for this and re-submit, but you seem to\nhave beat me to it. Thanks. :)\n\n-Peff\n"},{"id":"115175","messageId":"7vk53wogku.fsf@alter.siamese.dyndns.org","threadId":"19606","inReplyTo":"20090530215418.GA19241@coredump.intra.peff.net","subject":"Re: BUG: mergetool fails on gitignore:d files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-06-01T02:04:01Z","receivedAt":"2009-06-01T02:04:01Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Actually, I think the problem is not in mergetool at all, but with the\n> dir.c code underlying \"git add\". \"git add\" really should not be\n> complaining, because you are not adding a new path at all, but are\n> rather adding content to a tracked path.\n\nCorrect, and thanks.\n"}]}