2005-09-12 19:06:10 +00:00
|
|
|
#!/bin/sh
|
2005-09-12 23:46:53 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) Linus Torvalds, 2005
|
|
|
|
#
|
|
|
|
|
2006-01-20 23:00:12 +00:00
|
|
|
USAGE='[<option>...] [-e] <pattern> [<path>...]'
|
2005-12-13 22:30:31 +00:00
|
|
|
SUBDIRECTORY_OK='Yes'
|
|
|
|
. git-sh-setup
|
|
|
|
|
2006-01-20 23:00:12 +00:00
|
|
|
got_pattern () {
|
|
|
|
if [ -z "$no_more_patterns" ]
|
|
|
|
then
|
|
|
|
pattern="$1" no_more_patterns=yes
|
|
|
|
else
|
|
|
|
die "git-grep: do not specify more than one pattern"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
no_more_patterns=
|
2005-09-12 23:46:53 +00:00
|
|
|
pattern=
|
|
|
|
flags=()
|
|
|
|
git_flags=()
|
|
|
|
while : ; do
|
|
|
|
case "$1" in
|
2006-01-20 23:00:12 +00:00
|
|
|
-o|--cached|--deleted|--others|--killed|\
|
|
|
|
--ignored|--modified|--exclude=*|\
|
2005-09-12 23:46:53 +00:00
|
|
|
--exclude-from=*|\--exclude-per-directory=*)
|
|
|
|
git_flags=("${git_flags[@]}" "$1")
|
|
|
|
;;
|
|
|
|
-e)
|
2006-01-20 23:00:12 +00:00
|
|
|
got_pattern "$2"
|
2005-09-12 23:46:53 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-A|-B|-C|-D|-d|-f|-m)
|
|
|
|
flags=("${flags[@]}" "$1" "$2")
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--)
|
2006-01-20 23:00:12 +00:00
|
|
|
# The rest are git-ls-files paths
|
2005-09-12 23:46:53 +00:00
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
flags=("${flags[@]}" "$1")
|
|
|
|
;;
|
|
|
|
*)
|
2006-01-20 23:00:12 +00:00
|
|
|
if [ -z "$no_more_patterns" ]
|
|
|
|
then
|
|
|
|
got_pattern "$1"
|
2005-09-12 23:46:53 +00:00
|
|
|
shift
|
|
|
|
fi
|
2006-01-20 23:00:12 +00:00
|
|
|
[ "$1" = -- ] && shift
|
2005-09-12 23:46:53 +00:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
2005-09-12 19:06:10 +00:00
|
|
|
done
|
2005-11-16 17:38:46 +00:00
|
|
|
[ "$pattern" ] || {
|
2005-12-13 22:30:31 +00:00
|
|
|
usage
|
2005-11-16 17:38:46 +00:00
|
|
|
}
|
2006-01-20 23:00:12 +00:00
|
|
|
git-ls-files -z "${git_flags[@]}" -- "$@" |
|
|
|
|
xargs -0 grep "${flags[@]}" -e "$pattern" --
|