Revert "We do not like "HEAD" as a new branch name"
[git/jrn.git] / git-grep.sh
blob2ed8e955d6c44da7bd15342aac64de997f0f4bf4
1 #!/bin/sh
3 # Copyright (c) Linus Torvalds, 2005
6 USAGE='<option>... <pattern> <path>...'
7 SUBDIRECTORY_OK='Yes'
8 . git-sh-setup
10 pattern=
11 flags=()
12 git_flags=()
13 while : ; do
14 case "$1" in
15 --cached|--deleted|--others|--killed|\
16 --ignored|--exclude=*|\
17 --exclude-from=*|\--exclude-per-directory=*)
18 git_flags=("${git_flags[@]}" "$1")
20 -e)
21 pattern="$2"
22 shift
24 -A|-B|-C|-D|-d|-f|-m)
25 flags=("${flags[@]}" "$1" "$2")
26 shift
28 --)
29 # The rest are git-ls-files paths (or flags)
30 shift
31 break
33 -*)
34 flags=("${flags[@]}" "$1")
37 if [ -z "$pattern" ]; then
38 pattern="$1"
39 shift
41 break
43 esac
44 shift
45 done
46 [ "$pattern" ] || {
47 usage
49 git-ls-files -z "${git_flags[@]}" "$@" |
50 xargs -0 grep "${flags[@]}" -e "$pattern"