interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t8014-blame-ignore-fuzzy.sh

438 lines · 7973 bytes Raw Blame History
1#!/bin/sh
2
3test_description='git blame ignore fuzzy heuristic'
4
5. ./test-lib.sh
6
7pick_author='s/^[0-9a-f^]* *(\([^ ]*\) .*/\1/'
8
9# Each test is composed of 4 variables:
10# titleN - the test name
11# aN - the initial content
12# bN - the final content
13# expectedN - the line numbers from aN that we expect git blame
14# on bN to identify, or "Final" if bN itself should
15# be identified as the origin of that line.
16
17# We start at test 2 because setup will show as test 1
18title2="Regression test for partially overlapping search ranges"
19cat <<EOF >a2
201
212
223
23abcdef
245
256
267
27ijkl
289
2910
3011
31pqrs
3213
3314
3415
35wxyz
3617
3718
3819
39EOF
40cat <<EOF >b2
41abcde
42ijk
43pqr
44wxy
45EOF
46cat <<EOF >expected2
474
488
4912
5016
51EOF
52
53title3="Combine 3 lines into 2"
54cat <<EOF >a3
55if ((maxgrow==0) ||
56 ( single_line_field && (field->dcols < maxgrow)) ||
57 (!single_line_field && (field->drows < maxgrow)))
58EOF
59cat <<EOF >b3
60if ((maxgrow == 0) || (single_line_field && (field->dcols < maxgrow)) ||
61 (!single_line_field && (field->drows < maxgrow))) {
62EOF
63cat <<EOF >expected3
642
653
66EOF
67
68title4="Add curly brackets"
69cat <<EOF >a4
70 if (rows) *rows = field->rows;
71 if (cols) *cols = field->cols;
72 if (frow) *frow = field->frow;
73 if (fcol) *fcol = field->fcol;
74EOF
75cat <<EOF >b4
76 if (rows) {
77 *rows = field->rows;
78 }
79 if (cols) {
80 *cols = field->cols;
81 }
82 if (frow) {
83 *frow = field->frow;
84 }
85 if (fcol) {
86 *fcol = field->fcol;
87 }
88EOF
89cat <<EOF >expected4
901
911
92Final
932
942
95Final
963
973
98Final
994
1004
101Final
102EOF
103
104
105title5="Combine many lines and change case"
106cat <<EOF >a5
107for(row=0,pBuffer=field->buf;
108 row<height;
109 row++,pBuffer+=width )
110{
111 if ((len = (int)( After_End_Of_Data( pBuffer, width ) - pBuffer )) > 0)
112 {
113 wmove( win, row, 0 );
114 waddnstr( win, pBuffer, len );
115EOF
116cat <<EOF >b5
117for (Row = 0, PBuffer = field->buf; Row < Height; Row++, PBuffer += Width) {
118 if ((Len = (int)(afterEndOfData(PBuffer, Width) - PBuffer)) > 0) {
119 wmove(win, Row, 0);
120 waddnstr(win, PBuffer, Len);
121EOF
122cat <<EOF >expected5
1231
1245
1257
1268
127EOF
128
129title6="Rename and combine lines"
130cat <<EOF >a6
131bool need_visual_update = ((form != (FORM *)0) &&
132 (form->status & _POSTED) &&
133 (form->current==field));
134
135if (need_visual_update)
136 Synchronize_Buffer(form);
137
138if (single_line_field)
139{
140 growth = field->cols * amount;
141 if (field->maxgrow)
142 growth = Minimum(field->maxgrow - field->dcols,growth);
143 field->dcols += growth;
144 if (field->dcols == field->maxgrow)
145EOF
146cat <<EOF >b6
147bool NeedVisualUpdate = ((Form != (FORM *)0) && (Form->status & _POSTED) &&
148 (Form->current == field));
149
150if (NeedVisualUpdate) {
151 synchronizeBuffer(Form);
152}
153
154if (SingleLineField) {
155 Growth = field->cols * amount;
156 if (field->maxgrow) {
157 Growth = Minimum(field->maxgrow - field->dcols, Growth);
158 }
159 field->dcols += Growth;
160 if (field->dcols == field->maxgrow) {
161EOF
162cat <<EOF >expected6
1631
1643
1654
1665
1676
168Final
1697
1708
17110
17211
17312
174Final
17513
17614
177EOF
178
179# Both lines match identically so position must be used to tie-break.
180title7="Same line twice"
181cat <<EOF >a7
182abc
183abc
184EOF
185cat <<EOF >b7
186abcd
187abcd
188EOF
189cat <<EOF >expected7
1901
1912
192EOF
193
194title8="Enforce line order"
195cat <<EOF >a8
196abcdef
197ghijkl
198ab
199EOF
200cat <<EOF >b8
201ghijk
202abcd
203EOF
204cat <<EOF >expected8
2052
2063
207EOF
208
209title9="Expand lines and rename variables"
210cat <<EOF >a9
211int myFunction(int ArgumentOne, Thing *ArgTwo, Blah XuglyBug) {
212 Squiggle FabulousResult = squargle(ArgumentOne, *ArgTwo,
213 XuglyBug) + EwwwGlobalWithAReallyLongNameYepTooLong;
214 return FabulousResult * 42;
215}
216EOF
217cat <<EOF >b9
218int myFunction(int argument_one, Thing *arg_asdfgh,
219 Blah xugly_bug) {
220 Squiggle fabulous_result = squargle(argument_one,
221 *arg_asdfgh, xugly_bug)
222 + g_ewww_global_with_a_really_long_name_yep_too_long;
223 return fabulous_result * 42;
224}
225EOF
226cat <<EOF >expected9
2271
2281
2292
2303
2313
2324
2335
234EOF
235
236title10="Two close matches versus one less close match"
237cat <<EOF >a10
238abcdef
239abcdef
240ghijkl
241EOF
242cat <<EOF >b10
243gh
244abcdefx
245EOF
246cat <<EOF >expected10
247Final
2482
249EOF
250
251# The first line of b matches best with the last line of a, but the overall
252# match is better if we match it with the first line of a.
253title11="Piggy in the middle"
254cat <<EOF >a11
255abcdefg
256ijklmn
257abcdefgh
258EOF
259cat <<EOF >b11
260abcdefghx
261ijklm
262EOF
263cat <<EOF >expected11
2641
2652
266EOF
267
268title12="No trailing newline"
269printf "abc\ndef" >a12
270printf "abx\nstu" >b12
271cat <<EOF >expected12
2721
273Final
274EOF
275
276title13="Reorder includes"
277cat <<EOF >a13
278#include "c.h"
279#include "b.h"
280#include "a.h"
281#include "e.h"
282#include "d.h"
283EOF
284cat <<EOF >b13
285#include "a.h"
286#include "b.h"
287#include "c.h"
288#include "d.h"
289#include "e.h"
290EOF
291cat <<EOF >expected13
2923
2932
2941
2955
2964
297EOF
298
299last_test=13
300
301test_expect_success setup '
302 for i in $(test_seq 2 $last_test)
303 do
304 # Append each line in a separate commit to make it easy to
305 # check which original line the blame output relates to.
306
307 line_count=0 &&
308 while IFS= read line
309 do
310 line_count=$((line_count+1)) &&
311 echo "$line" >>"$i" &&
312 git add "$i" &&
313 test_tick &&
314 GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count" || return 1
315 done <"a$i"
316 done &&
317
318 for i in $(test_seq 2 $last_test)
319 do
320 # Overwrite the files with the final content.
321 cp b$i $i &&
322 git add $i || return 1
323 done &&
324 test_tick &&
325
326 # Commit the final content all at once so it can all be
327 # referred to with the same commit ID.
328 GIT_AUTHOR_NAME=Final git commit -m Final &&
329
330 IGNOREME=$(git rev-parse HEAD)
331'
332
333for i in $(test_seq 2 $last_test); do
334 eval title="\$title$i"
335 test_expect_success "$title" \
336 "git blame -M9 --ignore-rev $IGNOREME $i >output &&
337 sed -e \"$pick_author\" output >actual &&
338 test_cmp expected$i actual"
339done
340
341# This invoked a null pointer dereference when the chunk callback was called
342# with a zero length parent chunk and there were no more suspects.
343test_expect_success 'Diff chunks with no suspects' '
344 test_write_lines xy1 A B C xy1 >file &&
345 git add file &&
346 test_tick &&
347 GIT_AUTHOR_NAME=1 git commit -m 1 &&
348
349 test_write_lines xy2 A B xy2 C xy2 >file &&
350 git add file &&
351 test_tick &&
352 GIT_AUTHOR_NAME=2 git commit -m 2 &&
353 REV_2=$(git rev-parse HEAD) &&
354
355 test_write_lines xy3 A >file &&
356 git add file &&
357 test_tick &&
358 GIT_AUTHOR_NAME=3 git commit -m 3 &&
359 REV_3=$(git rev-parse HEAD) &&
360
361 test_write_lines 1 1 >expected &&
362
363 git blame --ignore-rev $REV_2 --ignore-rev $REV_3 file >output &&
364 sed -e "$pick_author" output >actual &&
365
366 test_cmp expected actual
367 '
368
369test_expect_success 'position matching' '
370 test_write_lines abc def >file2 &&
371 git add file2 &&
372 test_tick &&
373 GIT_AUTHOR_NAME=1 git commit -m 1 &&
374
375 test_write_lines abc def abc def >file2 &&
376 git add file2 &&
377 test_tick &&
378 GIT_AUTHOR_NAME=2 git commit -m 2 &&
379
380 test_write_lines abcx defx abcx defx >file2 &&
381 git add file2 &&
382 test_tick &&
383 GIT_AUTHOR_NAME=3 git commit -m 3 &&
384 REV_3=$(git rev-parse HEAD) &&
385
386 test_write_lines abcy defy abcx defx >file2 &&
387 git add file2 &&
388 test_tick &&
389 GIT_AUTHOR_NAME=4 git commit -m 4 &&
390 REV_4=$(git rev-parse HEAD) &&
391
392 test_write_lines 1 1 2 2 >expected &&
393
394 git blame --ignore-rev $REV_3 --ignore-rev $REV_4 file2 >output &&
395 sed -e "$pick_author" output >actual &&
396
397 test_cmp expected actual
398 '
399
400# This fails if each blame entry is processed independently instead of
401# processing each diff change in full.
402test_expect_success 'preserve order' '
403 test_write_lines bcde >file3 &&
404 git add file3 &&
405 test_tick &&
406 GIT_AUTHOR_NAME=1 git commit -m 1 &&
407
408 test_write_lines bcde fghij >file3 &&
409 git add file3 &&
410 test_tick &&
411 GIT_AUTHOR_NAME=2 git commit -m 2 &&
412
413 test_write_lines bcde fghij abcd >file3 &&
414 git add file3 &&
415 test_tick &&
416 GIT_AUTHOR_NAME=3 git commit -m 3 &&
417
418 test_write_lines abcdx fghijx bcdex >file3 &&
419 git add file3 &&
420 test_tick &&
421 GIT_AUTHOR_NAME=4 git commit -m 4 &&
422 REV_4=$(git rev-parse HEAD) &&
423
424 test_write_lines abcdx fghijy bcdex >file3 &&
425 git add file3 &&
426 test_tick &&
427 GIT_AUTHOR_NAME=5 git commit -m 5 &&
428 REV_5=$(git rev-parse HEAD) &&
429
430 test_write_lines 1 2 3 >expected &&
431
432 git blame --ignore-rev $REV_4 --ignore-rev $REV_5 file3 >output &&
433 sed -e "$pick_author" output >actual &&
434
435 test_cmp expected actual
436 '
437
438test_done