Merge branch 'ab/config-based-hooks-base' into seen
[git] / t / t4209-log-pickaxe.sh
1 #!/bin/sh
2
3 test_description='log --grep/--author/--regexp-ignore-case/-S/-G'
4 . ./test-lib.sh
5
6 test_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
36 # test -i and --regexp-ignore-case and expect both to behave the same way
37 test_log_icase () {
38         test_log $@ --regexp-ignore-case
39         test_log $@ -i
40 }
41
42 test_expect_success setup '
43         >expect_nomatch &&
44
45         >file &&
46         git add file &&
47         test_tick &&
48         git commit -m initial &&
49         git rev-parse --verify HEAD >expect_initial &&
50
51         echo Picked >file &&
52         git add file &&
53         test_tick &&
54         git commit --author="Another Person <another@example.com>" -m second &&
55         git rev-parse --verify HEAD >expect_second
56 '
57
58 test_expect_success 'usage' '
59         test_expect_code 129 git log -S 2>err &&
60         test_i18ngrep "switch.*requires a value" err &&
61
62         test_expect_code 129 git log -G 2>err &&
63         test_i18ngrep "switch.*requires a value" err &&
64
65         test_expect_code 128 git log -Gregex -Sstring 2>err &&
66         grep "mutually exclusive" err &&
67
68         test_expect_code 128 git log -Gregex --find-object=HEAD 2>err &&
69         grep "mutually exclusive" err &&
70
71         test_expect_code 128 git log -Sstring --find-object=HEAD 2>err &&
72         grep "mutually exclusive" err &&
73
74         test_expect_code 128 git log --pickaxe-all --find-object=HEAD 2>err &&
75         grep "mutually exclusive" err
76 '
77
78 test_expect_success 'usage: --pickaxe-regex' '
79         test_expect_code 128 git log -Gregex --pickaxe-regex 2>err &&
80         grep "mutually exclusive" err
81 '
82
83 test_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
95 test_log        expect_initial  --grep initial
96 test_log        expect_nomatch  --grep InItial
97 test_log_icase  expect_initial  --grep InItial
98 test_log_icase  expect_nomatch  --grep initail
99
100 test_log        expect_second   --author Person
101 test_log        expect_nomatch  --author person
102 test_log_icase  expect_second   --author person
103 test_log_icase  expect_nomatch  --author spreon
104
105 test_log        expect_nomatch  -G picked
106 test_log        expect_second   -G Picked
107 test_log_icase  expect_nomatch  -G pickle
108 test_log_icase  expect_second   -G picked
109
110 test_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
116 test_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 &&
119         test_cmp expect_nomatch actual &&
120         rm .gitattributes
121 '
122
123 test_log        expect_nomatch  -S picked
124 test_log        expect_second   -S Picked
125 test_log_icase  expect_second   -S picked
126 test_log_icase  expect_nomatch  -S pickle
127
128 test_log        expect_nomatch  -S p.cked --pickaxe-regex
129 test_log        expect_second   -S P.cked --pickaxe-regex
130 test_log_icase  expect_second   -S p.cked --pickaxe-regex
131 test_log_icase  expect_nomatch  -S p.ckle --pickaxe-regex
132
133 test_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
139 test_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 &&
142         test_cmp expect_nomatch actual &&
143         rm .gitattributes
144 '
145
146 test_expect_success 'setup log -[GS] plain & regex' '
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" &&
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 &&
158         git -C GS-plain log >full-log
159 '
160
161 test_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 &&
165         test_cmp log A-to-B-then-E-log
166 '
167
168 test_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
183 '
184
185 test_expect_success 'setup log -[GS] binary & --text' '
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
191 '
192
193 test_expect_success 'log -G ignores binary files' '
194         git -C GS-bin-txt log -Ga >log &&
195         test_must_be_empty log
196 '
197
198 test_expect_success 'log -G looks into binary files with -a' '
199         git -C GS-bin-txt log -a -Ga >log &&
200         test_cmp log full-log
201 '
202
203 test_expect_success 'log -G looks into binary files with textconv filter' '
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         ) &&
210         test_cmp log full-log
211 '
212
213 test_expect_success 'log -S looks into binary files' '
214         git -C GS-bin-txt log -Sa >log &&
215         test_cmp log full-log
216 '
217
218 test_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
226 test_done