git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Improved "git add"
@ 2005-09-18 18:27 Linus Torvalds
  2005-09-18 21:29 ` Nico -telmich- Schottelius
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Torvalds @ 2005-09-18 18:27 UTC (permalink / raw
  To: Junio C Hamano, Git Mailing List


This fixes everybodys favourite complaint about "git add", namely that it 
doesn't take directories.

We use "git-ls-files --others" to generate an arbitrary list of filenames, 
and thus also automatically honor ignore-files while we're at it.

Side note: there's a lot of room for improvement here. In particular, if
we have a long list of filenames (importing a big archive), this will just
do a big stupid for-loop and add them one at a time. Maybe it should use

	generate-list | xargs -0 git-update-idex --add --

instead.

Also, I think we should have a default ignore list if we don't find a 
.git/info/exclude file. Ignoring "*.o" and ".*" by default would probably 
be the right thing to do.

But I think this is a good first step.

Use the "-n" flag to just show the list of files to be added without 
adding them. 

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

NOTE! This depends on the previous patch that added "--git-dir" to 
git-rev-parse

diff --git a/git-add.sh b/git-add.sh
--- a/git-add.sh
+++ b/git-add.sh
@@ -1,2 +1,32 @@
 #!/bin/sh
-git-update-index --add -- "$@"
+
+show_only=
+verbose=
+while : ; do
+  case "$1" in
+    -n)
+	show_only=true
+	verbose=true
+	;;
+    -v)
+	verbose=true
+	;;
+    *)
+	break
+	;;
+  esac
+  shift
+done
+
+GIT_DIR=$(git-rev-parse --git-dir) || exit
+global_exclude=
+if [ -f "$GIT_DIR/info/exclude" ]; then
+   global_exclude="--exclude-from=$GIT_DIR/info/exclude"
+fi
+for i in $(git-ls-files --others \
+	$global_exclude --exclude-per-directory=.gitignore \
+	"$@")
+do
+   [ "$verbose" ] && echo "  $i"
+   [ "$show_only" ] || git-update-index --add -- "$i" || exit
+done

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Improved "git add"
  2005-09-18 18:27 Improved "git add" Linus Torvalds
@ 2005-09-18 21:29 ` Nico -telmich- Schottelius
  2005-09-18 22:17   ` Petr Baudis
  0 siblings, 1 reply; 3+ messages in thread
From: Nico -telmich- Schottelius @ 2005-09-18 21:29 UTC (permalink / raw
  To: Git Mailing List

[-- Attachment #1: Type: text/plain, Size: 983 bytes --]

Linus Torvalds [Sun, Sep 18, 2005 at 11:27:45AM -0700]:
> [git-add/directory fix]

Nice, first cogito and now git itself. You are pretty fast.

> [...]
> Also, I think we should have a default ignore list if we don't find a 
> .git/info/exclude file. Ignoring "*.o" and ".*" by default would probably 
> be the right thing to do.

I do use doc/.warning or similar in some projects files for outputting
a warning when somebody simply types 'make', so he'll get instructions
on what to do.

Other people may even want to include *.o in their tree, because it's
used by their program for another purpose.

I do not think that a VCS should ignore anything from itself. If we
generate a standard .git/info/excludes (or whatever the name of it is)
and write those standard values in there, this is a different thing.

Nico

-- 
Latest project: cconfig (http://nico.schotteli.us/papers/linux/cconfig/)
Open Source nutures open minds and free, creative developers.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 827 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Improved "git add"
  2005-09-18 21:29 ` Nico -telmich- Schottelius
@ 2005-09-18 22:17   ` Petr Baudis
  0 siblings, 0 replies; 3+ messages in thread
From: Petr Baudis @ 2005-09-18 22:17 UTC (permalink / raw
  To: Nico -telmich- Schottelius; +Cc: Git Mailing List

Dear diary, on Sun, Sep 18, 2005 at 11:29:04PM CEST, I got a letter
where Nico -telmich- Schottelius <nico-linux-git@schottelius.org> told me that...
> Linus Torvalds [Sun, Sep 18, 2005 at 11:27:45AM -0700]:
> > [git-add/directory fix]
> 
> Nice, first cogito and now git itself. You are pretty fast.
> 
> > [...]
> > Also, I think we should have a default ignore list if we don't find a 
> > .git/info/exclude file. Ignoring "*.o" and ".*" by default would probably 
> > be the right thing to do.
> 
> I do use doc/.warning or similar in some projects files for outputting
> a warning when somebody simply types 'make', so he'll get instructions
> on what to do.
> 
> Other people may even want to include *.o in their tree, because it's
> used by their program for another purpose.
> 
> I do not think that a VCS should ignore anything from itself. If we
> generate a standard .git/info/excludes (or whatever the name of it is)
> and write those standard values in there, this is a different thing.

But .git/info/exclude mostly sucks, you really want these kinds of rules
in .gitignore if anywhere. E.g. CVS by default ignores some stuff and it
seems as a fine strategy for me, and is working out in the vast majority
of cases. You can unignore files by doing '!pattern', so if you want to
throw away all the defaults, just specify '!*'.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
If you want the holes in your knowledge showing up try teaching
someone.  -- Alan Cox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-09-18 22:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-18 18:27 Improved "git add" Linus Torvalds
2005-09-18 21:29 ` Nico -telmich- Schottelius
2005-09-18 22:17   ` Petr Baudis

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).