aboutsummaryrefslogtreecommitdiff
path: root/git-rm.sh
blob: fda4541c766cb1606402259cc1a6e0281105732f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh

USAGE='[-f] [-n] [-v] [--] <file>...'
SUBDIRECTORY_OK='Yes'
. git-sh-setup

remove_files=
show_only=
verbose=
while : ; do
  case "$1" in
    -f)
	remove_files=true
	;;
    -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

if test -f "$GIT_DIR/info/exclude"
then
	git-ls-files -z \
	--exclude-from="$GIT_DIR/info/exclude" \
	--exclude-per-directory=.gitignore -- "$@"
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
	;;
*)
	git-update-index --force-remove $verbose -z --stdin
	;;
esac