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
24 git add file x y z t/t &&
29 test_expect_success
'grep should not segfault with a bad input' '
30 test_must_fail git grep "("
36 HEAD
) HC
='HEAD:' L
='HEAD' ;;
37 '') HC
= L
='in working tree' ;;
40 test_expect_success
"grep -w $L" '
42 echo ${HC}file:1:foo mmap bar
43 echo ${HC}file:3:foo_mmap bar mmap
44 echo ${HC}file:4:foo mmap bar_mmap
45 echo ${HC}file:5:foo_mmap bar mmap baz
47 git grep -n -w -e mmap $H >actual &&
51 test_expect_success
"grep -w $L (x)" '
53 echo ${HC}x:1:x x xx x
55 git grep -n -w -e "x xx* x" $H >actual &&
59 test_expect_success
"grep -w $L (y-1)" '
63 git grep -n -w -e "^y" $H >actual &&
67 test_expect_success
"grep -w $L (y-2)" '
69 if git grep -n -w -e "^y y" $H >actual
71 echo should not have matched
79 test_expect_success
"grep -w $L (z)" '
81 if git grep -n -w -e "^z" $H >actual
83 echo should not have matched
91 test_expect_success
"grep $L (t-1)" '
92 echo "${HC}t/t:1:test" >expected &&
93 git grep -n -e test $H >actual &&
97 test_expect_success
"grep $L (t-2)" '
98 echo "${HC}t:1:test" >expected &&
101 git grep -n -e test $H
106 test_expect_success
"grep $L (t-3)" '
107 echo "${HC}t/t:1:test" >expected &&
110 git grep --full-name -n -e test $H
115 test_expect_success
"grep -c $L (no /dev/null)" '
116 ! git grep -c test $H | grep -q /dev/null
121 test_expect_success
'log grep setup' '
124 GIT_AUTHOR_NAME="With * Asterisk" \
125 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
126 git commit -a -m "second" &&
130 git commit -a -m "third"
134 test_expect_success
'log grep (1)' '
135 git log --author=author --pretty=tformat:%s >actual &&
136 ( echo third ; echo initial ) >expect &&
137 test_cmp expect actual
140 test_expect_success
'log grep (2)' '
141 git log --author=" * " -F --pretty=tformat:%s >actual &&
142 ( echo second ) >expect &&
143 test_cmp expect actual
146 test_expect_success
'log grep (3)' '
147 git log --author="^A U" --pretty=tformat:%s >actual &&
148 ( echo third ; echo initial ) >expect &&
149 test_cmp expect actual
152 test_expect_success
'log grep (4)' '
153 git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
154 ( echo second ) >expect &&
155 test_cmp expect actual
158 test_expect_success
'log grep (5)' '
159 git log --author=Thor -F --grep=Thu --pretty=tformat:%s >actual &&
160 ( echo third ; echo initial ) >expect &&
161 test_cmp expect actual
164 test_expect_success
'log grep (6)' '
165 git log --author=-0700 --pretty=tformat:%s >actual &&
167 test_cmp expect actual