diff options
author | Carl Worth <cworth@cworth.org> | 2006-02-21 15:04:51 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-02-22 17:10:42 -0800 |
commit | d4a1cab541be0c276b38285c8b33050ea411eacf (patch) | |
tree | fa392a19be606f1f90e0792d8407df3a4bf09969 /git-rm.sh | |
parent | 2cf3be1d31b322cf45640f3019a32d19a8a9b6f8 (diff) | |
download | git-d4a1cab541be0c276b38285c8b33050ea411eacf.tar.gz git-d4a1cab541be0c276b38285c8b33050ea411eacf.tar.xz |
Add new git-rm command with documentation
This adds a git-rm command which provides convenience similar to
git-add, (and a bit more since it takes care of the rm as well if
given -f).
Like git-add, git-rm expands the given path names through
git-ls-files. This means it only acts on files listed in the
index. And it does act recursively on directories by default, (no -r
needed as in the case of rm itself). When it recurses, it does not
remove empty directories that are left behind.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'git-rm.sh')
-rwxr-xr-x | git-rm.sh | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/git-rm.sh b/git-rm.sh new file mode 100755 index 000000000..0a3f54668 --- /dev/null +++ b/git-rm.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +USAGE='[-f] [-n] [-v] [--] <file>...' +SUBDIRECTORY_OK='Yes' +. git-sh-setup + +index_remove_option=--force-remove +remove_files= +show_only= +verbose= +while : ; do + case "$1" in + -f) + remove_files=true + index_remote_option=--force + ;; + -n) + show_only=true + ;; + -v) + verbose=--verbose + ;; + --) + shift; break + ;; + -*) + usage + ;; + *) + break + ;; + esac + shift +done + +# This is typo-proofing. If some paths match and some do not, we want +# to do nothing. +case "$#" in +0) ;; +*) + git-ls-files --error-unmatch -- "$@" >/dev/null || { + echo >&2 "Maybe you misspelled it?" + exit 1 + } + ;; +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 \ + --exclude-per-directory=.gitignore -- "$@" + fi | sort | uniq +) + +case "$show_only" in +true) + echo $files + ;; +*) + [[ "$remove_files" = "true" ]] && rm -- $files + git-update-index $index_remove_option $verbose $files + ;; +esac |