3 test_description='git blame ignore fuzzy heuristic'
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"
52 title3="Combine 3 lines into 2"
55 ( single_line_field && (field->dcols < maxgrow)) ||
56 (!single_line_field && (field->drows < maxgrow)))
59 if ((maxgrow == 0) || (single_line_field && (field->dcols < maxgrow)) ||
60 (!single_line_field && (field->drows < maxgrow))) {
67 title4="Add curly brackets"
69 if (rows) *rows = field->rows;
70 if (cols) *cols = field->cols;
71 if (frow) *frow = field->frow;
72 if (fcol) *fcol = field->fcol;
104 title5="Combine many lines and change case"
106 for(row=0,pBuffer=field->buf;
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 );
116 for (Row = 0, PBuffer = field->buf; Row < Height; Row++, PBuffer += Width) {
117 if ((Len = (int)(afterEndOfData(PBuffer, Width) - PBuffer)) > 0) {
119 waddnstr(win, PBuffer, Len);
128 title6="Rename and combine lines"
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;
141 growth = Minimum(field->maxgrow - field->dcols,growth);
142 field->dcols += growth;
143 if (field->dcols == field->maxgrow)
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) {
178 # Both lines match identically so position must be used to tie-break.
179 title7="Same line twice"
193 title8="Enforce line order"
208 title9="Expand lines and rename variables"
210 int myFunction(int ArgumentOne, Thing *ArgTwo, Blah XuglyBug) {
211 Squiggle FabulousResult = squargle(ArgumentOne, *ArgTwo,
212 XuglyBug) + EwwwGlobalWithAReallyLongNameYepTooLong;
213 return FabulousResult * 42;
217 int myFunction(int argument_one, Thing *arg_asdfgh,
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;
235 title10="Two close matches versus one less close match"
245 cat <<EOF >expected10
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"
262 cat <<EOF >expected11
267 title12="No trailing newline"
268 printf "abc\ndef" >a12
269 printf "abx\nstu" >b12
270 cat <<EOF >expected12
275 title13="Reorder includes"
290 cat <<EOF >expected13
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.
309 line_count=$((line_count+1)) &&
310 echo "$line" >>"$i" &&
313 GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count"
317 for i in $(test_seq 2 $last_test)
319 # Overwrite the files with the final content.
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"
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 &&
346 GIT_AUTHOR_NAME=1 git commit -m 1 &&
348 test_write_lines xy2 A B xy2 C xy2 >file &&
351 GIT_AUTHOR_NAME=2 git commit -m 2 &&
352 REV_2=$(git rev-parse HEAD) &&
354 test_write_lines xy3 A >file &&
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 &&
372 GIT_AUTHOR_NAME=1 git commit -m 1 &&
374 test_write_lines abc def abc def >file2 &&
377 GIT_AUTHOR_NAME=2 git commit -m 2 &&
379 test_write_lines abcx defx abcx defx >file2 &&
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 &&
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 &&
405 GIT_AUTHOR_NAME=1 git commit -m 1 &&
407 test_write_lines bcde fghij >file3 &&
410 GIT_AUTHOR_NAME=2 git commit -m 2 &&
412 test_write_lines bcde fghij abcd >file3 &&
415 GIT_AUTHOR_NAME=3 git commit -m 3 &&
417 test_write_lines abcdx fghijx bcdex >file3 &&
420 GIT_AUTHOR_NAME=4 git commit -m 4 &&
421 REV_4=$(git rev-parse HEAD) &&
423 test_write_lines abcdx fghijy bcdex >file3 &&
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