GIT 1.6.2.5
[git/haiku.git] / t / t7002-grep.sh
blobb81593780a2a6adaf34bb10293b607e3a303cfcd
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 test_expect_success 'grep should not segfault with a bad input' '
30 test_must_fail git grep "("
33 for H in HEAD ''
35 case "$H" in
36 HEAD) HC='HEAD:' L='HEAD' ;;
37 '') HC= L='in working tree' ;;
38 esac
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
46 } >expected &&
47 git grep -n -w -e mmap $H >actual &&
48 diff expected actual
51 test_expect_success "grep -w $L (x)" '
53 echo ${HC}x:1:x x xx x
54 } >expected &&
55 git grep -n -w -e "x xx* x" $H >actual &&
56 diff expected actual
59 test_expect_success "grep -w $L (y-1)" '
61 echo ${HC}y:1:y yy
62 } >expected &&
63 git grep -n -w -e "^y" $H >actual &&
64 diff expected actual
67 test_expect_success "grep -w $L (y-2)" '
68 : >expected &&
69 if git grep -n -w -e "^y y" $H >actual
70 then
71 echo should not have matched
72 cat actual
73 false
74 else
75 diff expected actual
79 test_expect_success "grep -w $L (z)" '
80 : >expected &&
81 if git grep -n -w -e "^z" $H >actual
82 then
83 echo should not have matched
84 cat actual
85 false
86 else
87 diff expected actual
91 test_expect_success "grep $L (t-1)" '
92 echo "${HC}t/t:1:test" >expected &&
93 git grep -n -e test $H >actual &&
94 diff expected actual
97 test_expect_success "grep $L (t-2)" '
98 echo "${HC}t:1:test" >expected &&
100 cd t &&
101 git grep -n -e test $H
102 ) >actual &&
103 diff expected actual
106 test_expect_success "grep $L (t-3)" '
107 echo "${HC}t/t:1:test" >expected &&
109 cd t &&
110 git grep --full-name -n -e test $H
111 ) >actual &&
112 diff expected actual
115 test_expect_success "grep -c $L (no /dev/null)" '
116 ! git grep -c test $H | grep /dev/null
119 done
121 test_expect_success 'log grep setup' '
122 echo a >>file &&
123 test_tick &&
124 GIT_AUTHOR_NAME="With * Asterisk" \
125 GIT_AUTHOR_EMAIL="xyzzy@frotz.com" \
126 git commit -a -m "second" &&
128 echo a >>file &&
129 test_tick &&
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 &&
166 >expect &&
167 test_cmp expect actual
170 test_expect_success 'grep with CE_VALID file' '
171 git update-index --assume-unchanged t/t &&
172 rm t/t &&
173 test "$(git grep --no-ext-grep t)" = "t/t:test" &&
174 git update-index --no-assume-unchanged t/t &&
175 git checkout t/t
178 test_done