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