{"thread":{"id":"6106","subject":"[PATCH 5/5] git-add: add ignored files when asked explicitly.","startedAt":"2006-12-25T11:13:45Z","lastAt":"2007-01-04T13:58:57Z","messageCount":11,"participants":["Junio C Hamano","Johannes Schindelin","Nicolas Pitre","Jakub Narebski","Andreas Ericsson"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"30268","messageId":"7vbqlskz2u.fsf@assigned-by-dhcp.cox.net","threadId":"6106","inReplyTo":null,"subject":"[PATCH 5/5] git-add: add ignored files when asked explicitly.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-25T11:13:45Z","receivedAt":"2006-12-25T11:13:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"One thing many people found confusing about git-add was that a\nfile whose name matches an ignored pattern could not be added to\nthe index.  With this, such a file can be added by explicitly\nspelling its name to git-add.\n\nFileglobs and recursive behaviour do not add ignored files to\nthe index.  That is, if a pattern '*.o' is in .gitignore, and\ntwo files foo.o, bar/baz.o are in the working tree:\n\n    $ git add foo.o\n    $ git add '*.o'\n    $ git add bar\n\nOnly the first form adds foo.o to the index.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n Documentation/git-add.txt |   11 ++++++++---\n builtin-add.c             |   11 ++++++++++-\n 2 files changed, 18 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-add.txt b/Documentation/git-add.txt\nindex d86c0e7..a8ed459 100644\n--- a/Documentation/git-add.txt\n+++ b/Documentation/git-add.txt\n@@ -25,8 +25,9 @@ the commit.\n The 'git status' command can be used to obtain a summary of what is included\n for the next commit.\n \n-This command only adds non-ignored files, to add ignored files use\n-\"git update-index --add\".\n+This command can be used to add ignored files, but they have to be\n+explicitly and exactly specified from the command line.  File globbing\n+and recursive behaviour do not add ignored files.\n \n Please see gitlink:git-commit[1] for alternative ways to add content to a\n commit.\n@@ -35,7 +36,11 @@ commit.\n OPTIONS\n -------\n <file>...::\n-\tFiles to add content from.\n+\tFiles to add content from.  Fileglobs (e.g. `*.c`) can\n+\tbe given to add all matching files.  Also a\n+\tleading directory name (e.g. `dir` to add `dir/file1`\n+\tand `dir/file2`) can be given to add all files in the\n+\tdirectory, recursively.\n \n -n::\n         Don't actually add the file(s), just show if they exist.\ndiff --git a/builtin-add.c b/builtin-add.c\nindex f306f82..389c106 100644\n--- a/builtin-add.c\n+++ b/builtin-add.c\n@@ -25,7 +25,14 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p\n \ti = dir->nr;\n \twhile (--i >= 0) {\n \t\tstruct dir_entry *entry = *src++;\n-\t\tif (!match_pathspec(pathspec, entry->name, entry->len, prefix, seen)) {\n+\t\tint how = match_pathspec(pathspec, entry->name, entry->len,\n+\t\t\t\t\t prefix, seen);\n+\t\t/*\n+\t\t * ignored entries can be added with exact match,\n+\t\t * but not with glob nor recursive.\n+\t\t */\n+\t\tif (!how ||\n+\t\t    (entry->ignored_entry && how != MATCHED_EXACTLY)) {\n \t\t\tfree(entry);\n \t\t\tcontinue;\n \t\t}\n@@ -54,6 +61,8 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)\n \n \t/* Set up the default git porcelain excludes */\n \tmemset(dir, 0, sizeof(*dir));\n+\tif (pathspec)\n+\t\tdir->show_both = 1;\n \tdir->exclude_per_dir = \".gitignore\";\n \tpath = git_path(\"info/exclude\");\n \tif (!access(path, R_OK))\n-- \n1.4.4.3.g50da\n"},{"id":"30270","messageId":"Pine.LNX.4.63.0612251443230.19693@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6106","inReplyTo":"7vbqlskz2u.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-25T13:47:13Z","receivedAt":"2006-12-25T13:47:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 25 Dec 2006, Junio C Hamano wrote:\n\n>     $ git add foo.o\n>     $ git add '*.o'\n\nMost people do\n\n\t$ git add *.o\n\ninstead, where bash expands the expression. Maybe this new behaviour \nshould be hidden between a \"-f\" option?\n\nCiao,\nDscho\n"},{"id":"30273","messageId":"7vslf3khsc.fsf@assigned-by-dhcp.cox.net","threadId":"6106","inReplyTo":"Pine.LNX.4.63.0612251443230.19693@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-25T17:27:15Z","receivedAt":"2006-12-25T17:27:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> On Mon, 25 Dec 2006, Junio C Hamano wrote:\n>\n>>     $ git add foo.o\n>>     $ git add '*.o'\n>\n> Most people do\n>\n> \t$ git add *.o\n>\n> instead, where bash expands the expression. Maybe this new behaviour \n> should be hidden between a \"-f\" option?\n\nWhen would anybody do \"git add *.o\"?\n\nA more plausible situation is that you have '*.o' in .gitignore\nbecause you do not want to keep track of object files generated\nfrom your source, but your project needs to keep track of one\nthird-party object file that you do not have the source to, and\nhelping that situation is what this patch is about.\n\nAn alternative is to use the mechanism I added here to _detect_\nthe attempt to add an ignored file with explicitly spelled out\npathspec, and issue an info message that says something like:\n\n\tPath 'xyzzy/filfre.o' is not being ignored by one of\n\tyour .gitignore files.  If you really want to add it,\n\tplease add this entry to .gitignore file:\n\n        !/xyzzy/filfre.o\n\nOne advantage of this is that it would help guiding the user in\nthe right direction, giving a reusable piece of knowledge,\nwithout changing the behaviour of the command (what is refused\nis refused).  But I can already see people's complaints: if the\ntool knows how to fix that situation why forces the user to do\nso?\n\nAlthough the reason why the alternative does not do so is \"The\nuser earlier said *.o files are uninteresting but came back with\na conflicting request to add xyzzy/filfre.o, which could be a\nmistake.  We ask for a confirmation\", which is very sensible,\nanother alternative would be to add the path anyway and issue an\nwarning, like this:\n\n\t$ ls xyzzy\n        filfre.c\tfilfre.o\n\t$ git add xyzzy/filfre.?\n\tadded ignored path xyzzy/filfre.o\n"},{"id":"30275","messageId":"7vodprizuw.fsf_-_@assigned-by-dhcp.cox.net","threadId":"6106","inReplyTo":"7vslf3khsc.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] git-add: warn when adding an ignored file with an explicit request.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-25T18:39:51Z","receivedAt":"2006-12-25T18:39:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"We allow otherwise ignored paths to be added to the index by\nspelling its path out on the command line, but we would warn the\nuser about them when we do so.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n * This is on top of what I sent out last night.\n\n builtin-add.c |    3 +++\n 1 files changed, 3 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-add.c b/builtin-add.c\nindex 822075a..c54c694 100644\n--- a/builtin-add.c\n+++ b/builtin-add.c\n@@ -37,6 +37,9 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p\n \t\t\tfree(entry);\n \t\t\tcontinue;\n \t\t}\n+\t\tif (entry->ignored_entry)\n+\t\t\tfprintf(stderr, \"warning: '%s' is an ignored path.\\n\",\n+\t\t\t\tentry->name);\n \t\t*dst++ = entry;\n \t}\n \tdir->nr = dst - dir->entries;\n-- \n1.4.4.3.g71b5\n"},{"id":"30276","messageId":"Pine.LNX.4.64.0612251454040.18171@xanadu.home","threadId":"6106","inReplyTo":"7vslf3khsc.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2006-12-25T19:57:22Z","receivedAt":"2006-12-25T19:57:22Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Mon, 25 Dec 2006, Junio C Hamano wrote:\n\n> An alternative is to use the mechanism I added here to _detect_\n> the attempt to add an ignored file with explicitly spelled out\n> pathspec, and issue an info message that says something like:\n> \n> \tPath 'xyzzy/filfre.o' is not being ignored by one of\n> \tyour .gitignore files.  If you really want to add it,\n> \tplease add this entry to .gitignore file:\n> \n>         !/xyzzy/filfre.o\n\nWhat about this instead:\n\n\tPath 'xyzzy/filfre.o' should be ignored according to one of\n\tyour .gitignore files.  If you really want to add it, you must\n\tuse the -f flag.\n\n\nNicolas\n"},{"id":"30279","messageId":"empitl$t6p$1@sea.gmane.org","threadId":"6106","inReplyTo":"7vodprizuw.fsf_-_@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] git-add: warn when adding an ignored file with an explicit request.","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-25T22:24:30Z","receivedAt":"2006-12-25T22:24:30Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Junio C Hamano wrote:\n\n> We allow otherwise ignored paths to be added to the index by\n> spelling its path out on the command line, but we would warn the\n> user about them when we do so.\n\nI'm for warning user that the file to be added is ignored file and\ntelling how to make an exception in .gitignore _AND_ that -f option\ncan be used to bypass that check. And adding ignored path as above\nwith -f option.\n\nBut otherwise: nice series of patches.\n\nP.S. Were all the patches sent as replies to introductory letter?\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"30303","messageId":"Pine.LNX.4.63.0612261632360.19693@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6106","inReplyTo":"7vslf3khsc.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-26T15:34:18Z","receivedAt":"2006-12-26T15:34:18Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 25 Dec 2006, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > On Mon, 25 Dec 2006, Junio C Hamano wrote:\n> >\n> >>     $ git add foo.o\n> >>     $ git add '*.o'\n> >\n> > Most people do\n> >\n> > \t$ git add *.o\n> >\n> > instead, where bash expands the expression. Maybe this new behaviour \n> > should be hidden between a \"-f\" option?\n> \n> When would anybody do \"git add *.o\"?\n\nNot exactly \"git add *.o\", but when I see in git-status that there are \nonly a couple of files which are untracked, and I want them added, I \nlazily do \"git add *\".\n\nCiao,\nDscho\n"},{"id":"30306","messageId":"Pine.LNX.4.63.0612261718070.19693@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6106","inReplyTo":"empitl$t6p$1@sea.gmane.org","subject":"Re: [PATCH] git-add: warn when adding an ignored file with an explicit request.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-26T16:19:57Z","receivedAt":"2006-12-26T16:19:57Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 25 Dec 2006, Jakub Narebski wrote:\n\n> P.S. Were all the patches sent as replies to introductory letter?\n\nI actually don't like that convention at all. It makes for a _huge_ thread \nof unrelated discussions, since most of the time the series is _exactly_ \nbecause the patches are somewhat independent (otherwise you could not \nseparate them).\n\nCiao,\nDscho\n"},{"id":"30309","messageId":"7v1wmmfpfw.fsf@assigned-by-dhcp.cox.net","threadId":"6106","inReplyTo":"Pine.LNX.4.63.0612261632360.19693@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-26T19:05:23Z","receivedAt":"2006-12-26T19:05:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n>> > Most people do\n>> >\n>> > \t$ git add *.o\n>> >\n>> > instead, where bash expands the expression. Maybe this new behaviour \n>> > should be hidden between a \"-f\" option?\n>> \n>> When would anybody do \"git add *.o\"?\n>\n> Not exactly \"git add *.o\", but when I see in git-status that there are \n> only a couple of files which are untracked, and I want them added, I \n> lazily do \"git add *\".\n\nI changed it to warn and refuse and made it only add under -f\nflag.\n"},{"id":"30314","messageId":"Pine.LNX.4.63.0612262348260.19693@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6106","inReplyTo":"7v1wmmfpfw.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-12-26T22:48:37Z","receivedAt":"2006-12-26T22:48:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 26 Dec 2006, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> >> > Most people do\n> >> >\n> >> > \t$ git add *.o\n> >> >\n> >> > instead, where bash expands the expression. Maybe this new behaviour \n> >> > should be hidden between a \"-f\" option?\n> >> \n> >> When would anybody do \"git add *.o\"?\n> >\n> > Not exactly \"git add *.o\", but when I see in git-status that there are \n> > only a couple of files which are untracked, and I want them added, I \n> > lazily do \"git add *\".\n> \n> I changed it to warn and refuse and made it only add under -f\n> flag.\n\nThanks!\n\nCiao,\nDscho\n"},{"id":"30813","messageId":"459D0821.10204@op5.se","threadId":"6106","inReplyTo":"7vslf3khsc.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 5/5] git-add: add ignored files when asked explicitly.","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-01-04T13:58:57Z","receivedAt":"2007-01-04T13:58:57Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Junio C Hamano wrote:\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n>> On Mon, 25 Dec 2006, Junio C Hamano wrote:\n>>\n>>>     $ git add foo.o\n>>>     $ git add '*.o'\n>> Most people do\n>>\n>> \t$ git add *.o\n>>\n>> instead, where bash expands the expression. Maybe this new behaviour \n>> should be hidden between a \"-f\" option?\n> \n> When would anybody do \"git add *.o\"?\n> \n\nMake that \"git add *.c\" then, in a directory normally containing a lot \nof generated C-files.\n\n> \n> An alternative is to use the mechanism I added here to _detect_\n> the attempt to add an ignored file with explicitly spelled out\n> pathspec, and issue an info message that says something like:\n> \n> \tPath 'xyzzy/filfre.o' is not being ignored by one of\n> \tyour .gitignore files.  If you really want to add it,\n> \tplease add this entry to .gitignore file:\n> \n>         !/xyzzy/filfre.o\n> \n\nSounds very sensible to me, although I assume you meant \"path \nxyzzy/filfre.o is being ignored\" (ie, \"is not being ignored\" (sic) was a \ntypo).\n\n\n> One advantage of this is that it would help guiding the user in\n> the right direction, giving a reusable piece of knowledge,\n> without changing the behaviour of the command (what is refused\n> is refused).  But I can already see people's complaints: if the\n> tool knows how to fix that situation why forces the user to do\n> so?\n> \n> Although the reason why the alternative does not do so is \"The\n> user earlier said *.o files are uninteresting but came back with\n> a conflicting request to add xyzzy/filfre.o, which could be a\n> mistake.  We ask for a confirmation\", which is very sensible,\n\nVery sensible indeed. If you tell a cabdriver \"go-left-go-right\" (very \nfast) he'll (hopefully) stop and ask you where you really wanted to go.\n\n> another alternative would be to add the path anyway and issue an\n> warning, like this:\n> \n> \t$ ls xyzzy\n>         filfre.c\tfilfre.o\n> \t$ git add xyzzy/filfre.?\n> \tadded ignored path xyzzy/filfre.o\n> \n\nI like the \"you did something weird. Education served\" option better.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"}]}