grep: grep cache entries if they are "assume unchanged"
[git/mjg.git] / t / t7002-grep.sh
blobc4938544d4ca7c5e7e886a59144c9b10b7971748
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='git grep various.
9 . ./test-lib.sh
11 test_expect_success setup '
13 echo foo mmap bar
14 echo foo_mmap bar
15 echo foo_mmap bar mmap
16 echo foo mmap bar_mmap
17 echo foo_mmap bar mmap baz
18 } >file &&
19 echo x x xx x >x &&
20 echo y yy >y &&
21 echo zzz > z &&
22 mkdir t &&
23 echo test >t/t &&
24 git add file x y z t/t &&
25 test_tick &&
26 git commit -m initial
29 for H in HEAD ''
31 case "$H" in
32 HEAD) HC='HEAD:' L='HEAD' ;;
33 '') HC= L='in working tree' ;;
34 esac
36 test_expect_success "grep -w $L" '
38 echo ${HC}file:1:foo mmap bar
39 echo ${HC}file:3:foo_mmap bar mmap
40 echo ${HC}file:4:foo mmap bar_mmap
41 echo ${HC}file:5:foo_mmap bar mmap baz
42 } >expected &&
43 git grep -n -w -e mmap $H >actual &&
44 diff expected actual
47 test_expect_success "grep -w $L (x)" '
49 echo ${HC}x:1:x x xx x
50 } >expected &&
51 git grep -n -w -e "x xx* x" $H >actual &&
52 diff expected actual
55 test_expect_success "grep -w $L (y-1)" '
57 echo ${HC}y:1:y yy
58 } >expected &&
59 git grep -n -w -e "^y" $H >actual &&
60 diff expected actual
63 test_expect_success "grep -w $L (y-2)" '
64 : >expected &&
65 if git grep -n -w -e "^y y" $H >actual
66 then
67 echo should not have matched
68 cat actual
69 false
70 else
71 diff expected actual
75 test_expect_success "grep -w $L (z)" '
76 : >expected &&
77 if git grep -n -w -e "^z" $H >actual
78 then
79 echo should not have matched
80 cat actual
81 false
82 else
83 diff expected actual
87 test_expect_success "grep $L (t-1)" '
88 echo "${HC}t/t:1:test" >expected &&
89 git grep -n -e test $H >actual &&
90 diff expected actual
93 test_expect_success "grep $L (t-2)" '
94 echo "${HC}t:1:test" >expected &&
96 cd t &&
97 git grep -n -e test $H
98 ) >actual &&
99 diff expected actual
102 test_expect_success "grep $L (t-3)" '
103 echo "${HC}t/t:1:test" >expected &&
105 cd t &&
106 git grep --full-name -n -e test $H
107 ) >actual &&
108 diff expected actual
111 test_expect_success "grep -c $L (no /dev/null)" '
112 ! git grep -c test $H | grep /dev/null
115 done
117 test_expect_success 'log grep setup' '
118 echo a >>file &&
119 test_tick &&
120 GIT_AUTHOR_NAME="With * Asterisk" \
121 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
122 git commit -a -m "second" &&
124 echo a >>file &&
125 test_tick &&
126 git commit -a -m "third"
130 test_expect_success 'log grep (1)' '
131 git log --author=author --pretty=tformat:%s >actual &&
132 ( echo third ; echo initial ) >expect &&
133 test_cmp expect actual
136 test_expect_success 'log grep (2)' '
137 git log --author=" * " -F --pretty=tformat:%s >actual &&
138 ( echo second ) >expect &&
139 test_cmp expect actual
142 test_expect_success 'log grep (3)' '
143 git log --author="^A U" --pretty=tformat:%s >actual &&
144 ( echo third ; echo initial ) >expect &&
145 test_cmp expect actual
148 test_expect_success 'log grep (4)' '
149 git log --author="frotz\.com>$" --pretty=tformat:%s >actual &&
150 ( echo second ) >expect &&
151 test_cmp expect actual
154 test_expect_success 'log grep (5)' '
155 git log --author=Thor -F --grep=Thu --pretty=tformat:%s >actual &&
156 ( echo third ; echo initial ) >expect &&
157 test_cmp expect actual
160 test_expect_success 'log grep (6)' '
161 git log --author=-0700 --pretty=tformat:%s >actual &&
162 >expect &&
163 test_cmp expect actual
166 test_expect_success 'grep with CE_VALID file' '
167 git update-index --assume-unchanged t/t &&
168 rm t/t &&
169 test "$(git grep --no-ext-grep t)" = "t/t:test" &&
170 git update-index --no-assume-unchanged t/t &&
171 git checkout t/t
174 test_done