X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=git-add.sh;h=b5fe46aa20865d6785390fd22406d32b00a77845;hb=54a9ba0d44c37c43670087793bfeb1b54d718cdb;hp=3d364db2517b6a19de6b8e26f6d61a86589c1fcc;hpb=727132834e6be48a93c1bd6458a29d474ce7d5d5;p=git.git diff --git a/git-add.sh b/git-add.sh index 3d364db2..b5fe46aa 100755 --- a/git-add.sh +++ b/git-add.sh @@ -1,15 +1,21 @@ #!/bin/sh +usage() { + die "usage: git add [-n] [-v] ..." +} + show_only= verbose= while : ; do case "$1" in -n) show_only=true - verbose=true ;; -v) - verbose=true + verbose=--verbose + ;; + -*) + usage ;; *) break @@ -19,14 +25,19 @@ while : ; do 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 + +if test -f "$GIT_DIR/info/exclude" +then + git-ls-files -z \ + --exclude-from="$GIT_DIR/info/exclude" \ + --others --exclude-per-directory=.gitignore -- "$@" +else + git-ls-files -z \ + --others --exclude-per-directory=.gitignore -- "$@" +fi | +case "$show_only" in +true) + xargs -0 echo ;; +*) + git-update-index --add $verbose -z --stdin ;; +esac