| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test main ref store api' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | RUN="test-tool ref-store main" |
| 11 | |
| 12 | |
| 13 | test_expect_success 'setup' ' |
| 14 | test_commit one |
| 15 | ' |
| 16 | |
| 17 | test_expect_success 'create_symref(FOO, refs/heads/main)' ' |
| 18 | $RUN create-symref FOO refs/heads/main nothing && |
| 19 | echo refs/heads/main >expected && |
| 20 | git symbolic-ref FOO >actual && |
| 21 | test_cmp expected actual |
| 22 | ' |
| 23 | |
| 24 | test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' ' |
| 25 | git tag -a -m new-tag new-tag HEAD && |
| 26 | git rev-parse FOO -- && |
| 27 | git rev-parse refs/tags/new-tag -- && |
| 28 | m=$(git rev-parse main) && |
| 29 | $RUN delete-refs REF_NO_DEREF nothing FOO refs/tags/new-tag && |
| 30 | test_must_fail git rev-parse --symbolic-full-name FOO && |
| 31 | test_must_fail git rev-parse FOO -- && |
| 32 | test_must_fail git rev-parse refs/tags/new-tag -- |
| 33 | ' |
| 34 | |
| 35 | test_expect_success 'rename_refs(main, new-main)' ' |
| 36 | git rev-parse main >expected && |
| 37 | $RUN rename-ref refs/heads/main refs/heads/new-main && |
| 38 | git rev-parse new-main >actual && |
| 39 | test_cmp expected actual && |
| 40 | test_commit recreate-main |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'for_each_ref(refs/heads/)' ' |
| 44 | $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual && |
| 45 | cat >expected <<-\EOF && |
| 46 | main 0x0 |
| 47 | new-main 0x0 |
| 48 | EOF |
| 49 | test_cmp expected actual |
| 50 | ' |
| 51 | |
| 52 | test_expect_success 'for_each_ref() is sorted' ' |
| 53 | $RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual && |
| 54 | sort actual > expected && |
| 55 | test_cmp expected actual |
| 56 | ' |
| 57 | |
| 58 | test_expect_success 'resolve_ref(new-main)' ' |
| 59 | SHA1=`git rev-parse new-main` && |
| 60 | echo "$SHA1 refs/heads/new-main 0x0" >expected && |
| 61 | $RUN resolve-ref refs/heads/new-main 0 >actual && |
| 62 | test_cmp expected actual |
| 63 | ' |
| 64 | |
| 65 | test_expect_success 'verify_ref(new-main)' ' |
| 66 | $RUN verify-ref refs/heads/new-main |
| 67 | ' |
| 68 | |
| 69 | test_expect_success 'for_each_reflog()' ' |
| 70 | $RUN for-each-reflog >actual && |
| 71 | cat >expected <<-\EOF && |
| 72 | HEAD |
| 73 | refs/heads/main |
| 74 | refs/heads/new-main |
| 75 | EOF |
| 76 | test_cmp expected actual |
| 77 | ' |
| 78 | |
| 79 | test_expect_success 'for_each_reflog_ent()' ' |
| 80 | $RUN for-each-reflog-ent HEAD >actual && |
| 81 | head -n1 actual | grep one && |
| 82 | tail -n1 actual | grep recreate-main |
| 83 | ' |
| 84 | |
| 85 | test_expect_success 'for_each_reflog_ent_reverse()' ' |
| 86 | $RUN for-each-reflog-ent-reverse HEAD >actual && |
| 87 | head -n1 actual | grep recreate-main && |
| 88 | tail -n1 actual | grep one |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'reflog_exists(HEAD)' ' |
| 92 | $RUN reflog-exists HEAD |
| 93 | ' |
| 94 | |
| 95 | test_expect_success 'delete_reflog(HEAD)' ' |
| 96 | $RUN delete-reflog HEAD && |
| 97 | test_must_fail git reflog exists HEAD |
| 98 | ' |
| 99 | |
| 100 | test_expect_success 'create-reflog(HEAD)' ' |
| 101 | $RUN create-reflog HEAD && |
| 102 | git reflog exists HEAD |
| 103 | ' |
| 104 | |
| 105 | test_expect_success 'delete_ref(refs/heads/foo)' ' |
| 106 | git checkout -b foo && |
| 107 | FOO_SHA1=`git rev-parse foo` && |
| 108 | git checkout --detach && |
| 109 | test_commit bar-commit && |
| 110 | git checkout -b bar && |
| 111 | BAR_SHA1=`git rev-parse bar` && |
| 112 | $RUN update-ref updating refs/heads/foo $BAR_SHA1 $FOO_SHA1 0 && |
| 113 | echo $BAR_SHA1 >expected && |
| 114 | git rev-parse refs/heads/foo >actual && |
| 115 | test_cmp expected actual |
| 116 | ' |
| 117 | |
| 118 | test_expect_success 'delete_ref(refs/heads/foo)' ' |
| 119 | SHA1=`git rev-parse foo` && |
| 120 | git checkout --detach && |
| 121 | $RUN delete-ref msg refs/heads/foo $SHA1 0 && |
| 122 | test_must_fail git rev-parse refs/heads/foo -- |
| 123 | ' |
| 124 | |
| 125 | test_done |