subtree: t7900: add porcelain tests for 'pull' and 'push'
The 'pull' and 'push' subcommands deserve their own sections in the tests. Add some basic tests for them. Signed-off-by: Luke Shumaker <lukeshu@datawire.io> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Luke Shumaker committed
Apr 27, 2021 at 15:17 UTC
b04538d99f07a2ac39a5314ec76bc9f07e5fd686
1 file changed
+127
contrib/subtree/t/t7900-subtree.sh
+127
@@ -427,6 +427,133 @@ test_expect_success 'split "sub dir"/ with --branch for an incompatible branch'
427
)
428
'
429
430
+#
431
+# Tests for 'git subtree pull'
432
+#
433
+
434
+test_expect_success 'pull requires option --prefix' '
435
+ subtree_test_create_repo "$test_count" &&
436
+ subtree_test_create_repo "$test_count/sub proj" &&
437
+ test_create_commit "$test_count" main1 &&
438
+ test_create_commit "$test_count/sub proj" sub1 &&
439
+ (
440
+ cd "$test_count" &&
441
+ git fetch ./"sub proj" HEAD &&
442
+ git subtree add --prefix="sub dir" FETCH_HEAD
443
+ ) &&
444
+ test_create_commit "$test_count/sub proj" sub2 &&
445
+ (
446
+ cd "$test_count" &&
447
+ test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err &&
448
+
449
+ echo "You must provide the --prefix option." >expected &&
450
+ test_must_be_empty out &&
451
+ test_cmp expected err
452
+ )
453
+'
454
+
455
+test_expect_success 'pull requires path given by option --prefix must exist' '
456
+ subtree_test_create_repo "$test_count" &&
457
+ subtree_test_create_repo "$test_count/sub proj" &&
458
+ test_create_commit "$test_count" main1 &&
459
+ test_create_commit "$test_count/sub proj" sub1 &&
460
+ (
461
+ test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err &&
462
+
463
+ echo "'\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected &&
464
+ test_must_be_empty out &&
465
+ test_cmp expected err
466
+ )
467
+'
468
+
469
+test_expect_success 'pull basic operation' '
470
+ subtree_test_create_repo "$test_count" &&
471
+ subtree_test_create_repo "$test_count/sub proj" &&
472
+ test_create_commit "$test_count" main1 &&
473
+ test_create_commit "$test_count/sub proj" sub1 &&
474
+ (
475
+ cd "$test_count" &&
476
+ git fetch ./"sub proj" HEAD &&
477
+ git subtree add --prefix="sub dir" FETCH_HEAD
478
+ ) &&
479
+ test_create_commit "$test_count/sub proj" sub2 &&
480
+ (
481
+ cd "$test_count" &&
482
+ exp=$(git -C "sub proj" rev-parse --verify HEAD:) &&
483
+ git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
484
+ act=$(git rev-parse --verify HEAD:"sub dir") &&
485
+ test "$act" = "$exp"
486
+ )
487
+'
488
+
489
+#
490
+# Tests for 'git subtree push'
491
+#
492
+
493
+test_expect_success 'push requires option --prefix' '
494
+ subtree_test_create_repo "$test_count" &&
495
+ subtree_test_create_repo "$test_count/sub proj" &&
496
+ test_create_commit "$test_count" main1 &&
497
+ test_create_commit "$test_count/sub proj" sub1 &&
498
+ (
499
+ cd "$test_count" &&
500
+ git fetch ./"sub proj" HEAD &&
501
+ git subtree add --prefix="sub dir" FETCH_HEAD &&
502
+ echo "You must provide the --prefix option." >expected &&
503
+ test_must_fail git subtree push "./sub proj" from-mainline >actual 2>&1 &&
504
+ test_debug "printf '"expected: "'" &&
505
+ test_debug "cat expected" &&
506
+ test_debug "printf '"actual: "'" &&
507
+ test_debug "cat actual" &&
508
+ test_cmp expected actual
509
+ )
510
+'
511
+
512
+test_expect_success 'push requires path given by option --prefix must exist' '
513
+ subtree_test_create_repo "$test_count" &&
514
+ subtree_test_create_repo "$test_count/sub proj" &&
515
+ test_create_commit "$test_count" main1 &&
516
+ test_create_commit "$test_count/sub proj" sub1 &&
517
+ (
518
+ cd "$test_count" &&
519
+ git fetch ./"sub proj" HEAD &&
520
+ git subtree add --prefix="sub dir" FETCH_HEAD &&
521
+ echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
522
+ test_must_fail git subtree push --prefix=non-existent-directory "./sub proj" from-mainline >actual 2>&1 &&
523
+ test_debug "printf '"expected: "'" &&
524
+ test_debug "cat expected" &&
525
+ test_debug "printf '"actual: "'" &&
526
+ test_debug "cat actual" &&
527
+ test_cmp expected actual
528
+ )
529
+'
530
+
531
+test_expect_success 'push basic operation' '
532
+ subtree_test_create_repo "$test_count" &&
533
+ subtree_test_create_repo "$test_count/sub proj" &&
534
+ test_create_commit "$test_count" main1 &&
535
+ test_create_commit "$test_count/sub proj" sub1 &&
536
+ (
537
+ cd "$test_count" &&
538
+ git fetch ./"sub proj" HEAD &&
539
+ git subtree add --prefix="sub dir" FETCH_HEAD
540
+ ) &&
541
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
542
+ test_create_commit "$test_count" main2 &&
543
+ test_create_commit "$test_count/sub proj" sub2 &&
544
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
545
+ (
546
+ cd "$test_count" &&
547
+ git fetch ./"sub proj" HEAD &&
548
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
549
+ before=$(git rev-parse --verify HEAD) &&
550
+ split_hash=$(git subtree split --prefix="sub dir") &&
551
+ git subtree push --prefix="sub dir" ./"sub proj" from-mainline &&
552
+ test "$before" = "$(git rev-parse --verify HEAD)" &&
553
+ test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
554
+ )
555
+'
556
+
557
#
558
# Validity checking
559
#