The eleventh batch
[alt-git.git] / t / t4209-log-pickaxe.sh
blobb42fdc54fcb544349dd2fdb7fd8f48b0bf241442
1 #!/bin/sh
3 test_description='log --grep/--author/--regexp-ignore-case/-S/-G'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_log () {
9 expect=$1
10 kind=$2
11 needle=$3
12 shift 3
13 rest=$@
15 case $kind in
16 --*)
17 opt=$kind=$needle
20 opt=$kind$needle
22 esac
23 case $expect in
24 expect_nomatch)
25 match=nomatch
28 match=match
30 esac
32 test_expect_success "log $kind${rest:+ $rest} ($match)" "
33 git log $rest $opt --format=%H >actual &&
34 test_cmp $expect actual
38 # test -i and --regexp-ignore-case and expect both to behave the same way
39 test_log_icase () {
40 test_log $@ --regexp-ignore-case
41 test_log $@ -i
44 test_expect_success setup '
45 >expect_nomatch &&
47 >file &&
48 git add file &&
49 test_tick &&
50 git commit -m initial &&
51 git rev-parse --verify HEAD >expect_initial &&
53 echo Picked >file &&
54 git add file &&
55 test_tick &&
56 git commit --author="Another Person <another@example.com>" -m second &&
57 git rev-parse --verify HEAD >expect_second
60 test_expect_success 'usage' '
61 test_expect_code 129 git log -S 2>err &&
62 test_grep "switch.*requires a value" err &&
64 test_expect_code 129 git log -G 2>err &&
65 test_grep "switch.*requires a value" err &&
67 test_expect_code 128 git log -Gregex -Sstring 2>err &&
68 grep "cannot be used together" err &&
70 test_expect_code 128 git log -Gregex --find-object=HEAD 2>err &&
71 grep "cannot be used together" err &&
73 test_expect_code 128 git log -Sstring --find-object=HEAD 2>err &&
74 grep "cannot be used together" err &&
76 test_expect_code 128 git log --pickaxe-all --find-object=HEAD 2>err &&
77 grep "cannot be used together" err
80 test_expect_success 'usage: --pickaxe-regex' '
81 test_expect_code 128 git log -Gregex --pickaxe-regex 2>err &&
82 grep "cannot be used together" err
85 test_expect_success 'usage: --no-pickaxe-regex' '
86 cat >expect <<-\EOF &&
87 fatal: unrecognized argument: --no-pickaxe-regex
88 EOF
90 test_expect_code 128 git log -Sstring --no-pickaxe-regex 2>actual &&
91 test_cmp expect actual &&
93 test_expect_code 128 git log -Gstring --no-pickaxe-regex 2>err &&
94 test_cmp expect actual
97 test_log expect_initial --grep initial
98 test_log expect_nomatch --grep InItial
99 test_log_icase expect_initial --grep InItial
100 test_log_icase expect_nomatch --grep initail
102 test_log expect_second --author Person
103 test_log expect_nomatch --author person
104 test_log_icase expect_second --author person
105 test_log_icase expect_nomatch --author spreon
107 test_log expect_nomatch -G picked
108 test_log expect_second -G Picked
109 test_log_icase expect_nomatch -G pickle
110 test_log_icase expect_second -G picked
112 test_expect_success 'log -G --textconv (missing textconv tool)' '
113 echo "* diff=test" >.gitattributes &&
114 test_must_fail git -c diff.test.textconv=missing log -Gfoo &&
115 rm .gitattributes
118 test_expect_success 'log -G --no-textconv (missing textconv tool)' '
119 echo "* diff=test" >.gitattributes &&
120 git -c diff.test.textconv=missing log -Gfoo --no-textconv >actual &&
121 test_cmp expect_nomatch actual &&
122 rm .gitattributes
125 test_log expect_nomatch -S picked
126 test_log expect_second -S Picked
127 test_log_icase expect_second -S picked
128 test_log_icase expect_nomatch -S pickle
130 test_log expect_nomatch -S p.cked --pickaxe-regex
131 test_log expect_second -S P.cked --pickaxe-regex
132 test_log_icase expect_second -S p.cked --pickaxe-regex
133 test_log_icase expect_nomatch -S p.ckle --pickaxe-regex
135 test_expect_success 'log -S --textconv (missing textconv tool)' '
136 echo "* diff=test" >.gitattributes &&
137 test_must_fail git -c diff.test.textconv=missing log -Sfoo &&
138 rm .gitattributes
141 test_expect_success 'log -S --no-textconv (missing textconv tool)' '
142 echo "* diff=test" >.gitattributes &&
143 git -c diff.test.textconv=missing log -Sfoo --no-textconv >actual &&
144 test_cmp expect_nomatch actual &&
145 rm .gitattributes
148 test_expect_success 'setup log -[GS] plain & regex' '
149 test_create_repo GS-plain &&
150 test_commit -C GS-plain --append A data.txt "a" &&
151 test_commit -C GS-plain --append B data.txt "a a" &&
152 test_commit -C GS-plain --append C data.txt "b" &&
153 test_commit -C GS-plain --append D data.txt "[b]" &&
154 test_commit -C GS-plain E data.txt "" &&
156 # We also include E, the deletion commit
157 git -C GS-plain log --grep="[ABE]" >A-to-B-then-E-log &&
158 git -C GS-plain log --grep="[CDE]" >C-to-D-then-E-log &&
159 git -C GS-plain log --grep="[DE]" >D-then-E-log &&
160 git -C GS-plain log >full-log
163 test_expect_success 'log -G trims diff new/old [-+]' '
164 git -C GS-plain log -G"[+-]a" >log &&
165 test_must_be_empty log &&
166 git -C GS-plain log -G"^a" >log &&
167 test_cmp log A-to-B-then-E-log
170 test_expect_success 'log -S<pat> is not a regex, but -S<pat> --pickaxe-regex is' '
171 git -C GS-plain log -S"a" >log &&
172 test_cmp log A-to-B-then-E-log &&
174 git -C GS-plain log -S"[a]" >log &&
175 test_must_be_empty log &&
177 git -C GS-plain log -S"[a]" --pickaxe-regex >log &&
178 test_cmp log A-to-B-then-E-log &&
180 git -C GS-plain log -S"[b]" >log &&
181 test_cmp log D-then-E-log &&
183 git -C GS-plain log -S"[b]" --pickaxe-regex >log &&
184 test_cmp log C-to-D-then-E-log
187 test_expect_success 'setup log -[GS] binary & --text' '
188 test_create_repo GS-bin-txt &&
189 test_commit -C GS-bin-txt --printf A data.bin "a\na\0a\n" &&
190 test_commit -C GS-bin-txt --append --printf B data.bin "a\na\0a\n" &&
191 test_commit -C GS-bin-txt C data.bin "" &&
192 git -C GS-bin-txt log >full-log
195 test_expect_success 'log -G ignores binary files' '
196 git -C GS-bin-txt log -Ga >log &&
197 test_must_be_empty log
200 test_expect_success 'log -G looks into binary files with -a' '
201 git -C GS-bin-txt log -a -Ga >log &&
202 test_cmp log full-log
205 test_expect_success 'log -G looks into binary files with textconv filter' '
206 test_when_finished "rm GS-bin-txt/.gitattributes" &&
208 cd GS-bin-txt &&
209 echo "* diff=bin" >.gitattributes &&
210 git -c diff.bin.textconv=cat log -Ga >../log
211 ) &&
212 test_cmp log full-log
215 test_expect_success 'log -S looks into binary files' '
216 git -C GS-bin-txt log -Sa >log &&
217 test_cmp log full-log
220 test_expect_success 'log -S --pickaxe-regex looks into binary files' '
221 git -C GS-bin-txt log --pickaxe-regex -Sa >log &&
222 test_cmp log full-log &&
224 git -C GS-bin-txt log --pickaxe-regex -S"[a]" >log &&
225 test_cmp log full-log
228 test_done