Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t8014-blame-ignore-fuzzy.sh
blobe68e6115a66d3722413a1982aa86cc2a5d5932eb
1 #!/bin/sh
3 test_description='git blame ignore fuzzy heuristic'
4 . ./test-lib.sh
6 pick_author='s/^[0-9a-f^]* *(\([^ ]*\) .*/\1/'
8 # Each test is composed of 4 variables:
9 # titleN - the test name
10 # aN - the initial content
11 # bN - the final content
12 # expectedN - the line numbers from aN that we expect git blame
13 # on bN to identify, or "Final" if bN itself should
14 # be identified as the origin of that line.
16 # We start at test 2 because setup will show as test 1
17 title2="Regression test for partially overlapping search ranges"
18 cat <<EOF >a2
22 abcdef
26 ijkl
30 pqrs
34 wxyz
38 EOF
39 cat <<EOF >b2
40 abcde
41 ijk
42 pqr
43 wxy
44 EOF
45 cat <<EOF >expected2
50 EOF
52 title3="Combine 3 lines into 2"
53 cat <<EOF >a3
54 if ((maxgrow==0) ||
55 ( single_line_field && (field->dcols < maxgrow)) ||
56 (!single_line_field && (field->drows < maxgrow)))
57 EOF
58 cat <<EOF >b3
59 if ((maxgrow == 0) || (single_line_field && (field->dcols < maxgrow)) ||
60 (!single_line_field && (field->drows < maxgrow))) {
61 EOF
62 cat <<EOF >expected3
65 EOF
67 title4="Add curly brackets"
68 cat <<EOF >a4
69 if (rows) *rows = field->rows;
70 if (cols) *cols = field->cols;
71 if (frow) *frow = field->frow;
72 if (fcol) *fcol = field->fcol;
73 EOF
74 cat <<EOF >b4
75 if (rows) {
76 *rows = field->rows;
78 if (cols) {
79 *cols = field->cols;
81 if (frow) {
82 *frow = field->frow;
84 if (fcol) {
85 *fcol = field->fcol;
87 EOF
88 cat <<EOF >expected4
91 Final
94 Final
97 Final
100 Final
104 title5="Combine many lines and change case"
105 cat <<EOF >a5
106 for(row=0,pBuffer=field->buf;
107 row<height;
108 row++,pBuffer+=width )
110 if ((len = (int)( After_End_Of_Data( pBuffer, width ) - pBuffer )) > 0)
112 wmove( win, row, 0 );
113 waddnstr( win, pBuffer, len );
115 cat <<EOF >b5
116 for (Row = 0, PBuffer = field->buf; Row < Height; Row++, PBuffer += Width) {
117 if ((Len = (int)(afterEndOfData(PBuffer, Width) - PBuffer)) > 0) {
118 wmove(win, Row, 0);
119 waddnstr(win, PBuffer, Len);
121 cat <<EOF >expected5
128 title6="Rename and combine lines"
129 cat <<EOF >a6
130 bool need_visual_update = ((form != (FORM *)0) &&
131 (form->status & _POSTED) &&
132 (form->current==field));
134 if (need_visual_update)
135 Synchronize_Buffer(form);
137 if (single_line_field)
139 growth = field->cols * amount;
140 if (field->maxgrow)
141 growth = Minimum(field->maxgrow - field->dcols,growth);
142 field->dcols += growth;
143 if (field->dcols == field->maxgrow)
145 cat <<EOF >b6
146 bool NeedVisualUpdate = ((Form != (FORM *)0) && (Form->status & _POSTED) &&
147 (Form->current == field));
149 if (NeedVisualUpdate) {
150 synchronizeBuffer(Form);
153 if (SingleLineField) {
154 Growth = field->cols * amount;
155 if (field->maxgrow) {
156 Growth = Minimum(field->maxgrow - field->dcols, Growth);
158 field->dcols += Growth;
159 if (field->dcols == field->maxgrow) {
161 cat <<EOF >expected6
167 Final
173 Final
178 # Both lines match identically so position must be used to tie-break.
179 title7="Same line twice"
180 cat <<EOF >a7
184 cat <<EOF >b7
185 abcd
186 abcd
188 cat <<EOF >expected7
193 title8="Enforce line order"
194 cat <<EOF >a8
195 abcdef
196 ghijkl
199 cat <<EOF >b8
200 ghijk
201 abcd
203 cat <<EOF >expected8
208 title9="Expand lines and rename variables"
209 cat <<EOF >a9
210 int myFunction(int ArgumentOne, Thing *ArgTwo, Blah XuglyBug) {
211 Squiggle FabulousResult = squargle(ArgumentOne, *ArgTwo,
212 XuglyBug) + EwwwGlobalWithAReallyLongNameYepTooLong;
213 return FabulousResult * 42;
216 cat <<EOF >b9
217 int myFunction(int argument_one, Thing *arg_asdfgh,
218 Blah xugly_bug) {
219 Squiggle fabulous_result = squargle(argument_one,
220 *arg_asdfgh, xugly_bug)
221 + g_ewww_global_with_a_really_long_name_yep_too_long;
222 return fabulous_result * 42;
225 cat <<EOF >expected9
235 title10="Two close matches versus one less close match"
236 cat <<EOF >a10
237 abcdef
238 abcdef
239 ghijkl
241 cat <<EOF >b10
243 abcdefx
245 cat <<EOF >expected10
246 Final
250 # The first line of b matches best with the last line of a, but the overall
251 # match is better if we match it with the first line of a.
252 title11="Piggy in the middle"
253 cat <<EOF >a11
254 abcdefg
255 ijklmn
256 abcdefgh
258 cat <<EOF >b11
259 abcdefghx
260 ijklm
262 cat <<EOF >expected11
267 title12="No trailing newline"
268 printf "abc\ndef" >a12
269 printf "abx\nstu" >b12
270 cat <<EOF >expected12
272 Final
275 title13="Reorder includes"
276 cat <<EOF >a13
277 #include "c.h"
278 #include "b.h"
279 #include "a.h"
280 #include "e.h"
281 #include "d.h"
283 cat <<EOF >b13
284 #include "a.h"
285 #include "b.h"
286 #include "c.h"
287 #include "d.h"
288 #include "e.h"
290 cat <<EOF >expected13
298 last_test=13
300 test_expect_success setup '
301 for i in $(test_seq 2 $last_test)
303 # Append each line in a separate commit to make it easy to
304 # check which original line the blame output relates to.
306 line_count=0 &&
307 while IFS= read line
309 line_count=$((line_count+1)) &&
310 echo "$line" >>"$i" &&
311 git add "$i" &&
312 test_tick &&
313 GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count"
314 done <"a$i"
315 done &&
317 for i in $(test_seq 2 $last_test)
319 # Overwrite the files with the final content.
320 cp b$i $i &&
321 git add $i
322 done &&
323 test_tick &&
325 # Commit the final content all at once so it can all be
326 # referred to with the same commit ID.
327 GIT_AUTHOR_NAME=Final git commit -m Final &&
329 IGNOREME=$(git rev-parse HEAD)
332 for i in $(test_seq 2 $last_test); do
333 eval title="\$title$i"
334 test_expect_success "$title" \
335 "git blame -M9 --ignore-rev $IGNOREME $i >output &&
336 sed -e \"$pick_author\" output >actual &&
337 test_cmp expected$i actual"
338 done
340 # This invoked a null pointer dereference when the chunk callback was called
341 # with a zero length parent chunk and there were no more suspects.
342 test_expect_success 'Diff chunks with no suspects' '
343 test_write_lines xy1 A B C xy1 >file &&
344 git add file &&
345 test_tick &&
346 GIT_AUTHOR_NAME=1 git commit -m 1 &&
348 test_write_lines xy2 A B xy2 C xy2 >file &&
349 git add file &&
350 test_tick &&
351 GIT_AUTHOR_NAME=2 git commit -m 2 &&
352 REV_2=$(git rev-parse HEAD) &&
354 test_write_lines xy3 A >file &&
355 git add file &&
356 test_tick &&
357 GIT_AUTHOR_NAME=3 git commit -m 3 &&
358 REV_3=$(git rev-parse HEAD) &&
360 test_write_lines 1 1 >expected &&
362 git blame --ignore-rev $REV_2 --ignore-rev $REV_3 file >output &&
363 sed -e "$pick_author" output >actual &&
365 test_cmp expected actual
368 test_expect_success 'position matching' '
369 test_write_lines abc def >file2 &&
370 git add file2 &&
371 test_tick &&
372 GIT_AUTHOR_NAME=1 git commit -m 1 &&
374 test_write_lines abc def abc def >file2 &&
375 git add file2 &&
376 test_tick &&
377 GIT_AUTHOR_NAME=2 git commit -m 2 &&
379 test_write_lines abcx defx abcx defx >file2 &&
380 git add file2 &&
381 test_tick &&
382 GIT_AUTHOR_NAME=3 git commit -m 3 &&
383 REV_3=$(git rev-parse HEAD) &&
385 test_write_lines abcy defy abcx defx >file2 &&
386 git add file2 &&
387 test_tick &&
388 GIT_AUTHOR_NAME=4 git commit -m 4 &&
389 REV_4=$(git rev-parse HEAD) &&
391 test_write_lines 1 1 2 2 >expected &&
393 git blame --ignore-rev $REV_3 --ignore-rev $REV_4 file2 >output &&
394 sed -e "$pick_author" output >actual &&
396 test_cmp expected actual
399 # This fails if each blame entry is processed independently instead of
400 # processing each diff change in full.
401 test_expect_success 'preserve order' '
402 test_write_lines bcde >file3 &&
403 git add file3 &&
404 test_tick &&
405 GIT_AUTHOR_NAME=1 git commit -m 1 &&
407 test_write_lines bcde fghij >file3 &&
408 git add file3 &&
409 test_tick &&
410 GIT_AUTHOR_NAME=2 git commit -m 2 &&
412 test_write_lines bcde fghij abcd >file3 &&
413 git add file3 &&
414 test_tick &&
415 GIT_AUTHOR_NAME=3 git commit -m 3 &&
417 test_write_lines abcdx fghijx bcdex >file3 &&
418 git add file3 &&
419 test_tick &&
420 GIT_AUTHOR_NAME=4 git commit -m 4 &&
421 REV_4=$(git rev-parse HEAD) &&
423 test_write_lines abcdx fghijy bcdex >file3 &&
424 git add file3 &&
425 test_tick &&
426 GIT_AUTHOR_NAME=5 git commit -m 5 &&
427 REV_5=$(git rev-parse HEAD) &&
429 test_write_lines 1 2 3 >expected &&
431 git blame --ignore-rev $REV_4 --ignore-rev $REV_5 file3 >output &&
432 sed -e "$pick_author" output >actual &&
434 test_cmp expected actual
437 test_done