3 # Copyright (c) 2006 Junio C Hamano
6 test_description
='git grep various.
11 test_expect_success setup
'
15 echo foo_mmap bar mmap
16 echo foo mmap bar_mmap
17 echo foo_mmap bar mmap baz
25 git add file w x y z t/t &&
30 test_expect_success
'grep should not segfault with a bad input' '
31 test_must_fail git grep "("
37 HEAD
) HC
='HEAD:' L
='HEAD' ;;
38 '') HC
= L
='in working tree' ;;
41 test_expect_success
"grep -w $L" '
43 echo ${HC}file:1:foo mmap bar
44 echo ${HC}file:3:foo_mmap bar mmap
45 echo ${HC}file:4:foo mmap bar_mmap
46 echo ${HC}file:5:foo_mmap bar mmap baz
48 git grep -n -w -e mmap $H >actual &&
52 test_expect_success
"grep -w $L (w)" '
54 ! git grep -n -w -e "^w" >actual &&
55 test_cmp expected actual
58 test_expect_success
"grep -w $L (x)" '
60 echo ${HC}x:1:x x xx x
62 git grep -n -w -e "x xx* x" $H >actual &&
66 test_expect_success
"grep -w $L (y-1)" '
70 git grep -n -w -e "^y" $H >actual &&
74 test_expect_success
"grep -w $L (y-2)" '
76 if git grep -n -w -e "^y y" $H >actual
78 echo should not have matched
86 test_expect_success
"grep -w $L (z)" '
88 if git grep -n -w -e "^z" $H >actual
90 echo should not have matched
98 test_expect_success
"grep $L (t-1)" '
99 echo "${HC}t/t:1:test" >expected &&
100 git grep -n -e test $H >actual &&
104 test_expect_success
"grep $L (t-2)" '
105 echo "${HC}t:1:test" >expected &&
108 git grep -n -e test $H
113 test_expect_success
"grep $L (t-3)" '
114 echo "${HC}t/t:1:test" >expected &&
117 git grep --full-name -n -e test $H
122 test_expect_success
"grep -c $L (no /dev/null)" '
123 ! git grep -c test $H | grep /dev/null
129 file:foo mmap bar_mmap
132 test_expect_success
'grep -e A --and -e B' '
133 git grep -e "foo mmap" --and -e bar_mmap >actual &&
134 test_cmp expected actual
138 file:foo_mmap bar mmap
139 file:foo_mmap bar mmap baz
143 test_expect_success
'grep ( -e A --or -e B ) --and -e B' '
144 git grep \( -e foo_ --or -e baz \) \
145 --and -e " mmap" >actual &&
146 test_cmp expected actual
153 test_expect_success
'grep -e A --and --not -e B' '
154 git grep -e "foo mmap" --and --not -e bar_mmap >actual &&
155 test_cmp expected actual
158 test_expect_success
'log grep setup' '
161 GIT_AUTHOR_NAME="With * Asterisk" \
162 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
163 git commit -a -m "second" &&
167 git commit -a -m "third"
171 test_expect_success
'log grep (1)' '
172 git log --author=author --pretty=tformat:%s >actual &&
173 ( echo third ; echo initial ) >expect &&
174 test_cmp expect actual
177 test_expect_success
'log grep (2)' '
178 git log --author=" * " -F --pretty=tformat:%s >actual &&
179 ( echo second ) >expect &&
180 test_cmp expect actual
183 test_expect_success
'log grep (3)' '
184 git log --author="^A U" --pretty=tformat:%s >actual &&
185 ( echo third ; echo initial ) >expect &&
186 test_cmp expect actual
189 test_expect_success
'log grep (4)' '
190 git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
191 ( echo second ) >expect &&
192 test_cmp expect actual
195 test_expect_success
'log grep (5)' '
196 git log --author=Thor -F --grep=Thu --pretty=tformat:%s >actual &&
197 ( echo third ; echo initial ) >expect &&
198 test_cmp expect actual
201 test_expect_success
'log grep (6)' '
202 git log --author=-0700 --pretty=tformat:%s >actual &&
204 test_cmp expect actual
207 test_expect_success
'grep with CE_VALID file' '
208 git update-index --assume-unchanged t/t &&
210 test "$(git grep --no-ext-grep t)" = "t/t:test" &&
211 git update-index --no-assume-unchanged t/t &&