{"thread":{"id":"24705","subject":"[RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","startedAt":"2010-08-11T07:03:56Z","lastAt":"2010-08-29T18:27:22Z","messageCount":28,"participants":["Greg Brockman","Ævar Arnfjörð Bjarmason","Junio C Hamano","Jens Lehmann","Matthieu Moy","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"147723","messageId":"1281510236-8103-1-git-send-email-gdb@mit.edu","threadId":"24705","inReplyTo":null,"subject":"[RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-11T07:03:56Z","receivedAt":"2010-08-11T07:03:56Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":"Currently, 'git add' will complain about excluded files, even if they\nare already tracked:\n\n$ mkdir dir && touch dir/file && cat > .gitignore <<< dir\n$ git add -f dir/file\n$ git status\n  ...\n  new file:   dir/file\n  ...\n$ git add dir/file\nThe following paths are ignored by one of your .gitignore files:\ndir\nUse -f if you really want to add them.\nfatal: no files added\n\nThis commit changes 'git add' to disregard excludes for tracked files\nwhose paths are explicitly specified on the command-line.  So in the\nabove example, 'git add dir/file' no longer requires a '-f'.  However,\n'git add dir' does.\n\nSigned-off-by: Greg Brockman <gdb@mit.edu>\n---\n builtin/add.c |   19 +++++++++++++++++++\n 1 files changed, 19 insertions(+), 0 deletions(-)\n\nWhat do people think of this behavior?  My motivation in writing this patch is\nthat I sometimes track files in an ignored directory, and it can be cumbersome\nto remember to pass '-f' when adding them.  Related commands such as 'git add -p'\nand 'git commit -a' do not require a '-f' in this case, so it feels natural to me not\nto require extra user confirmation when an explicit path has been provided.\n\nAs always, thanks in advance for your comments.\n\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 56a4e0a..46b1fdb 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -423,8 +423,27 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t\t/* Set up the default git porcelain excludes */\n \t\tmemset(&dir, 0, sizeof(dir));\n \t\tif (!ignored_too) {\n+\t\t\tconst char **tracked = xmalloc(sizeof(char *) * (argc + 1));\n+\t\t\tconst char **p;\n+\t\t\tint tidx = 0;\n+\t\t\tint pidx = 0;\n+\n \t\t\tdir.flags |= DIR_COLLECT_IGNORED;\n \t\t\tsetup_standard_excludes(&dir);\n+\n+\t\t\tfor (p = pathspec; *p; p++) {\n+\t\t\t\tif ((*p)[0] && cache_name_exists(*p, strlen(*p), 0))\n+\t\t\t\t\ttracked[tidx++] = *p;\n+\t\t\t\telse\n+\t\t\t\t\tpathspec[pidx++] = *p;\n+\t\t\t}\n+\n+\t\t\ttracked[tidx] = NULL;\n+\t\t\tpathspec[pidx] = NULL;\n+\t\t\texit_status |= add_files_to_cache(prefix, tracked, flags);\n+\t\t\t/* All files were tracked */\n+\t\t\tif (pidx == 0)\n+\t\t\t\tgoto finish;\n \t\t}\n \n \t\t/* This picks up the paths that are not tracked */\n-- \n1.7.0.4\n"},{"id":"147759","messageId":"AANLkTikPSR36SdUuzWsXxZsy9jsKOnp=_iz43BF-6nYe@mail.gmail.com","threadId":"24705","inReplyTo":"1281510236-8103-1-git-send-email-gdb@mit.edu","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-08-11T12:24:02Z","receivedAt":"2010-08-11T12:24:02Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Wed, Aug 11, 2010 at 07:03, Greg Brockman <gdb@mit.edu> wrote:\n> Currently, 'git add' will complain about excluded files, even if they\n> are already tracked:\n>\n> $ mkdir dir && touch dir/file && cat > .gitignore <<< dir\n> $ git add -f dir/file\n> $ git status\n>  ...\n>  new file:   dir/file\n>  ...\n> $ git add dir/file\n> The following paths are ignored by one of your .gitignore files:\n> dir\n> Use -f if you really want to add them.\n> fatal: no files added\n>\n> This commit changes 'git add' to disregard excludes for tracked files\n> whose paths are explicitly specified on the command-line.  So in the\n> above example, 'git add dir/file' no longer requires a '-f'.  However,\n> 'git add dir' does.\n>\n> Signed-off-by: Greg Brockman <gdb@mit.edu>\n> ---\n>  builtin/add.c |   19 +++++++++++++++++++\n>  1 files changed, 19 insertions(+), 0 deletions(-)\n>\n> What do people think of this behavior?  My motivation in writing this patch is\n> that I sometimes track files in an ignored directory, and it can be cumbersome\n> to remember to pass '-f' when adding them.  Related commands such as 'git add -p'\n> and 'git commit -a' do not require a '-f' in this case, so it feels natural to me not\n> to require extra user confirmation when an explicit path has been provided.\n\nI like it. I keep a /etc in git with .gitignore \"*\". This would help a\nlot for use cases like that. Explicitly specifying a full path should\noverride gitignore IMO.\n\nI think with some tests this should be ready to go.\n"},{"id":"147799","messageId":"7vmxstypot.fsf@alter.siamese.dyndns.org","threadId":"24705","inReplyTo":"1281510236-8103-1-git-send-email-gdb@mit.edu","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-08-11T18:22:42Z","receivedAt":"2010-08-11T18:22:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Greg Brockman <gdb@MIT.EDU> writes:\n\n> Currently, 'git add' will complain about excluded files, even if they\n> are already tracked:\n>\n> $ mkdir dir && touch dir/file && cat > .gitignore <<< dir\n> $ git add -f dir/file\n> $ git status\n>   ...\n>   new file:   dir/file\n>   ...\n> $ git add dir/file\n> The following paths are ignored by one of your .gitignore files:\n> dir\n> Use -f if you really want to add them.\n> fatal: no files added\n\nThanks.\n\nI think it is reasonble if we don't complain in this particular case.\n\nWhat should happen if the user did these instead, after adding \"dir\" as an\nignored entry, and adding dir/file but not dir/untracked to the index?\n\n (1)    git add dir/file dir/untracked    ; explicitly named\n (2)    git add dir/*\t\t\t  ; have shell glob--same as (1)\n (3)    git add \"dir/*\"                   ; have git glob\n (4)    git add dir                       ; have git recurse\n\nWhat does your code do?\n"},{"id":"147807","messageId":"AANLkTinbMHDa6P8N4Mne34rMkmzzbrpm0osd2LRbr-Jv@mail.gmail.com","threadId":"24705","inReplyTo":"7vmxstypot.fsf@alter.siamese.dyndns.org","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-11T18:36:13Z","receivedAt":"2010-08-11T18:36:13Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":"> What should happen if the user did these instead, after adding \"dir\" as an\n> ignored entry, and adding dir/file but not dir/untracked to the index?\n>\n>  (1)    git add dir/file dir/untracked    ; explicitly named\n>  (2)    git add dir/*                     ; have shell glob--same as (1)\n>  (3)    git add \"dir/*\"                   ; have git glob\n>  (4)    git add dir                       ; have git recurse\n\nIn all four cases, the output I get is:\n\"\"\"\nThe following paths are ignored by one of your .gitignore files:\ndir\nUse -f if you really want to add them.\nfatal: no files added\n\"\"\"\n\nNote that this is also the output if you run\n\n(5) rm dir/untracked && git add \"dir/*\"\n\nGreg\n"},{"id":"147833","messageId":"4C630D23.5090001@web.de","threadId":"24705","inReplyTo":"AANLkTikPSR36SdUuzWsXxZsy9jsKOnp=_iz43BF-6nYe@mail.gmail.com","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2010-08-11T20:50:43Z","receivedAt":"2010-08-11T20:50:43Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Are we talking about two different issues here?\n\nAm 11.08.2010 14:24, schrieb Ævar Arnfjörð Bjarmason:\n> On Wed, Aug 11, 2010 at 07:03, Greg Brockman <gdb@mit.edu> wrote:\n>> Currently, 'git add' will complain about excluded files, even if they\n>> are already tracked:\n\nI'm all for not complaining when adding an ignored file that is\nalready tracked, as the user already told us he wants to track\nthis file despite .gitignore.\n\n>> ... so it feels natural to me not\n>> to require extra user confirmation when an explicit path has been provided.\n> \n> I like it. I keep a /etc in git with .gitignore \"*\". This would help a\n> lot for use cases like that. Explicitly specifying a full path should\n> override gitignore IMO.\n\nI'm not so sure if we should silently add ignored files just because\nthey appear on the command line. For me having to force the first time\nI do a \"git add\" for an otherwise ignored file looks like a feature.\n"},{"id":"147853","messageId":"AANLkTimg8_YAVR0ncz71Mr1+b8Q9kL9oxjjYEOpqFMoK@mail.gmail.com","threadId":"24705","inReplyTo":"4C630D23.5090001@web.de","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-12T02:11:35Z","receivedAt":"2010-08-12T02:11:35Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":"> Are we talking about two different issues here?\n>\n> Am 11.08.2010 14:24, schrieb Ævar Arnfjörð Bjarmason:\n>> On Wed, Aug 11, 2010 at 07:03, Greg Brockman <gdb@mit.edu> wrote:\n>>> Currently, 'git add' will complain about excluded files, even if they\n>>> are already tracked:\n>\n> I'm all for not complaining when adding an ignored file that is\n> already tracked, as the user already told us he wants to track\n> this file despite .gitignore.\n>\n>>> ... so it feels natural to me not\n>>> to require extra user confirmation when an explicit path has been provided.\n>>\n>> I like it. I keep a /etc in git with .gitignore \"*\". This would help a\n>> lot for use cases like that. Explicitly specifying a full path should\n>> override gitignore IMO.\n>\n> I'm not so sure if we should silently add ignored files just because\n> they appear on the command line. For me having to force the first time\n> I do a \"git add\" for an otherwise ignored file looks like a feature.\nCorrect me if I'm wrong, but I read Ævar's use to be exactly the one I\ndescribed.  In particular, he presumably has a few interesting files\nin /etc that he tracks but wants to ignore the rest.  So as far as I\ncan tell we are all talking about the same issue.\n\nTo be clear, I certainly agree that having to force the first time you\nrun 'git add' is a feature, and my patch explicitly does not change\nthis functionality.\n\nAnyway, modulo further discussion, I will add some tests and send the\nrevised version to the list.  Thanks all for looking this over.\n"},{"id":"147858","messageId":"7vaaosv8lt.fsf@alter.siamese.dyndns.org","threadId":"24705","inReplyTo":"AANLkTinbMHDa6P8N4Mne34rMkmzzbrpm0osd2LRbr-Jv@mail.gmail.com","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-08-12T02:59:58Z","receivedAt":"2010-08-12T02:59:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Greg Brockman <gdb@MIT.EDU> writes:\n\n>> What should happen if the user did these instead, after adding \"dir\" as an\n>> ignored entry, and adding dir/file but not dir/untracked to the index?\n>>\n>>  (1)    git add dir/file dir/untracked    ; explicitly named\n>>  (2)    git add dir/*                     ; have shell glob--same as (1)\n>>  (3)    git add \"dir/*\"                   ; have git glob\n>>  (4)    git add dir                       ; have git recurse\n>\n> In all four cases, the output I get is:\n> \"\"\"\n> The following paths are ignored by one of your .gitignore files:\n> dir\n> Use -f if you really want to add them.\n> fatal: no files added\n> \"\"\"\n>\n> Note that this is also the output if you run\n>\n> (5) rm dir/untracked && git add \"dir/*\"\n\nHere is the one that troubles me the most:\n\n (6) git add dir/f*\n\nThis _looks_ like very explicitly named from git's point of view, but from\nthe end user's point of view it is not.  Depending on presense (or absense)\nof another file whose name begins with 'f' in the directory, the add will\nbe either prevented or silently accepted.\n\nI am not sure what the best solution would be; I tend to think the current\nbehaviour is slightly saner in the face of shell globbing.\n"},{"id":"147863","messageId":"AANLkTi=uKceZZGLDP5+9DN8yBtWwt070ftWSc3J-Y63i@mail.gmail.com","threadId":"24705","inReplyTo":"7vaaosv8lt.fsf@alter.siamese.dyndns.org","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-12T03:19:53Z","receivedAt":"2010-08-12T03:19:53Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":"> Here is the one that troubles me the most:\n>\n>  (6) git add dir/f*\n>\n> This _looks_ like very explicitly named from git's point of view, but from\n> the end user's point of view it is not.  Depending on presense (or absense)\n> of another file whose name begins with 'f' in the directory, the add will\n> be either prevented or silently accepted.\n>\n> I am not sure what the best solution would be; I tend to think the current\n> behaviour is slightly saner in the face of shell globbing.\nI agree that case seems rather gray.  But in what circumstances would\nyou expect it to be a problem?  I think only if the user has a tracked\nfile with local changes that he or she does not wish to be committed.\nHow common is it that a user will do this and expect gitignores to\nprotect that file's changes  I don't believe I've ever tried that in\npractice, but I also wouldn't trust gitignores to protect me from\nmyself, as a careless 'git commit -a' would still commit my changes.\n\nPerhaps one could add some syntax to .gitignore files that configures\nthis behavior.  I can come up with a proposal for something along\nthose lines if you believe it would be useful.  However, I don't have\ngreat use case for it, unless we also make 'git commit -a' and friends\nrespect this configuration.  (As an example, perhaps a line like\n+dir\nwould mean that file should be excluded even if the user runs 'git add\ndir/file' while a line like\ndir\nwould mean that 'git add dir/file' should succeed if dir/file is\nalready tracked.)\n"},{"id":"147882","messageId":"vpqsk2kjks7.fsf@bauges.imag.fr","threadId":"24705","inReplyTo":"1281510236-8103-1-git-send-email-gdb@mit.edu","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-08-12T08:30:00Z","receivedAt":"2010-08-12T08:30:00Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Greg Brockman <gdb@MIT.EDU> writes:\n\n> Currently, 'git add' will complain about excluded files, even if they\n> are already tracked:\n\nThis is not exactly true:\n\n$ echo '*.pdf' > .gitignore; touch foo.pdf; git add -f foo.pdf\n$ echo content >> foo.pdf; git add foo.pdf\n\nHere, the second \"git add\" didn't need the -f flag.\n\nSo, your problem is not about already-tracked exclude files, but it is\nabout already-tracked files in an excluded directory.\n\n> This commit changes 'git add' to disregard excludes for tracked files\n> whose paths are explicitly specified on the command-line.\n\nI don't think you need this to solve the problem, and as Junio said,\nthat would make \"git add dir/*\" add all the ignored files, which would\nmake -f essentially useless.\n\nAfter a quick look at the code, the issue seems close to (dir.c):\n\nstruct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)\n{\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\treturn dir->ignored[dir->ignored_nr++] = dir_entry_new(pathname, len);\n}\n\nI guess the \"if (!cache_name_is_other(pathname, len))\" test is the one\nallowing the behavior I got above, but here, in the case of \"git add\ndir/file\" with \"dir\" being ignored, \"pathname\" is just \"dir\", not\n\"dir/file\", hence your problem.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"147912","messageId":"AANLkTimODL6j11D6QuUX4b47GwFOVOXdqkhqrRfRaxmq@mail.gmail.com","threadId":"24705","inReplyTo":"vpqsk2kjks7.fsf@bauges.imag.fr","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-12T15:54:01Z","receivedAt":"2010-08-12T15:54:01Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":">> Currently, 'git add' will complain about excluded files, even if they\n>> are already tracked:\n>\n> This is not exactly true:\n>\n> $ echo '*.pdf' > .gitignore; touch foo.pdf; git add -f foo.pdf\n> $ echo content >> foo.pdf; git add foo.pdf\n>\n> Here, the second \"git add\" didn't need the -f flag.\n>\n> So, your problem is not about already-tracked exclude files, but it is\n> about already-tracked files in an excluded directory.\nGood catch.  My commit message is definitely wrong.\n\n>> This commit changes 'git add' to disregard excludes for tracked files\n>> whose paths are explicitly specified on the command-line.\n>\n> I don't think you need this to solve the problem, and as Junio said,\n> that would make \"git add dir/*\" add all the ignored files, which would\n> make -f essentially useless.\nI respectfully disagree with this assessment, however.\n\nFirst of all, as you point out 'git add foo.pdf' works where foo.pdf\nhas been explicitly ignored, while in contrast 'git add dir/file'\nfails when file has only been indirectly ignored because it is in an\nignored directory.  In the former case, the user explicitly specified\na policy for that file.  In the later case, the policy is only\nindirectly expressed because that file happens to be in an ignored\ndirectory; in my and Ævar's use cases what we mean is \"I only care\nabout a few files in a big directory and don't feel like writing out a\n.gitignore entry for each one\".  So it doesn't make sense to me to\nallow the user to add the file in the first place (whether by a 'git\nadd foo.pdf' or a 'git add f*') but not the second.  Perhaps the\nanswer is to swing in the opposite direction of this patch series and\nmake 'git add foo.pdf' fail as well, but I must ask what we'd be\ndefending against... it seems the only reason is to allow the user to\nmaintain local changes to a tracked file, but as I've stated many\nother tools don't seem to similarly respect the .gitignore.\n\nSecondly, I don't think this makes '-f' useless.  '-f' would still be\nused to initially add an untracked file to the index.  So this would\nmaintain an invariant that no ignored files are tracked unless the\nuser has specified a '-f' for it in the past.\n\nIncidentally, I noticed that 'git add dir/file' for ignored dir worked\nfine in an older version of git.  'git bisect' reveals that the\nbehavior I would like to change was introduced in 29209cb.  From the\ncommit message, I get the sense that this particular behavior was not\nactually intentional (someone please correct me if I'm missing\nsomething).\n\nThanks,\n\nGreg\n"},{"id":"147915","messageId":"vpq39ujg5da.fsf@bauges.imag.fr","threadId":"24705","inReplyTo":"AANLkTimODL6j11D6QuUX4b47GwFOVOXdqkhqrRfRaxmq@mail.gmail.com","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-08-12T16:31:13Z","receivedAt":"2010-08-12T16:31:13Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Greg Brockman <gdb@MIT.EDU> writes:\n\n>>> This commit changes 'git add' to disregard excludes for tracked files\n>>> whose paths are explicitly specified on the command-line.\n>>\n>> I don't think you need this to solve the problem,\n\nThis remains (see below) ...\n\n>> and as Junio said, that would make \"git add dir/*\" add all the\n>> ignored files, which would make -f essentially useless.\n\n... but this is actually wrong, yes. Your commit message states\n\n| This commit changes 'git add' to disregard excludes for tracked\n| files whose paths are explicitly specified on the command-line.\n\nI had missed the \"tracked files whose ...\" part, and focused on the\n\"path is explicitely specified on the command-line\".\n\nAnd actually, all you need is to see whether the file is tracked or\nnot, and not whether it's been given from the command-line. With your\npatch, I get:\n\n$ git init git\nInitialized empty Git repository in /tmp/git/.git/\n$ cd git\n$ mkdir dir\n$ touch dir/file\n$ echo dir > .gitignore\n$ git add -f dir/file\n$ echo content >> dir/file\n$ git add dir/file\n$ git add dir/f*    # <--- shell globing\n\nUp to now, everything OK. But:\n\n$ git add dir/f\\*   # <--- Git globing.\nThe following paths are ignored by one of your .gitignore files:\ndir\nUse -f if you really want to add them.\nfatal: no files added\n\nI think Git should not apply any .gitignore rule to already-tracked\nfiles, whether they are given from the command-line explicitely or\nthrough globbing.\n\nOne case which can be discussed:\n\n$ git add dir\nThe following paths are ignored by one of your .gitignore files:\ndir\nUse -f if you really want to add them.\nfatal: no files added\n\nI don't think I should need a -f flag here either, since dir/ contains\nonly tracked files. But I don't care much here.\n\n> Incidentally, I noticed that 'git add dir/file' for ignored dir worked\n> fine in an older version of git.  'git bisect' reveals that the\n> behavior I would like to change was introduced in 29209cb.  From the\n> commit message, I get the sense that this particular behavior was not\n> actually intentional (someone please correct me if I'm missing\n> something).\n\nMy understanding is that the goal was to reject the first \"git add\nsubdir/file\", but not subsequent ones.\n\nI'd suggest that you write a first patch introducing new tests,\npossibly marked as test_expect_failure, so that people can at least\nagree on the desired behavior, and then an implementation could\nfollow.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"147933","messageId":"7viq3fsirv.fsf@alter.siamese.dyndns.org","threadId":"24705","inReplyTo":"AANLkTimODL6j11D6QuUX4b47GwFOVOXdqkhqrRfRaxmq@mail.gmail.com","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-08-12T20:00:52Z","receivedAt":"2010-08-12T20:00:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Greg Brockman <gdb@MIT.EDU> writes:\n\n> First of all, as you point out 'git add foo.pdf' works where foo.pdf\n> has been explicitly ignored, while in contrast 'git add dir/file'\n> fails when file has only been indirectly ignored because it is in an\n> ignored directory.  In the former case, the user explicitly specified\n> a policy for that file.  In the later case, the policy is only\n> indirectly expressed because that file happens to be in an ignored\n> directory.\n\nSorry, but I don't get this argument.  When the user says \"everything in\nthis directory is ignored\", why does it make it less direct than \"this\nparticular file is ignored\"?\n"},{"id":"147936","messageId":"AANLkTikDvcn4eFDdkv26ADzsipwD_ofkdYwu_0abeLA3@mail.gmail.com","threadId":"24705","inReplyTo":"7viq3fsirv.fsf@alter.siamese.dyndns.org","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-12T20:19:39Z","receivedAt":"2010-08-12T20:19:39Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":">> First of all, as you point out 'git add foo.pdf' works where foo.pdf\n>> has been explicitly ignored, while in contrast 'git add dir/file'\n>> fails when file has only been indirectly ignored because it is in an\n>> ignored directory.  In the former case, the user explicitly specified\n>> a policy for that file.  In the later case, the policy is only\n>> indirectly expressed because that file happens to be in an ignored\n>> directory.\n>\n> Sorry, but I don't get this argument.  When the user says \"everything in\n> this directory is ignored\", why does it make it less direct than \"this\n> particular file is ignored\"?\nIn general, I view the presence of a dir entry in a .gitignore as the\nuser setting a default policy for files in that directory, but the\nuser might actually mean for there to be some exceptions to that\npolicy.\n\nFor example, in my personal usage, when I ignore a directory but track\nsome files within it, this is because I don't want to specify an\nignore for every single other file in that directory.  Also note that\nnegated .gitignore entries don't seem to work in this case, i.e. a\n.gitignore with contents\ndir\n!dir/file\nwon't actually let file be addable again.\n\nIn contrast, when I add dir/file to a .gitignore, there is no doubt\nthat I want to ignore that particular file.\n\nDoes that make more sense?\n\nGreg\n"},{"id":"147938","messageId":"AANLkTikV-fye7qc5kQNC5dSCTHB6nYoVfCg_PeFuk0KT@mail.gmail.com","threadId":"24705","inReplyTo":"AANLkTimODL6j11D6QuUX4b47GwFOVOXdqkhqrRfRaxmq@mail.gmail.com","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-08-12T20:26:09Z","receivedAt":"2010-08-12T20:26:09Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Thu, Aug 12, 2010 at 15:54, Greg Brockman <gdb@mit.edu> wrote:\n\n> Secondly, I don't think this makes '-f' useless.  '-f' would still be\n> used to initially add an untracked file to the index.  So this would\n> maintain an invariant that no ignored files are tracked unless the\n> user has specified a '-f' for it in the past.\n\nI initially misread what this series was about, and I was about to\nwithdraw my support for it. But this seems completely reasonable, and\nactually I think Git's current behavior here is clearly a bug.\n\nTo elabore with examples this behavior here is fine, and I think\neveryone agrees with that:\n\n    aoeu tmp (160M) $ git init meh\n    Initialized empty Git repository in /tmp/meh/.git/\n    aoeu tmp (160M) $ cd !$\n    cd meh\n    aoeu meh (master) $ echo '*' > .gitignore\n    aoeu meh (master) $ mkdir ignore-dir\n    aoeu meh (master) $ echo ignore > ignore-dir/file\n    aoeu meh (master) $ echo ignore > file\n    aoeu meh (master) $ git add file ignore-dir\n    The following paths are ignored by one of your .gitignore files:\n    file\n    ignore-dir\n    Use -f if you really want to add them.\n    fatal: no files added\n\nHere I have * in .gitignore but I'm adding files with an explicit\npath. Making this not ask for -f would be pretty bad, e.g. for the\nglob reasons Junio cited.\n\nSo I have to -f it:\n\n    aoeu meh (master) $ git add -f file ignore-dir\n    aoeu meh (master) $ git commit -m\"commiting ignored stuff\"\n    [master (root-commit) 6cae514] commiting ignored stuff\n     2 files changed, 2 insertions(+), 0 deletions(-)\n     create mode 100644 file\n     create mode 100644 ignore-dir/file\n\nHowever this part I think is a bug:\n\n    aoeu meh (master) $ echo whee >> ignore-dir/file\n    aoeu meh (master) $ echo whee >> file\n    aoeu meh (master) $ git status --short\n     M file\n     M ignore-dir/file\n    aoeu meh (master) $ git add file\n    aoeu meh (master) $ git add ignore-dir/file\n    The following paths are ignored by one of your .gitignore files:\n    ignore-dir\n    Use -f if you really want to add them.\n    fatal: no files added\n    $ git status --short\n    M  file\n     M ignore-dir/file\n\nHere \"file\" is already tracked by Git and it doesn't complain when I\n\"git add\" a update to it, but it complains about \"ignore-dir/file\"\njust because it's in a subdirectory.\n\nI hadn't noticed this before because I usually use \"git add -u\", which\ndoesn't complain about the ignore and happily updates the file in the\nindex:\n\n    aoeu meh (master) $ git add -u\n    aoeu meh (master) $ git status --short\n    M  file\n    M  ignore-dir/file\n\nI think \"git add ignore-dir/file\" above should act exactly like \"git\nadd file\", and not force me to add a \"-f\" to \"git add\".\n"},{"id":"147944","messageId":"20100812204051.GF2029@burratino","threadId":"24705","inReplyTo":"AANLkTikDvcn4eFDdkv26ADzsipwD_ofkdYwu_0abeLA3@mail.gmail.com","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-08-12T20:40:52Z","receivedAt":"2010-08-12T20:40:52Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Greg Brockman wrote:\n\n> For example, in my personal usage, when I ignore a directory but track\n> some files within it, this is because I don't want to specify an\n> ignore for every single other file in that directory.  Also note that\n> negated .gitignore entries don't seem to work in this case, i.e. a\n> .gitignore with contents\n> dir\n> !dir/file\n> won't actually let file be addable again.\n\nAside: yeah, this is something I have run into before.  The workaround\nI used was to use a dir/.gitignore instead, like this:\n\n *\n !/file\n\nwhich is ugly.\n\nMaybe git should get internal support for something like\n\n dir/**\n\n(meaning “all files under dir”) and “!dir/file” could be internally\nmunged to\n\n !/dir\n dir/**\n !dir/file\n\nwhen it appears after “dir”.\n"},{"id":"148347","messageId":"AANLkTiky+azVAnXEBFWR1q9_8NH8TX2TfuonXCpA_-ms@mail.gmail.com","threadId":"24705","inReplyTo":"AANLkTikV-fye7qc5kQNC5dSCTHB6nYoVfCg_PeFuk0KT@mail.gmail.com","subject":"Re: [RFC/PATCH] git-add: Don't exclude explicitly-specified tracked files","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-18T09:07:48Z","receivedAt":"2010-08-18T09:07:48Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":"> I think \"git add ignore-dir/file\" above should act exactly like \"git\n> add file\", and not force me to add a \"-f\" to \"git add\".\nI agree.  That seems very much like the correct behavior.  FWIW, prior\nto sending the patch I hadn't noticed that 'git add file' already\nworks without a '-f', which is why my commit message doesn't mention\nit.\n\nAnyway, I'm not sure if there's consensus on this being the right\nbehavior.  Thus I will take Matthieu's advice and propose a test-case\nfor the desired behavior.  I'll send that under separate cover in a\nfew moments.\n\nThanks everyone for contributing your thoughts thus far.\n\nGreg\n"},{"id":"148350","messageId":"1282123788-24055-1-git-send-email-gdb@mit.edu","threadId":"24705","inReplyTo":"AANLkTiky+azVAnXEBFWR1q9_8NH8TX2TfuonXCpA_-ms@mail.gmail.com","subject":"[RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-18T09:29:48Z","receivedAt":"2010-08-18T09:29:48Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":"This test case attempts to match the behavior of 'git add ignore-file'\nwith 'git add ignore-dir/file' when .gitignore contains entries for\nignore-file and ignore-dir.\n---\n t/t3700-add.sh |   30 ++++++++++++++++++++++++++++++\n 1 files changed, 30 insertions(+), 0 deletions(-)\n\nThis patch is a follow-up to the thread '[RFC/PATCH] git-add: Don't\nexclude explicitly-specified tracked files' at\n\n  http://thread.gmane.org/gmane.comp.version-control.git/153194\n\nIn this patch, I propose the desired behavior of 'git add' for files\ncontained in ignored directories.  I have attempted to mirror the\nbehavior of 'git add' for ignored files, but I may have gotten that\nwrong or that might not actually be what we want here.  Comments on\nwhether this is the desired behavior and whether these test-cases\naccurate capture that behavior would be appreciated.\n\nThank you,\n\nGreg\n\ndiff --git a/t/t3700-add.sh b/t/t3700-add.sh\nindex 7d7140d..97ba9e9 100755\n--- a/t/t3700-add.sh\n+++ b/t/t3700-add.sh\n@@ -288,4 +288,34 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '\n \ttest_cmp expect.err actual.err\n '\n \n+cat >expect <<EOF\n+The following paths are ignored by one of your .gitignore files:\n+ignored-dir\n+Use -f if you really want to add them.\n+fatal: no files added\n+EOF\n+\n+test_expect_success 'git add with file in ignored directory' '\n+\tmkdir ignored-dir &&\n+\techo ignored-dir >> .gitignore &&\n+\ttouch ignored-dir/file &&\n+\ttest_must_fail git add ignored-dir/file >actual 2>&1 &&\n+\ttest_cmp actual expect &&\n+\tgit add -f ignored-dir/file &&\n+\tgit add ignored-dir/file &&\n+\techo change > ignored-dir/file &&\n+\tgit add ignored-dir/file &&\n+\t! ( git ls-files -m ignored-dir/file | grep ignored-dir/file )\n+'\n+\n+test_expect_success 'git add with ignored directory using git globs' \"\n+\tmkdir ignored-dir2 && echo ignored-dir2 >> .gitignore && touch ignored-dir2/file &&\n+\tgit add 'ignored-dir2/*' >actual 2>&1 &&\n+\techo \\\"fatal: pathspec 'ignored-dir2/*' did not match any files\\\" | test_cmp - actual\n+\tgit add -f ignored-dir2/file && echo change > ignored-dir2/file &&\n+\tgit add 'ignored-dir2/*' >actual 2>&1 &&\n+\techo '' | test_cmp - actual &&\n+\tgit ls-files -m ignored-dir2/file | grep ignored-dir2/file\n+\"\n+\n test_done\n-- \n1.7.2.1.68.g1ba78\n"},{"id":"148352","messageId":"AANLkTik5t9Y8bLOLhnckPDXMh7gmC8s0xikg8xRfEpwU@mail.gmail.com","threadId":"24705","inReplyTo":"1282123788-24055-1-git-send-email-gdb@mit.edu","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-18T09:43:08Z","receivedAt":"2010-08-18T09:43:08Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":"Whoops, forgot the sign-off line:\n\n> This test case attempts to match the behavior of 'git add ignore-file'\n> with 'git add ignore-dir/file' when .gitignore contains entries for\n> ignore-file and ignore-dir.\n\nSigned-off-by: Greg Brockman <gdb@mit.edu>\n\n> ---\n>  t/t3700-add.sh |   30 ++++++++++++++++++++++++++++++\n>  1 files changed, 30 insertions(+), 0 deletions(-)\n>\n> This patch is a follow-up to the thread '[RFC/PATCH] git-add: Don't\n> exclude explicitly-specified tracked files' at\n>\n>  http://thread.gmane.org/gmane.comp.version-control.git/153194\n...\n"},{"id":"148353","messageId":"vpq8w44mer6.fsf@bauges.imag.fr","threadId":"24705","inReplyTo":"1282123788-24055-1-git-send-email-gdb@mit.edu","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-08-18T09:50:05Z","receivedAt":"2010-08-18T09:50:05Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Greg Brockman <gdb@MIT.EDU> writes:\n\n> This test case attempts to match the behavior of 'git add ignore-file'\n> with 'git add ignore-dir/file' when .gitignore contains entries for\n> ignore-file and ignore-dir.\n\nGood :-).\n\n> +test_expect_success 'git add with file in ignored directory' '\n\nIn the final version, you can make the tests test_expect_failure in\nthe first patch, and turn them back into test_expect_success in the\nsecond (which fixes the issue). This makes it clear what your change\nto the code do, and makes sure the test suite passes for each commit.\n\n> +\tmkdir ignored-dir &&\n> +\techo ignored-dir >> .gitignore &&\n> +\ttouch ignored-dir/file &&\n\nI think >ignored-dir/file is more portable than touch, and is\nrecommanded in the testsuite. But a quick grep shows that touch is\nalready used.\n\n> +\ttest_must_fail git add ignored-dir/file >actual 2>&1 &&\n> +\ttest_cmp actual expect &&\n> +\tgit add -f ignored-dir/file &&\n> +\tgit add ignored-dir/file &&\n\n(so, this is the first thing you're fixing, shouldn't be\ncontroversial)\n\n> +test_expect_success 'git add with ignored directory using git globs' \"\n> +\tmkdir ignored-dir2 && echo ignored-dir2 >> .gitignore && touch ignored-dir2/file &&\n> +\tgit add 'ignored-dir2/*' >actual 2>&1 &&\n> +\techo \\\"fatal: pathspec 'ignored-dir2/*' did not match any files\\\" | test_cmp - actual\n\nCurrently, \"git add 'dir/*'\" will add the files under dir/ if dir/\nisn't ignored, and require -f if dir is ignored.\n\nI don't think you want to complain with \"did not match any files\"\nhere.\n\n> +\tgit add -f ignored-dir2/file && echo change > ignored-dir2/file &&\n> +\tgit add 'ignored-dir2/*' >actual 2>&1 &&\n\nJust making sure I'm reading correctly: this is the second thing that\nshould be fixed, and that your earlier patch didn't.\n\nYou're not testing the case\n\n  git add ignored-dir/\n\nwhich gives another case where Git tries to add files not explicitely\ngiven on the command-line. But the correct behavior of this case may\nbe more controversial, so maybe it's indeed better to focus on the\nother cases.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"148376","messageId":"AANLkTi=UJmXx0-fV6OqDTOzuTdQQWioUb=3vrVx01qi6@mail.gmail.com","threadId":"24705","inReplyTo":"1282123788-24055-1-git-send-email-gdb@mit.edu","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-08-18T13:43:00Z","receivedAt":"2010-08-18T13:43:00Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Wed, Aug 18, 2010 at 09:29, Greg Brockman <gdb@mit.edu> wrote:\n\n> +cat >expect <<EOF\n> +The following paths are ignored by one of your .gitignore files:\n> +ignored-dir\n> +Use -f if you really want to add them.\n> +fatal: no files added\n> +EOF\n\nPlease make this a test, per this bit in t/README:\n\n - Put all code inside test_expect_success and other assertions.\n\n   Even code that isn't a test per se, but merely some setup code\n   should be inside a test assertion.\n"},{"id":"148377","messageId":"vpqk4noc9ro.fsf@bauges.imag.fr","threadId":"24705","inReplyTo":"AANLkTi=UJmXx0-fV6OqDTOzuTdQQWioUb=3vrVx01qi6@mail.gmail.com","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-08-18T13:47:55Z","receivedAt":"2010-08-18T13:47:55Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n> On Wed, Aug 18, 2010 at 09:29, Greg Brockman <gdb@mit.edu> wrote:\n>\n>> +cat >expect <<EOF\n>> +The following paths are ignored by one of your .gitignore files:\n>> +ignored-dir\n>> +Use -f if you really want to add them.\n>> +fatal: no files added\n>> +EOF\n>\n> Please make this a test, per this bit in t/README:\n>\n>  - Put all code inside test_expect_success and other assertions.\n>\n>    Even code that isn't a test per se, but merely some setup code\n>    should be inside a test assertion.\n\nNot sure what is the gain by doing so, and the vast majority of tests\nalready there use the style of Greg's patch ...\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"148384","messageId":"AANLkTinhAMNm3OyGPE4xbkXrF9nB=0rZy=9s1witpNfG@mail.gmail.com","threadId":"24705","inReplyTo":"vpqk4noc9ro.fsf@bauges.imag.fr","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-08-18T14:02:40Z","receivedAt":"2010-08-18T14:02:40Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Wed, Aug 18, 2010 at 13:47, Matthieu Moy\n<Matthieu.Moy@grenoble-inp.fr> wrote:\n> Not sure what is the gain by doing so\n\nMost of those cases were already discussed in\n<1278082789-19872-8-git-send-email-avarab@gmail.com> and surrounding\nmails, I'll point to those instead of repeating things, unless there's\nsomething else that needs clarifying (and perhaps elaborated in\nt/README).\n\n> and the vast majority of tests already there use the style of Greg's\n> patch ...\n\nThey do because we haven't converted them yet. New tests following the\nrecommendations in t/README helps with that conversion effort.\n"},{"id":"148427","messageId":"20100819000052.GA11081@burratino","threadId":"24705","inReplyTo":"vpqk4noc9ro.fsf@bauges.imag.fr","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-08-19T00:00:52Z","receivedAt":"2010-08-19T00:00:52Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Matthieu Moy wrote:\n\n> Not sure what is the gain by doing so, and the vast majority of tests\n> already there use the style of Greg's patch ...\n\nRight.  The usual rule when contributing to an existing project is\n\"imitate the surruounding code\", but there is often a tension between\nglobal style guidelines and the local conventions.\n\nIn this case I have to agree with Matthieu: the test script is\neasier to read if it follows a single, consistent style.  The cleanup\ncan happen another day.\n"},{"id":"148428","messageId":"AANLkTikLUQCnrDAp8c0QBWoGE1XUgXmd8g_19v3HnxJ4@mail.gmail.com","threadId":"24705","inReplyTo":"20100819000052.GA11081@burratino","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-08-19T00:24:54Z","receivedAt":"2010-08-19T00:24:54Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Thu, Aug 19, 2010 at 00:00, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Matthieu Moy wrote:\n>\n>> Not sure what is the gain by doing so, and the vast majority of tests\n>> already there use the style of Greg's patch ...\n>\n> Right.  The usual rule when contributing to an existing project is\n> \"imitate the surruounding code\", but there is often a tension between\n> global style guidelines and the local conventions.\n>\n> In this case I have to agree with Matthieu: the test script is\n> easier to read if it follows a single, consistent style.  The cleanup\n> can happen another day.\n\nSure, I don't feel in any way strongly about it. I just try to\n(hopefully mostly helpfully) to point out common things that\ncontradict the docs we have, especially with the tests, since I'm\ngetting pretty familiar with them :)\n"},{"id":"148450","messageId":"AANLkTi=u2jA5MOKwyYO_pwcZaK=A1D2g+gueFGF2L+5U@mail.gmail.com","threadId":"24705","inReplyTo":"vpq8w44mer6.fsf@bauges.imag.fr","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Greg Brockman","fromEmail":"gdb@mit.edu","sentAt":"2010-08-19T07:52:28Z","receivedAt":"2010-08-19T07:52:28Z","isPatch":true,"sender":{"key":"gdb@mit.edu","avatar":"https://gravatar.com/avatar/3b907cf60d0cadf6d0659d5429d971b16965fb6b1e3f5acd26a6ba2974b45da4?d=mp&s=160"},"body":">> +     mkdir ignored-dir &&\n>> +     echo ignored-dir >> .gitignore &&\n>> +     touch ignored-dir/file &&\n>\n> I think >ignored-dir/file is more portable than touch, and is\n> recommanded in the testsuite. But a quick grep shows that touch is\n> already used.\nOk, sure.  I'll switch over to >ignored-dir/file.\n\n>> +     test_must_fail git add ignored-dir/file >actual 2>&1 &&\n>> +     test_cmp actual expect &&\n>> +     git add -f ignored-dir/file &&\n>> +     git add ignored-dir/file &&\n>\n> (so, this is the first thing you're fixing, shouldn't be\n> controversial)\nHopefully not :).\n\n>> +test_expect_success 'git add with ignored directory using git globs' \"\n>> +     mkdir ignored-dir2 && echo ignored-dir2 >> .gitignore && touch ignored-dir2/file &&\n>> +     git add 'ignored-dir2/*' >actual 2>&1 &&\n>> +     echo \\\"fatal: pathspec 'ignored-dir2/*' did not match any files\\\" | test_cmp - actual\n>\n> Currently, \"git add 'dir/*'\" will add the files under dir/ if dir/\n> isn't ignored, and require -f if dir is ignored.\n>\n> I don't think you want to complain with \"did not match any files\"\n> here.\nWell, I copied the behavior of 'git add \"*\"' here, where every file in\n. is ignored.  E.g.\n\"\"\"\n$ echo >ignore-file\n$ echo .gitignore >>.gitignore\n$ echo ignore-file >>.gitignore\n$ git add '*'\nfatal: pathspec '*' did not match any files\n\"\"\"\nOne could reasonably choose to instead say \"The following paths are\nignored by one of your .gitignore files: ...\".  When I chose the \"did\nnot match any files\", I had been assuming that globbing works roughly\nanalogously to shell globbing, meaning the error one gets from a '*'\nshould be the same as that one gets from a 'dir/*' or '*/*'.  I\nrealized today that git globbing seems to act differently depending on\nwhere the wildcard appears.  E.g.:\n\"\"\"\n$ mkdir a && echo >a/b\n$ git add '*/*' # complains, doesn't stage any files\nfatal: pathspec '*/*' did not match any files\n$ git add 'a/*'\n$ echo change >a/b\n$ git add '*/*' # doesn't complain, but doesn't stage changes\n$ git ls-files -m\na/b\n\"\"\"\nIs this a bug?  I looked for some docs on the globbing functionality,\nbut I didn't come across anything that specified it in detail.\nAnyway, either way I still think consistency is ideal, and hence would\nstill vote for \"did not match any files\".  Thoughts?\n\n>> +     git add -f ignored-dir2/file && echo change > ignored-dir2/file &&\n>> +     git add 'ignored-dir2/*' >actual 2>&1 &&\n>\n> Just making sure I'm reading correctly: this is the second thing that\n> should be fixed, and that your earlier patch didn't.\nYes, that's correct.  (Again, just trying to match functionality with\nignored files.)\n\n> You're not testing the case\n>\n>  git add ignored-dir/\n>\n> which gives another case where Git tries to add files not explicitely\n> given on the command-line. But the correct behavior of this case may\n> be more controversial, so maybe it's indeed better to focus on the\n> other cases.\nA fair point.  I would have thought the behavior here should be\nunchanged, namely that 'git add ignored-dir/' should spit out a \"The\nfollowing paths are ignored by one of your .gitignore files: ...\"\nerror, regardless of the directory's contents.  Does anyone believe\nthis should be different/would it be useful for me to draw up a test\ncase for it now?  In any case, I'll certainly put a test case for this\ninto the final patch.\n\nGreg\n"},{"id":"148439","messageId":"vpqr5hv56m2.fsf@bauges.imag.fr","threadId":"24705","inReplyTo":"AANLkTi=u2jA5MOKwyYO_pwcZaK=A1D2g+gueFGF2L+5U@mail.gmail.com","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-08-19T08:50:13Z","receivedAt":"2010-08-19T08:50:13Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Greg Brockman <gdb@mit.edu> writes:\n\n>> I don't think you want to complain with \"did not match any files\"\n>> here.\n> Well, I copied the behavior of 'git add \"*\"' here, where every file in\n> . is ignored.  E.g.\n> \"\"\"\n> $ echo >ignore-file\n> $ echo .gitignore >>.gitignore\n> $ echo ignore-file >>.gitignore\n> $ git add '*'\n> fatal: pathspec '*' did not match any files\n> \"\"\"\n\nOK, that makes sense (you can add comments to your tests or commit\nmessage to justify this is case someone wonders later).\n\n> realized today that git globbing seems to act differently depending on\n> where the wildcard appears.  E.g.:\n\n> Is this a bug?\n\nThere are many known inconsistancies with Git globing, yes. See for\nexample:\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/128672/focus=128759\n\n>> You're not testing the case\n>>\n>>  git add ignored-dir/\n>>\n>> which gives another case where Git tries to add files not explicitely\n>> given on the command-line. But the correct behavior of this case may\n>> be more controversial, so maybe it's indeed better to focus on the\n>> other cases.\n> A fair point.  I would have thought the behavior here should be\n> unchanged, namely that 'git add ignored-dir/' should spit out a \"The\n> following paths are ignored by one of your .gitignore files: ...\"\n> error, regardless of the directory's contents.  Does anyone believe\n> this should be different/would it be useful for me to draw up a test\n> case for it now?  In any case, I'll certainly put a test case for this\n> into the final patch.\n\nIt makes sense to make \"git add dir/\" equivalent to \"git add dir/*\",\nbut I don't really care either way.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"148927","messageId":"20100825031341.GF11619@burratino","threadId":"24705","inReplyTo":"AANLkTikLUQCnrDAp8c0QBWoGE1XUgXmd8g_19v3HnxJ4@mail.gmail.com","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-08-25T03:13:41Z","receivedAt":"2010-08-25T03:13:41Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Ævar Arnfjörð Bjarmason wrote:\n\n> I just try to\n> (hopefully mostly helpfully) to point out common things that\n> contradict the docs we have\n\nThanks for doing so, by the way.  One of the best ways to make sure\nthe docs are sane is to use them.\n\nWhen a guideline is unclear, probably I should have been updating the\ndocs instead of dispensing advice.\n\nHow about something like this?\n\ndiff --git a/t/README b/t/README\nindex 410499a..f347de7 100644\n--- a/t/README\n+++ b/t/README\n@@ -235,7 +235,9 @@ Do's, don'ts & things to keep in mind\n -------------------------------------\n \n Here are a few examples of things you probably should and shouldn't do\n-when writing tests.\n+when writing tests.  If you are editing an existing test script and have\n+the time for it, consider updating the script to follow these guidelines\n+in a separate patch before adding your new test.\n \n Do:\n \n-- \n"},{"id":"149220","messageId":"AANLkTimE7LPV0NOdVXZZHgw8=NT061GjjfFYHxVn=X2B@mail.gmail.com","threadId":"24705","inReplyTo":"20100825031341.GF11619@burratino","subject":"Re: [RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-08-29T18:27:22Z","receivedAt":"2010-08-29T18:27:22Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Wed, Aug 25, 2010 at 03:13, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Ævar Arnfjörð Bjarmason wrote:\n>\n>> I just try to\n>> (hopefully mostly helpfully) to point out common things that\n>> contradict the docs we have\n>\n> Thanks for doing so, by the way.  One of the best ways to make sure\n> the docs are sane is to use them.\n>\n> When a guideline is unclear, probably I should have been updating the\n> docs instead of dispensing advice.\n>\n> How about something like this?\n>\n> diff --git a/t/README b/t/README\n> index 410499a..f347de7 100644\n> --- a/t/README\n> +++ b/t/README\n> @@ -235,7 +235,9 @@ Do's, don'ts & things to keep in mind\n>  -------------------------------------\n>\n>  Here are a few examples of things you probably should and shouldn't do\n> -when writing tests.\n> +when writing tests.  If you are editing an existing test script and have\n> +the time for it, consider updating the script to follow these guidelines\n> +in a separate patch before adding your new test.\n\nThat looks good.\n"}]}