summaryrefslogtreecommitdiff
path: root/git-rm.sh
diff options
context:
space:
mode:
authorLibravatar Carl Worth <cworth@cworth.org>2006-02-22 16:37:27 -0800
committerLibravatar Junio C Hamano <junkio@cox.net>2006-02-22 17:10:42 -0800
commit3844cdc8f19dcd848003586d6b98c9f2bd36a7d0 (patch)
tree058288877f9735ccc806c5245c974bfb4f2805b8 /git-rm.sh
parentAdd new git-rm command with documentation (diff)
downloadtgif-3844cdc8f19dcd848003586d6b98c9f2bd36a7d0.tar.xz
git-rm: Fix to properly handle files with spaces, tabs, newlines, etc.
New tests are added to the git-rm test case to cover this as well. Signed-off-by: Carl Worth <cworth@cworth.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git-rm.sh')
-rwxr-xr-xgit-rm.sh37
1 files changed, 20 insertions, 17 deletions
diff --git a/git-rm.sh b/git-rm.sh
index 0a3f546683..fda4541c76 100755
--- a/git-rm.sh
+++ b/git-rm.sh
@@ -4,7 +4,6 @@ USAGE='[-f] [-n] [-v] [--] <file>...'
SUBDIRECTORY_OK='Yes'
. git-sh-setup
-index_remove_option=--force-remove
remove_files=
show_only=
verbose=
@@ -12,7 +11,6 @@ while : ; do
case "$1" in
-f)
remove_files=true
- index_remote_option=--force
;;
-n)
show_only=true
@@ -45,23 +43,28 @@ case "$#" in
;;
esac
-files=$(
- if test -f "$GIT_DIR/info/exclude" ; then
- git-ls-files \
- --exclude-from="$GIT_DIR/info/exclude" \
- --exclude-per-directory=.gitignore -- "$@"
- else
- git-ls-files \
+if test -f "$GIT_DIR/info/exclude"
+then
+ git-ls-files -z \
+ --exclude-from="$GIT_DIR/info/exclude" \
--exclude-per-directory=.gitignore -- "$@"
- fi | sort | uniq
-)
-
-case "$show_only" in
-true)
- echo $files
+else
+ git-ls-files -z \
+ --exclude-per-directory=.gitignore -- "$@"
+fi |
+case "$show_only,$remove_files" in
+true,*)
+ xargs -0 echo
+ ;;
+*,true)
+ xargs -0 sh -c "
+ while [ \$# -gt 0 ]; do
+ file=\$1; shift
+ rm -- \"\$file\" && git-update-index --remove $verbose \"\$file\"
+ done
+ " inline
;;
*)
- [[ "$remove_files" = "true" ]] && rm -- $files
- git-update-index $index_remove_option $verbose $files
+ git-update-index --force-remove $verbose -z --stdin
;;
esac