]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4209-log-pickaxe.sh
The third batch
[thirdparty/git.git] / t / t4209-log-pickaxe.sh
CommitLineData
accccde4
JH
1#!/bin/sh
2
3test_description='log --grep/--author/--regexp-ignore-case/-S/-G'
4. ./test-lib.sh
5
57b6dc76
RS
6test_log () {
7 expect=$1
8 kind=$2
9 needle=$3
10 shift 3
11 rest=$@
12
13 case $kind in
14 --*)
15 opt=$kind=$needle
16 ;;
17 *)
18 opt=$kind$needle
19 ;;
20 esac
21 case $expect in
22 expect_nomatch)
23 match=nomatch
24 ;;
25 *)
26 match=match
27 ;;
28 esac
29
30 test_expect_success "log $kind${rest:+ $rest} ($match)" "
31 git log $rest $opt --format=%H >actual &&
32 test_cmp $expect actual
33 "
34}
35
e7880fcd
RS
36# test -i and --regexp-ignore-case and expect both to behave the same way
37test_log_icase () {
38 test_log $@ --regexp-ignore-case
39 test_log $@ -i
40}
41
accccde4 42test_expect_success setup '
b0f7c7cf
RS
43 >expect_nomatch &&
44
accccde4
JH
45 >file &&
46 git add file &&
47 test_tick &&
48 git commit -m initial &&
b0f7c7cf 49 git rev-parse --verify HEAD >expect_initial &&
accccde4
JH
50
51 echo Picked >file &&
b0f7c7cf 52 git add file &&
accccde4 53 test_tick &&
b0f7c7cf
RS
54 git commit --author="Another Person <another@example.com>" -m second &&
55 git rev-parse --verify HEAD >expect_second
accccde4
JH
56'
57
064952fc 58test_expect_success 'usage' '
2e197a75 59 test_expect_code 129 git log -S 2>err &&
6789275d 60 test_grep "switch.*requires a value" err &&
2e197a75
ÆAB
61
62 test_expect_code 129 git log -G 2>err &&
6789275d 63 test_grep "switch.*requires a value" err &&
2e197a75 64
064952fc 65 test_expect_code 128 git log -Gregex -Sstring 2>err &&
c4881829 66 grep "cannot be used together" err &&
064952fc
ÆAB
67
68 test_expect_code 128 git log -Gregex --find-object=HEAD 2>err &&
c4881829 69 grep "cannot be used together" err &&
064952fc
ÆAB
70
71 test_expect_code 128 git log -Sstring --find-object=HEAD 2>err &&
c4881829 72 grep "cannot be used together" err &&
d26ec880
ÆAB
73
74 test_expect_code 128 git log --pickaxe-all --find-object=HEAD 2>err &&
246cac85 75 grep "cannot be used together" err
064952fc
ÆAB
76'
77
188e9e28
ÆAB
78test_expect_success 'usage: --pickaxe-regex' '
79 test_expect_code 128 git log -Gregex --pickaxe-regex 2>err &&
246cac85 80 grep "cannot be used together" err
188e9e28
ÆAB
81'
82
7cd5d5b2
ÆAB
83test_expect_success 'usage: --no-pickaxe-regex' '
84 cat >expect <<-\EOF &&
85 fatal: unrecognized argument: --no-pickaxe-regex
86 EOF
87
88 test_expect_code 128 git log -Sstring --no-pickaxe-regex 2>actual &&
89 test_cmp expect actual &&
90
91 test_expect_code 128 git log -Gstring --no-pickaxe-regex 2>err &&
92 test_cmp expect actual
93'
94
65a3402f
RS
95test_log expect_initial --grep initial
96test_log expect_nomatch --grep InItial
97test_log_icase expect_initial --grep InItial
98test_log_icase expect_nomatch --grep initail
accccde4 99
31a8189a
RS
100test_log expect_second --author Person
101test_log expect_nomatch --author person
102test_log_icase expect_second --author person
103test_log_icase expect_nomatch --author spreon
accccde4 104
e7880fcd
RS
105test_log expect_nomatch -G picked
106test_log expect_second -G Picked
107test_log_icase expect_nomatch -G pickle
108test_log_icase expect_second -G picked
accccde4 109
a8f61094
SR
110test_expect_success 'log -G --textconv (missing textconv tool)' '
111 echo "* diff=test" >.gitattributes &&
112 test_must_fail git -c diff.test.textconv=missing log -Gfoo &&
113 rm .gitattributes
114'
115
116test_expect_success 'log -G --no-textconv (missing textconv tool)' '
117 echo "* diff=test" >.gitattributes &&
118 git -c diff.test.textconv=missing log -Gfoo --no-textconv >actual &&
b0f7c7cf 119 test_cmp expect_nomatch actual &&
a8f61094
SR
120 rm .gitattributes
121'
122
e7880fcd
RS
123test_log expect_nomatch -S picked
124test_log expect_second -S Picked
125test_log_icase expect_second -S picked
126test_log_icase expect_nomatch -S pickle
accccde4 127
218c45a4
RS
128test_log expect_nomatch -S p.cked --pickaxe-regex
129test_log expect_second -S P.cked --pickaxe-regex
130test_log_icase expect_second -S p.cked --pickaxe-regex
131test_log_icase expect_nomatch -S p.ckle --pickaxe-regex
132
a8f61094
SR
133test_expect_success 'log -S --textconv (missing textconv tool)' '
134 echo "* diff=test" >.gitattributes &&
135 test_must_fail git -c diff.test.textconv=missing log -Sfoo &&
136 rm .gitattributes
137'
138
139test_expect_success 'log -S --no-textconv (missing textconv tool)' '
140 echo "* diff=test" >.gitattributes &&
141 git -c diff.test.textconv=missing log -Sfoo --no-textconv >actual &&
b0f7c7cf 142 test_cmp expect_nomatch actual &&
a8f61094
SR
143 rm .gitattributes
144'
145
69ae9308 146test_expect_success 'setup log -[GS] plain & regex' '
c9609398
ÆAB
147 test_create_repo GS-plain &&
148 test_commit -C GS-plain --append A data.txt "a" &&
149 test_commit -C GS-plain --append B data.txt "a a" &&
69ae9308
ÆAB
150 test_commit -C GS-plain --append C data.txt "b" &&
151 test_commit -C GS-plain --append D data.txt "[b]" &&
152 test_commit -C GS-plain E data.txt "" &&
153
154 # We also include E, the deletion commit
155 git -C GS-plain log --grep="[ABE]" >A-to-B-then-E-log &&
156 git -C GS-plain log --grep="[CDE]" >C-to-D-then-E-log &&
157 git -C GS-plain log --grep="[DE]" >D-then-E-log &&
c9609398
ÆAB
158 git -C GS-plain log >full-log
159'
160
161test_expect_success 'log -G trims diff new/old [-+]' '
162 git -C GS-plain log -G"[+-]a" >log &&
163 test_must_be_empty log &&
164 git -C GS-plain log -G"^a" >log &&
69ae9308
ÆAB
165 test_cmp log A-to-B-then-E-log
166'
167
168test_expect_success 'log -S<pat> is not a regex, but -S<pat> --pickaxe-regex is' '
169 git -C GS-plain log -S"a" >log &&
170 test_cmp log A-to-B-then-E-log &&
171
172 git -C GS-plain log -S"[a]" >log &&
173 test_must_be_empty log &&
174
175 git -C GS-plain log -S"[a]" --pickaxe-regex >log &&
176 test_cmp log A-to-B-then-E-log &&
177
178 git -C GS-plain log -S"[b]" >log &&
179 test_cmp log D-then-E-log &&
180
181 git -C GS-plain log -S"[b]" --pickaxe-regex >log &&
182 test_cmp log C-to-D-then-E-log
c9609398
ÆAB
183'
184
e0e7cb80 185test_expect_success 'setup log -[GS] binary & --text' '
6d0a4016
ÆAB
186 test_create_repo GS-bin-txt &&
187 test_commit -C GS-bin-txt --printf A data.bin "a\na\0a\n" &&
188 test_commit -C GS-bin-txt --append --printf B data.bin "a\na\0a\n" &&
189 test_commit -C GS-bin-txt C data.bin "" &&
190 git -C GS-bin-txt log >full-log
e0e7cb80
TB
191'
192
193test_expect_success 'log -G ignores binary files' '
6d0a4016 194 git -C GS-bin-txt log -Ga >log &&
e0e7cb80
TB
195 test_must_be_empty log
196'
197
198test_expect_success 'log -G looks into binary files with -a' '
6d0a4016 199 git -C GS-bin-txt log -a -Ga >log &&
e0e7cb80
TB
200 test_cmp log full-log
201'
202
203test_expect_success 'log -G looks into binary files with textconv filter' '
6d0a4016
ÆAB
204 test_when_finished "rm GS-bin-txt/.gitattributes" &&
205 (
206 cd GS-bin-txt &&
207 echo "* diff=bin" >.gitattributes &&
208 git -c diff.bin.textconv=cat log -Ga >../log
209 ) &&
e0e7cb80
TB
210 test_cmp log full-log
211'
212
213test_expect_success 'log -S looks into binary files' '
6d0a4016 214 git -C GS-bin-txt log -Sa >log &&
e0e7cb80
TB
215 test_cmp log full-log
216'
217
52e011cd
ÆAB
218test_expect_success 'log -S --pickaxe-regex looks into binary files' '
219 git -C GS-bin-txt log --pickaxe-regex -Sa >log &&
220 test_cmp log full-log &&
221
222 git -C GS-bin-txt log --pickaxe-regex -S"[a]" >log &&
223 test_cmp log full-log
224'
225
accccde4 226test_done