{"thread":{"id":"1852","subject":"Improved \"git add\"","startedAt":"2005-09-18T18:27:45Z","lastAt":"2005-09-18T22:17:02Z","messageCount":3,"participants":["Linus Torvalds","Nico -telmich- Schottelius","Petr Baudis"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"8799","messageId":"Pine.LNX.4.58.0509181119040.26803@g5.osdl.org","threadId":"1852","inReplyTo":null,"subject":"Improved \"git add\"","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-18T18:27:45Z","receivedAt":"2005-09-18T18:27:45Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nThis fixes everybodys favourite complaint about \"git add\", namely that it \ndoesn't take directories.\n\nWe use \"git-ls-files --others\" to generate an arbitrary list of filenames, \nand thus also automatically honor ignore-files while we're at it.\n\nSide note: there's a lot of room for improvement here. In particular, if\nwe have a long list of filenames (importing a big archive), this will just\ndo a big stupid for-loop and add them one at a time. Maybe it should use\n\n\tgenerate-list | xargs -0 git-update-idex --add --\n\ninstead.\n\nAlso, I think we should have a default ignore list if we don't find a \n.git/info/exclude file. Ignoring \"*.o\" and \".*\" by default would probably \nbe the right thing to do.\n\nBut I think this is a good first step.\n\nUse the \"-n\" flag to just show the list of files to be added without \nadding them. \n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\n\nNOTE! This depends on the previous patch that added \"--git-dir\" to \ngit-rev-parse\n\ndiff --git a/git-add.sh b/git-add.sh\n--- a/git-add.sh\n+++ b/git-add.sh\n@@ -1,2 +1,32 @@\n #!/bin/sh\n-git-update-index --add -- \"$@\"\n+\n+show_only=\n+verbose=\n+while : ; do\n+  case \"$1\" in\n+    -n)\n+\tshow_only=true\n+\tverbose=true\n+\t;;\n+    -v)\n+\tverbose=true\n+\t;;\n+    *)\n+\tbreak\n+\t;;\n+  esac\n+  shift\n+done\n+\n+GIT_DIR=$(git-rev-parse --git-dir) || exit\n+global_exclude=\n+if [ -f \"$GIT_DIR/info/exclude\" ]; then\n+   global_exclude=\"--exclude-from=$GIT_DIR/info/exclude\"\n+fi\n+for i in $(git-ls-files --others \\\n+\t$global_exclude --exclude-per-directory=.gitignore \\\n+\t\"$@\")\n+do\n+   [ \"$verbose\" ] && echo \"  $i\"\n+   [ \"$show_only\" ] || git-update-index --add -- \"$i\" || exit\n+done\n"},{"id":"8806","messageId":"20050918212904.GB1463@schottelius.org","threadId":"1852","inReplyTo":"Pine.LNX.4.58.0509181119040.26803@g5.osdl.org","subject":"Re: Improved \"git add\"","fromName":"Nico -telmich- Schottelius","fromEmail":"nico-linux-git@schottelius.org","sentAt":"2005-09-18T21:29:04Z","receivedAt":"2005-09-18T21:29:04Z","isPatch":false,"sender":{"key":"nico-linux-git@schottelius.org","avatar":null},"body":"Linus Torvalds [Sun, Sep 18, 2005 at 11:27:45AM -0700]:\n> [git-add/directory fix]\n\nNice, first cogito and now git itself. You are pretty fast.\n\n> [...]\n> Also, I think we should have a default ignore list if we don't find a \n> .git/info/exclude file. Ignoring \"*.o\" and \".*\" by default would probably \n> be the right thing to do.\n\nI do use doc/.warning or similar in some projects files for outputting\na warning when somebody simply types 'make', so he'll get instructions\non what to do.\n\nOther people may even want to include *.o in their tree, because it's\nused by their program for another purpose.\n\nI do not think that a VCS should ignore anything from itself. If we\ngenerate a standard .git/info/excludes (or whatever the name of it is)\nand write those standard values in there, this is a different thing.\n\nNico\n\n-- \nLatest project: cconfig (http://nico.schotteli.us/papers/linux/cconfig/)\nOpen Source nutures open minds and free, creative developers.\n"},{"id":"8812","messageId":"20050918221702.GE22391@pasky.or.cz","threadId":"1852","inReplyTo":"20050918212904.GB1463@schottelius.org","subject":"Re: Improved \"git add\"","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2005-09-18T22:17:02Z","receivedAt":"2005-09-18T22:17:02Z","isPatch":false,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"Dear diary, on Sun, Sep 18, 2005 at 11:29:04PM CEST, I got a letter\nwhere Nico -telmich- Schottelius <nico-linux-git@schottelius.org> told me that...\n> Linus Torvalds [Sun, Sep 18, 2005 at 11:27:45AM -0700]:\n> > [git-add/directory fix]\n> \n> Nice, first cogito and now git itself. You are pretty fast.\n> \n> > [...]\n> > Also, I think we should have a default ignore list if we don't find a \n> > .git/info/exclude file. Ignoring \"*.o\" and \".*\" by default would probably \n> > be the right thing to do.\n> \n> I do use doc/.warning or similar in some projects files for outputting\n> a warning when somebody simply types 'make', so he'll get instructions\n> on what to do.\n> \n> Other people may even want to include *.o in their tree, because it's\n> used by their program for another purpose.\n> \n> I do not think that a VCS should ignore anything from itself. If we\n> generate a standard .git/info/excludes (or whatever the name of it is)\n> and write those standard values in there, this is a different thing.\n\nBut .git/info/exclude mostly sucks, you really want these kinds of rules\nin .gitignore if anywhere. E.g. CVS by default ignores some stuff and it\nseems as a fine strategy for me, and is working out in the vast majority\nof cases. You can unignore files by doing '!pattern', so if you want to\nthrow away all the defaults, just specify '!*'.\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nIf you want the holes in your knowledge showing up try teaching\nsomeone.  -- Alan Cox\n"}]}