Add new git-rm command with documentation
[git.git] / git-rm.sh
1 #!/bin/sh
2
3 USAGE='[-f] [-n] [-v] [--] <file>...'
4 SUBDIRECTORY_OK='Yes'
5 . git-sh-setup
6
7 index_remove_option=--force-remove
8 remove_files=
9 show_only=
10 verbose=
11 while : ; do
12   case "$1" in
13     -f)
14         remove_files=true
15         index_remote_option=--force
16         ;;
17     -n)
18         show_only=true
19         ;;
20     -v)
21         verbose=--verbose
22         ;;
23     --)
24         shift; break
25         ;;
26     -*)
27         usage
28         ;;
29     *)
30         break
31         ;;
32   esac
33   shift
34 done
35
36 # This is typo-proofing. If some paths match and some do not, we want
37 # to do nothing.
38 case "$#" in
39 0)      ;;
40 *)
41         git-ls-files --error-unmatch -- "$@" >/dev/null || {
42                 echo >&2 "Maybe you misspelled it?"
43                 exit 1
44         }
45         ;;
46 esac
47
48 files=$(
49     if test -f "$GIT_DIR/info/exclude" ; then
50         git-ls-files \
51             --exclude-from="$GIT_DIR/info/exclude" \
52             --exclude-per-directory=.gitignore -- "$@"
53     else
54         git-ls-files \
55         --exclude-per-directory=.gitignore -- "$@"
56     fi | sort | uniq
57 )
58
59 case "$show_only" in
60 true)
61         echo $files
62         ;;
63 *)
64         [[ "$remove_files" = "true" ]] && rm -- $files
65         git-update-index $index_remove_option $verbose $files
66         ;;
67 esac