Make git-send-pack exit with error when some refs couldn't be pushed out
[git/debian.git] / git-grep.sh
blob44c16130bd93fea8b6f172f1614115801f8df2d9
1 #!/bin/sh
3 # Copyright (c) Linus Torvalds, 2005
6 pattern=
7 flags=()
8 git_flags=()
9 while : ; do
10 case "$1" in
11 --cached|--deleted|--others|--killed|\
12 --ignored|--exclude=*|\
13 --exclude-from=*|\--exclude-per-directory=*)
14 git_flags=("${git_flags[@]}" "$1")
16 -e)
17 pattern="$2"
18 shift
20 -A|-B|-C|-D|-d|-f|-m)
21 flags=("${flags[@]}" "$1" "$2")
22 shift
24 --)
25 # The rest are git-ls-files paths (or flags)
26 shift
27 break
29 -*)
30 flags=("${flags[@]}" "$1")
33 if [ -z "$pattern" ]; then
34 pattern="$1"
35 shift
37 break
39 esac
40 shift
41 done
42 [ "$pattern" ] || {
43 echo >&2 "usage: 'git grep <pattern> [pathspec*]'"
44 exit 1
46 git-ls-files -z "${git_flags[@]}" "$@" |
47 xargs -0 grep "${flags[@]}" -e "$pattern"