Viewing files at commit e60fa60d3a02Commit detailsView latest

suites/merge/vendor/gitoxide/text-baseline.sh 700 lines · 10.2 KB · bash
1
#!/usr/bin/env bash
2
set -eu -o pipefail
3
4
git init
5
rm -Rf .git/hooks
6
7
function baseline() {
8
  local ours=$DIR/${1:?1: our file}.blob;
9
  local base=$DIR/${2:?2: base file}.blob;
10
  local theirs=$DIR/${3:?3: their file}.blob;
11
  local output=$DIR/${4:?4: the name of the output file}.merged;
12
13
  shift 4
14
  # Exit codes 1..127 count conflicts; fatal errors must not become empty baselines.
15
  git merge-file --stdout "$@" "$ours" "$base" "$theirs" > "$output" || test "$?" -le 127
16
  echo "$ours" "$base" "$theirs" "$output" "$@" >> baseline.cases
17
18
  local output="${output}-reversed"
19
  git merge-file --stdout "$@" "$theirs" "$base" "$ours" > "${output}" || test "$?" -le 127
20
  echo "$theirs" "$base" "$ours" "${output}" "$@" >> baseline-reversed.cases
21
}
22
23
function write_lines () {
24
	printf "%s\n" "$@"
25
}
26
27
mkdir simple
28
(cd simple
29
  echo -e "line1-changed-by-both\nline2-to-be-changed-in-incoming" > ours.blob
30
  echo -e "line1-to-be-changed-by-both\nline2-to-be-changed-in-incoming" > base.blob
31
  echo -e "line1-changed-by-both\nline2-changed" > theirs.blob
32
)
33
34
# one big change includes multiple smaller ones
35
mkdir multi-change
36
(cd multi-change
37
  cat <<EOF > base.blob
38
0
39
1
40
2
41
3
42
4
43
5
44
6
45
7
46
8
47
9
48
EOF
49
50
  cat <<EOF > ours.blob
51
0
52
1
53
X
54
X
55
4
56
5
57
Y
58
Y
59
8
60
Z
61
EOF
62
63
  cat <<EOF > theirs.blob
64
T
65
T
66
T
67
T
68
T
69
T
70
T
71
T
72
T
73
T
74
EOF
75
)
76
77
# a change with deletion/clearing our file
78
mkdir clear-ours
79
(cd clear-ours
80
  cat <<EOF > base.blob
81
0
82
1
83
2
84
3
85
4
86
5
87
EOF
88
89
  touch ours.blob
90
91
  cat <<EOF > theirs.blob
92
T
93
T
94
T
95
T
96
T
97
EOF
98
)
99
100
# a change with deletion/clearing their file
101
mkdir clear-theirs
102
(cd clear-theirs
103
  cat <<EOF > base.blob
104
0
105
1
106
2
107
3
108
4
109
5
110
EOF
111
112
  cat <<EOF > ours.blob
113
O
114
O
115
O
116
O
117
O
118
EOF
119
120
  touch theirs.blob
121
)
122
123
# differently sized changes
124
mkdir ours-2-lines-theirs-1-line
125
(cd ours-2-lines-theirs-1-line
126
  cat <<EOF > base.blob
127
0
128
1
129
2
130
3
131
4
132
5
133
EOF
134
135
  cat <<EOF > ours.blob
136
0
137
1
138
X
139
X
140
4
141
5
142
EOF
143
144
  cat <<EOF > theirs.blob
145
0
146
1
147
Y
148
3
149
4
150
5
151
EOF
152
)
153
154
# partial match
155
mkdir partial-match
156
(cd partial-match
157
  cat <<EOF > base.blob
158
0
159
1
160
2
161
3
162
4
163
5
164
EOF
165
166
  cat <<EOF > ours.blob
167
0
168
X1
169
X2
170
X3
171
X4
172
5
173
EOF
174
175
  cat <<EOF > theirs.blob
176
0
177
X1
178
2
179
X3
180
X4
181
5
182
EOF
183
)
184
185
# based on 'unique merge base' from 'diff3-conflict-markers'
186
mkdir unique-merge-base-with-insertion
187
(cd unique-merge-base-with-insertion
188
  cat <<EOF > base.blob
189
1
190
2
191
3
192
4
193
5
194
EOF
195
196
  # no trailing newline
197
  echo -n $'1\n2\n3\n4\n5\n7' > ours.blob
198
  echo -n $'1\n2\n3\n4\n5\nsix' > theirs.blob
199
)
200
201
mkdir zdiff3-basic
202
(cd zdiff3-basic
203
  cat <<EOF > base.blob
204
1
205
2
206
3
207
4
208
5
209
6
210
7
211
8
212
9
213
EOF
214
215
  cat <<EOF > ours.blob
216
1
217
2
218
3
219
4
220
A
221
B
222
C
223
D
224
E
225
7
226
8
227
9
228
EOF
229
230
  cat <<EOF > theirs.blob
231
1
232
2
233
3
234
4
235
A
236
X
237
C
238
Y
239
E
240
7
241
8
242
9
243
EOF
244
)
245
246
mkdir zdiff3-middlecommon
247
(cd zdiff3-middlecommon
248
  cat <<EOF > base.blob
249
1
250
2
251
3
252
AA
253
4
254
5
255
BB
256
6
257
7
258
8
259
EOF
260
261
  cat <<EOF > ours.blob
262
1
263
2
264
3
265
CC
266
4
267
5
268
DD
269
6
270
7
271
8
272
EOF
273
274
  cat <<EOF > theirs.blob
275
1
276
2
277
3
278
EE
279
4
280
5
281
FF
282
6
283
7
284
8
285
EOF
286
)
287
288
289
mkdir zdiff3-interesting
290
(cd zdiff3-interesting
291
  cat <<EOF > base.blob
292
1
293
2
294
3
295
4
296
5
297
6
298
7
299
8
300
9
301
EOF
302
303
  cat <<EOF > ours.blob
304
1
305
2
306
3
307
4
308
A
309
B
310
C
311
D
312
E
313
F
314
G
315
H
316
I
317
J
318
7
319
8
320
9
321
EOF
322
323
  cat <<EOF > theirs.blob
324
1
325
2
326
3
327
4
328
A
329
B
330
C
331
5
332
6
333
G
334
H
335
I
336
J
337
7
338
8
339
9
340
EOF
341
)
342
343
mkdir zdiff3-evil
344
(cd zdiff3-evil
345
  cat <<EOF > base.blob
346
1
347
2
348
3
349
4
350
5
351
6
352
7
353
8
354
9
355
EOF
356
357
  cat <<EOF > ours.blob
358
1
359
2
360
3
361
4
362
X
363
A
364
B
365
C
366
7
367
8
368
9
369
EOF
370
371
  cat <<EOF > theirs.blob
372
1
373
2
374
3
375
4
376
Y
377
A
378
B
379
C
380
B
381
C
382
7
383
8
384
9
385
EOF
386
)
387
388
mkdir no-change-add
389
(cd no-change-add
390
391
  echo -e "  line 1\n\n  line 2" > base.blob
392
  echo -e "  line 1\n\n  line in between\n\n  line 2\n\n  line in between\n\n  line 3" > ours.blob
393
  cp ours.blob theirs.blob
394
)
395
396
mkdir no-change-remove
397
(cd no-change-remove
398
399
  echo -e "  line 1\n\n  line in between\n\n  line 2\n\n  line in between\n\n  line 3" > base.blob
400
  echo -e "  line 1\n\n  line 2" > ours.blob
401
  cp ours.blob theirs.blob
402
)
403
404
mkdir simple-conflict
405
(cd simple-conflict
406
  touch base.blob
407
  write_lines a c >ours.blob
408
  write_lines a b c >theirs.blob
409
)
410
411
mkdir simple-conflict-2
412
(cd simple-conflict-2
413
  touch base.blob
414
  write_lines a b c d >ours.blob
415
  write_lines a b c >theirs.blob
416
)
417
418
mkdir simple-conflict-3
419
(cd simple-conflict-3
420
  touch base.blob
421
  write_lines b c >ours.blob
422
  write_lines a b c >theirs.blob
423
)
424
425
mkdir complex
426
(cd complex
427
  cat <<EOF >base.blob
428
Dominus regit me,
429
et nihil mihi deerit.
430
In loco pascuae ibi me collocavit,
431
super aquam refectionis educavit me;
432
animam meam convertit,
433
deduxit me super semitas jusitiae,
434
propter nomen suum.
435
EOF
436
437
	cat <<EOF >new1.blob
438
Dominus regit me,
439
et nihil mihi deerit.
440
In loco pascuae ibi me collocavit,
441
super aquam refectionis educavit me;
442
animam meam convertit,
443
deduxit me super semitas jusitiae,
444
propter nomen suum.
445
Nam et si ambulavero in medio umbrae mortis,
446
non timebo mala, quoniam tu mecum es:
447
virga tua et baculus tuus ipsa me consolata sunt.
448
EOF
449
450
	cat <<EOF >new2.blob
451
Dominus regit me, et nihil mihi deerit.
452
In loco pascuae ibi me collocavit,
453
super aquam refectionis educavit me;
454
animam meam convertit,
455
deduxit me super semitas jusitiae,
456
propter nomen suum.
457
EOF
458
459
	cat <<EOF >new3.blob
460
DOMINUS regit me,
461
et nihil mihi deerit.
462
In loco pascuae ibi me collocavit,
463
super aquam refectionis educavit me;
464
animam meam convertit,
465
deduxit me super semitas jusitiae,
466
propter nomen suum.
467
EOF
468
469
	cat <<EOF >new4.blob
470
Dominus regit me, et nihil mihi deerit.
471
In loco pascuae ibi me collocavit,
472
super aquam refectionis educavit me;
473
animam meam convertit,
474
deduxit me super semitas jusitiae,
475
EOF
476
477
	cat <<EOF >new5.blob
478
Dominus regit me,
479
et nihil mihi deerit.
480
In loco pascuae ibi me collocavit,
481
super aquam refectionis educavit me;
482
animam meam convertit,
483
deduxit me super semitas jusitiae,
484
propter nomen suum.
485
Nam et si ambulavero in medio umbrae mortis,
486
non timebo mala, quoniam TU mecum es:
487
virga tua et baculus tuus ipsa me consolata sunt.
488
EOF
489
490
	echo -n "propter nomen suum." >>new4.blob
491
492
	cat <<EOF >base.c
493
int f(int x, int y)
494
{
495
  if (x == 0)
496
  {
497
    return y;
498
  }
499
  return x;
500
}
501
502
int g(size_t u)
503
{
504
  while (u < 30)
505
  {
506
    u++;
507
  }
508
  return u;
509
}
510
EOF
511
512
	cat <<EOF >ours.c
513
int g(size_t u)
514
{
515
  while (u < 30)
516
  {
517
    u++;
518
  }
519
  return u;
520
}
521
522
int h(int x, int y, int z)
523
{
524
  if (z == 0)
525
  {
526
    return x;
527
  }
528
  return y;
529
}
530
EOF
531
532
	cat <<EOF >theirs.c
533
int f(int x, int y)
534
{
535
  if (x == 0)
536
  {
537
    return y;
538
  }
539
  return x;
540
}
541
542
int g(size_t u)
543
{
544
  while (u > 34)
545
  {
546
    u--;
547
  }
548
  return u;
549
}
550
EOF
551
552
  mkdir no-change
553
  (cd no-change
554
    cp ../base.blob .
555
    cp base.blob ours.blob
556
    cp base.blob theirs.blob
557
  )
558
  mkdir no-conflict
559
  (cd no-conflict
560
    cp ../new1.blob ours.blob
561
    cp ../base.blob base.blob
562
    cp ../new2.blob theirs.blob
563
  )
564
  mkdir no-conflict-too
565
  (cd no-conflict-too
566
    cp ../base.blob ours.blob
567
    cp ../base.blob base.blob
568
    cp ../new2.blob theirs.blob
569
  )
570
  mkdir they-changed
571
  (cd they-changed
572
    touch ours.blob base.blob
573
    cp ../new2.blob theirs.blob
574
  )
575
  mkdir missing-LF-at-EOF
576
  (cd missing-LF-at-EOF
577
    cp ../new1.blob ours.blob
578
    cp ../base.blob base.blob
579
    cp ../new4.blob theirs.blob
580
  )
581
  mkdir missing-LF-at-EOF-no-conflict
582
  (cd missing-LF-at-EOF-no-conflict
583
    cp ../new4.blob ours.blob
584
    cp ../new2.blob base.blob
585
    cp ../new3.blob theirs.blob
586
  )
587
  mkdir with-conflicts
588
  (cd with-conflicts
589
    cp ../new1.blob ours.blob
590
    cp ../base.blob base.blob
591
    cp ../new3.blob theirs.blob
592
  )
593
  mkdir with-conflicts-in-removed-tail
594
  (cd with-conflicts-in-removed-tail
595
    cp ../base.blob ours.blob
596
    cp ../new1.blob base.blob
597
    cp ../new5.blob theirs.blob
598
  )
599
  mkdir auto-simplification
600
  (cd auto-simplification
601
    sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" <../new5.blob >ours.blob
602
    cp ../new5.blob base.blob
603
    sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" <../new5.blob >theirs.blob
604
  )
605
  mkdir auto-simplification2
606
  (cd auto-simplification2
607
    sed -e "s/deerit./&%%%%/" -e "s/locavit,/locavit;/" <../auto-simplification/ours.blob | tr % "\012" >ours.blob
608
    cp ../new5.blob base.blob
609
    sed -e "s/deerit./&%%%%/" -e "s/locavit,/locavit --/" <../auto-simplification/theirs.blob | tr % "\012" >theirs.blob
610
  )
611
  mkdir conflict-without-LF
612
  (cd conflict-without-LF
613
   	printf "line1\nline2\nline3" >base.blob
614
   	printf "line1\nline2\nline3x" >ours.blob
615
   	printf "line1\nline2\nline3y" >theirs.blob
616
  )
617
618
  mkdir marker-newline-handling-crlf
619
  (cd marker-newline-handling-crlf
620
  	printf "1\\r\\n2\\r\\n3" >base.blob
621
  	printf "1\\r\\n2\\r\\n4" >ours.blob
622
  	printf "1\\r\\n2\\r\\n5" >theirs.blob
623
  )
624
625
  mkdir marker-newline-handling-lf
626
  (cd marker-newline-handling-lf
627
  	printf "1\\r\\n2\\n3" >base.blob
628
  	printf "1\\r\\n2\\n4" >ours.blob
629
  	printf "1\\r\\n2\\n5" >theirs.blob
630
  )
631
632
  mkdir marker-newline-handling-lf2
633
  (cd marker-newline-handling-lf2
634
  	printf "1\\r\\n2\\r\\n3" >base.blob
635
  	printf "1\\r\\n2\\n4" >ours.blob
636
  	printf "1\\r\\n2\\n5" >theirs.blob
637
  )
638
639
  mkdir spurious-c-conflicts
640
  (cd spurious-c-conflicts
641
  	cp ../base.c base.blob
642
  	cp ../ours.c ours.blob
643
  	cp ../theirs.c theirs.blob
644
  )
645
)
646
647
mkdir line-ending-change
648
(cd line-ending-change
649
650
  echo -e "a\n" > base.blob
651
  echo -e "a\r\n" > ours.blob
652
  echo -e "a\n" > theirs.blob
653
)
654
655
656
for dir in  simple-conflict-3 \
657
            simple-conflict-2 \
658
            simple-conflict \
659
            simple \
660
            multi-change \
661
            clear-ours \
662
            clear-theirs \
663
            ours-2-lines-theirs-1-line \
664
            partial-match \
665
            unique-merge-base-with-insertion \
666
            zdiff3-basic \
667
            zdiff3-middlecommon \
668
            zdiff3-interesting \
669
            zdiff3-evil \
670
            no-change-add \
671
            no-change-remove \
672
            line-ending-change \
673
            complex/no-change \
674
            complex/no-conflict \
675
            complex/no-conflict-too \
676
            complex/they-changed \
677
            complex/missing-LF-at-EOF \
678
            complex/missing-LF-at-EOF-no-conflict \
679
            complex/with-conflicts \
680
            complex/with-conflicts-in-removed-tail \
681
            complex/auto-simplification \
682
            complex/auto-simplification2 \
683
            complex/conflict-without-LF \
684
            complex/marker-newline-handling-crlf \
685
            complex/marker-newline-handling-lf \
686
            complex/marker-newline-handling-lf2 \
687
            complex/spurious-c-conflicts; do
688
  DIR=$dir
689
  baseline ours base theirs merge
690
  baseline ours base theirs diff3 --diff3
691
  baseline ours base theirs zdiff3 --zdiff3
692
  baseline ours base theirs merge-ours --ours
693
  baseline ours base theirs merge-theirs --theirs
694
  baseline ours base theirs merge-union --union
695
  (
696
    export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=diff.algorithm GIT_CONFIG_VALUE_0=histogram
697
    baseline ours base theirs diff3-histogram --diff3
698
    baseline ours base theirs zdiff3-histogram --zdiff3
699
  )
700
done