X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=git-add.sh;h=d6a4bc7d092f619d3c9dd20507c6659e13f82a3c;hb=692c7fc9cb81a2f68b23199d5b8612494fe4d317;hp=3d364db2517b6a19de6b8e26f6d61a86589c1fcc;hpb=727132834e6be48a93c1bd6458a29d474ce7d5d5;p=git.git diff --git a/git-add.sh b/git-add.sh index 3d364db2..d6a4bc7d 100755 --- a/git-add.sh +++ b/git-add.sh @@ -1,15 +1,25 @@ #!/bin/sh +USAGE='[-n] [-v] ...' +SUBDIRECTORY_OK='Yes' +. git-sh-setup + show_only= verbose= while : ; do case "$1" in -n) show_only=true - verbose=true ;; -v) - verbose=true + verbose=--verbose + ;; + --) + shift + break + ;; + -*) + usage ;; *) break @@ -18,15 +28,29 @@ while : ; do 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 +# Check misspelled pathspec +case "$#" in +0) ;; +*) + git-ls-files --error-unmatch --others --cached -- "$@" >/dev/null || { + echo >&2 "Maybe you misspelled it?" + exit 1 + } + ;; +esac + +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