@matheusbsbs / matheus-bagliano / commits / 37539fbda5
Fork 0

[PATCH] Improved "git add"

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> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Sep 18, 2005 at 11:27 UTC 37539fbda5962cd3b7d8fe5ae8db743b5d9c9940
1 file changed +31 -1
git-add.sh
+31 -1
@@ -1,2 +1,32 @@
1 #!/bin/sh
2 -git-update-index --add -- "$@"
2 +
3 +show_only=
4 +verbose=
5 +while : ; do
6 + case "$1" in
7 + -n)
8 + show_only=true
9 + verbose=true
10 + ;;
11 + -v)
12 + verbose=true
13 + ;;
14 + *)
15 + break
16 + ;;
17 + esac
18 + shift
19 +done
20 +
21 +GIT_DIR=$(git-rev-parse --git-dir) || exit
22 +global_exclude=
23 +if [ -f "$GIT_DIR/info/exclude" ]; then
24 + global_exclude="--exclude-from=$GIT_DIR/info/exclude"
25 +fi
26 +for i in $(git-ls-files --others \
27 + $global_exclude --exclude-per-directory=.gitignore \
28 + "$@")
29 +do
30 + [ "$verbose" ] && echo " $i"
31 + [ "$show_only" ] || git-update-index --add -- "$i" || exit
32 +done