t1006: test oid compatibility with cat-file
Update the existing tests that are oid based to test that cat-file works correctly with the normal oid and the compat_oid. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric W. Biederman committed
Oct 1, 2023 at 21:40 UTC
3afa8d86accb01686a24c7859bee31370472ef56
1 file changed
+154
-97
t/t1006-cat-file.sh
+154
-97
@@ -236,27 +236,38 @@ hello_size=$(strlen "$hello_content")
236
hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin)
237
238
test_expect_success "setup" '
239
+ git config core.repositoryformatversion 1 &&
240
+ git config extensions.objectformat $test_hash_algo &&
241
+ git config extensions.compatobjectformat $test_compat_hash_algo &&
242
echo_without_newline "$hello_content" > hello &&
243
git update-index --add hello
244
'
245
243
-run_tests 'blob' $hello_oid $hello_size "$hello_content" "$hello_content"
246
+run_blob_tests () {
247
+ oid=$1
248
245
-test_expect_success '--batch-command --buffer with flush for blob info' '
246
- echo "$hello_oid blob $hello_size" >expect &&
247
- test_write_lines "info $hello_oid" "flush" |
249
+ run_tests 'blob' $oid $hello_size "$hello_content" "$hello_content"
250
+
251
+ test_expect_success '--batch-command --buffer with flush for blob info' '
252
+ echo "$oid blob $hello_size" >expect &&
253
+ test_write_lines "info $oid" "flush" |
254
GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT=1 \
255
git cat-file --batch-command --buffer >actual &&
256
test_cmp expect actual
251
-'
257
+ '
258
253
-test_expect_success '--batch-command --buffer without flush for blob info' '
259
+ test_expect_success '--batch-command --buffer without flush for blob info' '
260
touch output &&
255
- test_write_lines "info $hello_oid" |
261
+ test_write_lines "info $oid" |
262
GIT_TEST_CAT_FILE_NO_FLUSH_ON_EXIT=1 \
263
git cat-file --batch-command --buffer >>output &&
264
test_must_be_empty output
259
-'
265
+ '
266
+}
267
+
268
+hello_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $hello_oid)
269
+run_blob_tests $hello_oid
270
+run_blob_tests $hello_compat_oid
271
272
test_expect_success '--batch-check without %(rest) considers whole line' '
273
echo "$hello_oid blob $hello_size" >expect &&
@@ -267,35 +278,58 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
278
'
279
280
tree_oid=$(git write-tree)
281
+tree_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $tree_oid)
282
tree_size=$(($(test_oid rawsz) + 13))
283
+tree_compat_size=$(($(test_oid --hash=compat rawsz) + 13))
284
tree_pretty_content="100644 blob $hello_oid hello${LF}"
285
+tree_compat_pretty_content="100644 blob $hello_compat_oid hello${LF}"
286
287
run_tests 'tree' $tree_oid $tree_size "" "$tree_pretty_content"
288
+run_tests 'tree' $tree_compat_oid $tree_compat_size "" "$tree_compat_pretty_content"
289
290
commit_message="Initial commit"
291
commit_oid=$(echo_without_newline "$commit_message" | git commit-tree $tree_oid)
292
+commit_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $commit_oid)
293
commit_size=$(($(test_oid hexsz) + 137))
294
+commit_compat_size=$(($(test_oid --hash=compat hexsz) + 137))
295
commit_content="tree $tree_oid
296
author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE
297
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
298
299
$commit_message"
300
301
+commit_compat_content="tree $tree_compat_oid
302
+author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE
303
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
304
+
305
+$commit_message"
306
+
307
run_tests 'commit' $commit_oid $commit_size "$commit_content" "$commit_content"
308
+run_tests 'commit' $commit_compat_oid $commit_compat_size "$commit_compat_content" "$commit_compat_content"
309
286
-tag_header_without_timestamp="object $hello_oid
287
-type blob
310
+tag_header_without_oid="type blob
311
tag hellotag
312
tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
313
+tag_header_without_timestamp="object $hello_oid
314
+$tag_header_without_oid"
315
+tag_compat_header_without_timestamp="object $hello_compat_oid
316
+$tag_header_without_oid"
317
tag_description="This is a tag"
318
tag_content="$tag_header_without_timestamp 0 +0000
319
320
+$tag_description"
321
+tag_compat_content="$tag_compat_header_without_timestamp 0 +0000
322
+
323
$tag_description"
324
325
tag_oid=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w)
326
tag_size=$(strlen "$tag_content")
327
328
+tag_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $tag_oid)
329
+tag_compat_size=$(strlen "$tag_compat_content")
330
+
331
run_tests 'tag' $tag_oid $tag_size "$tag_content" "$tag_content"
332
+run_tests 'tag' $tag_compat_oid $tag_compat_size "$tag_compat_content" "$tag_compat_content"
333
334
test_expect_success "Reach a blob from a tag pointing to it" '
335
echo_without_newline "$hello_content" >expect &&
@@ -303,37 +337,43 @@ test_expect_success "Reach a blob from a tag pointing to it" '
337
test_cmp expect actual
338
'
339
306
-for batch in batch batch-check batch-command
340
+for oid in $hello_oid $hello_compat_oid
341
do
308
- for opt in t s e p
342
+ for batch in batch batch-check batch-command
343
do
344
+ for opt in t s e p
345
+ do
346
test_expect_success "Passing -$opt with --$batch fails" '
311
- test_must_fail git cat-file --$batch -$opt $hello_oid
347
+ test_must_fail git cat-file --$batch -$opt $oid
348
'
349
350
test_expect_success "Passing --$batch with -$opt fails" '
315
- test_must_fail git cat-file -$opt --$batch $hello_oid
351
+ test_must_fail git cat-file -$opt --$batch $oid
352
'
317
- done
353
+ done
354
319
- test_expect_success "Passing <type> with --$batch fails" '
320
- test_must_fail git cat-file --$batch blob $hello_oid
321
- '
355
+ test_expect_success "Passing <type> with --$batch fails" '
356
+ test_must_fail git cat-file --$batch blob $oid
357
+ '
358
323
- test_expect_success "Passing --$batch with <type> fails" '
324
- test_must_fail git cat-file blob --$batch $hello_oid
325
- '
359
+ test_expect_success "Passing --$batch with <type> fails" '
360
+ test_must_fail git cat-file blob --$batch $oid
361
+ '
362
327
- test_expect_success "Passing oid with --$batch fails" '
328
- test_must_fail git cat-file --$batch $hello_oid
329
- '
363
+ test_expect_success "Passing oid with --$batch fails" '
364
+ test_must_fail git cat-file --$batch $oid
365
+ '
366
+ done
367
done
368
332
-for opt in t s e p
369
+for oid in $hello_oid $hello_compat_oid
370
do
334
- test_expect_success "Passing -$opt with --follow-symlinks fails" '
335
- test_must_fail git cat-file --follow-symlinks -$opt $hello_oid
371
+ for opt in t s e p
372
+ do
373
+ test_expect_success "Passing -$opt with --follow-symlinks fails" '
374
+ test_must_fail git cat-file --follow-symlinks -$opt $oid
375
'
376
+ done
377
done
378
379
test_expect_success "--batch-check for a non-existent named object" '
@@ -386,112 +426,102 @@ test_expect_success 'empty --batch-check notices missing object' '
426
test_cmp expect actual
427
'
428
389
-batch_input="$hello_oid
390
-$commit_oid
391
-$tag_oid
429
+batch_tests () {
430
+ boid=$1
431
+ loid=$2
432
+ lsize=$3
433
+ coid=$4
434
+ csize=$5
435
+ ccontent=$6
436
+ toid=$7
437
+ tsize=$8
438
+ tcontent=$9
439
+
440
+ batch_input="$boid
441
+$coid
442
+$toid
443
deadbeef
444
445
"
446
396
-printf "%s\0" \
397
- "$hello_oid blob $hello_size" \
447
+ printf "%s\0" \
448
+ "$boid blob $hello_size" \
449
"$hello_content" \
399
- "$commit_oid commit $commit_size" \
400
- "$commit_content" \
401
- "$tag_oid tag $tag_size" \
402
- "$tag_content" \
450
+ "$coid commit $csize" \
451
+ "$ccontent" \
452
+ "$toid tag $tsize" \
453
+ "$tcontent" \
454
"deadbeef missing" \
455
" missing" >batch_output
456
406
-test_expect_success '--batch with multiple oids gives correct format' '
457
+ test_expect_success '--batch with multiple oids gives correct format' '
458
tr "\0" "\n" <batch_output >expect &&
459
echo_without_newline "$batch_input" >in &&
460
git cat-file --batch <in >actual &&
461
test_cmp expect actual
411
-'
462
+ '
463
413
-test_expect_success '--batch, -z with multiple oids gives correct format' '
464
+ test_expect_success '--batch, -z with multiple oids gives correct format' '
465
echo_without_newline_nul "$batch_input" >in &&
466
tr "\0" "\n" <batch_output >expect &&
467
git cat-file --batch -z <in >actual &&
468
test_cmp expect actual
418
-'
469
+ '
470
420
-test_expect_success '--batch, -Z with multiple oids gives correct format' '
471
+ test_expect_success '--batch, -Z with multiple oids gives correct format' '
472
echo_without_newline_nul "$batch_input" >in &&
473
git cat-file --batch -Z <in >actual &&
474
test_cmp batch_output actual
424
-'
475
+ '
476
426
-batch_check_input="$hello_oid
427
-$tree_oid
428
-$commit_oid
429
-$tag_oid
477
+batch_check_input="$boid
478
+$loid
479
+$coid
480
+$toid
481
deadbeef
482
483
"
484
434
-printf "%s\0" \
435
- "$hello_oid blob $hello_size" \
436
- "$tree_oid tree $tree_size" \
437
- "$commit_oid commit $commit_size" \
438
- "$tag_oid tag $tag_size" \
485
+ printf "%s\0" \
486
+ "$boid blob $hello_size" \
487
+ "$loid tree $lsize" \
488
+ "$coid commit $csize" \
489
+ "$toid tag $tsize" \
490
"deadbeef missing" \
491
" missing" >batch_check_output
492
442
-test_expect_success "--batch-check with multiple oids gives correct format" '
493
+ test_expect_success "--batch-check with multiple oids gives correct format" '
494
tr "\0" "\n" <batch_check_output >expect &&
495
echo_without_newline "$batch_check_input" >in &&
496
git cat-file --batch-check <in >actual &&
497
test_cmp expect actual
447
-'
498
+ '
499
449
-test_expect_success "--batch-check, -z with multiple oids gives correct format" '
500
+ test_expect_success "--batch-check, -z with multiple oids gives correct format" '
501
tr "\0" "\n" <batch_check_output >expect &&
502
echo_without_newline_nul "$batch_check_input" >in &&
503
git cat-file --batch-check -z <in >actual &&
504
test_cmp expect actual
454
-'
505
+ '
506
456
-test_expect_success "--batch-check, -Z with multiple oids gives correct format" '
507
+ test_expect_success "--batch-check, -Z with multiple oids gives correct format" '
508
echo_without_newline_nul "$batch_check_input" >in &&
509
git cat-file --batch-check -Z <in >actual &&
510
test_cmp batch_check_output actual
460
-'
461
-
462
-test_expect_success FUNNYNAMES 'setup with newline in input' '
463
- touch -- "newline${LF}embedded" &&
464
- git add -- "newline${LF}embedded" &&
465
- git commit -m "file with newline embedded" &&
466
- test_tick &&
467
-
468
- printf "HEAD:newline${LF}embedded" >in
469
-'
470
-
471
-test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' '
472
- git cat-file --batch-check -z <in >actual &&
473
- echo "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
474
- test_cmp expect actual
475
-'
476
-
477
-test_expect_success FUNNYNAMES '--batch-check, -Z with newline in input' '
478
- git cat-file --batch-check -Z <in >actual &&
479
- printf "%s\0" "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
480
- test_cmp expect actual
481
-'
511
+ '
512
483
-batch_command_multiple_info="info $hello_oid
484
-info $tree_oid
485
-info $commit_oid
486
-info $tag_oid
513
+batch_command_multiple_info="info $boid
514
+info $loid
515
+info $coid
516
+info $toid
517
info deadbeef"
518
489
-test_expect_success '--batch-command with multiple info calls gives correct format' '
519
+ test_expect_success '--batch-command with multiple info calls gives correct format' '
520
cat >expect <<-EOF &&
491
- $hello_oid blob $hello_size
492
- $tree_oid tree $tree_size
493
- $commit_oid commit $commit_size
494
- $tag_oid tag $tag_size
521
+ $boid blob $hello_size
522
+ $loid tree $lsize
523
+ $coid commit $csize
524
+ $toid tag $tsize
525
deadbeef missing
526
EOF
527
@@ -510,22 +540,22 @@ test_expect_success '--batch-command with multiple info calls gives correct form
540
git cat-file --batch-command --buffer -Z <in >actual &&
541
542
test_cmp expect_nul actual
513
-'
543
+ '
544
515
-batch_command_multiple_contents="contents $hello_oid
516
-contents $commit_oid
517
-contents $tag_oid
545
+batch_command_multiple_contents="contents $boid
546
+contents $coid
547
+contents $toid
548
contents deadbeef
549
flush"
550
521
-test_expect_success '--batch-command with multiple command calls gives correct format' '
551
+ test_expect_success '--batch-command with multiple command calls gives correct format' '
552
printf "%s\0" \
523
- "$hello_oid blob $hello_size" \
553
+ "$boid blob $hello_size" \
554
"$hello_content" \
525
- "$commit_oid commit $commit_size" \
526
- "$commit_content" \
527
- "$tag_oid tag $tag_size" \
528
- "$tag_content" \
555
+ "$coid commit $csize" \
556
+ "$ccontent" \
557
+ "$toid tag $tsize" \
558
+ "$tcontent" \
559
"deadbeef missing" >expect_nul &&
560
tr "\0" "\n" <expect_nul >expect &&
561
@@ -543,6 +573,33 @@ test_expect_success '--batch-command with multiple command calls gives correct f
573
git cat-file --batch-command --buffer -Z <in >actual &&
574
575
test_cmp expect_nul actual
576
+ '
577
+
578
+}
579
+
580
+batch_tests $hello_oid $tree_oid $tree_size $commit_oid $commit_size "$commit_content" $tag_oid $tag_size "$tag_content"
581
+batch_tests $hello_compat_oid $tree_compat_oid $tree_compat_size $commit_compat_oid $commit_compat_size "$commit_compat_content" $tag_compat_oid $tag_compat_size "$tag_compat_content"
582
+
583
+
584
+test_expect_success FUNNYNAMES 'setup with newline in input' '
585
+ touch -- "newline${LF}embedded" &&
586
+ git add -- "newline${LF}embedded" &&
587
+ git commit -m "file with newline embedded" &&
588
+ test_tick &&
589
+
590
+ printf "HEAD:newline${LF}embedded" >in
591
+'
592
+
593
+test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' '
594
+ git cat-file --batch-check -z <in >actual &&
595
+ echo "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
596
+ test_cmp expect actual
597
+'
598
+
599
+test_expect_success FUNNYNAMES '--batch-check, -Z with newline in input' '
600
+ git cat-file --batch-check -Z <in >actual &&
601
+ printf "%s\0" "$(git rev-parse "HEAD:newline${LF}embedded") blob 0" >expect &&
602
+ test_cmp expect actual
603
'
604
605
test_expect_success 'setup blobs which are likely to delta' '