|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +test_description='test submodule ref store api' |
| 4 | + |
| 5 | +. ./test-lib.sh |
| 6 | + |
| 7 | +RUN="test-ref-store submodule:sub" |
| 8 | + |
| 9 | +test_expect_success 'setup' ' |
| 10 | + git init sub && |
| 11 | + ( |
| 12 | + cd sub && |
| 13 | + test_commit first && |
| 14 | + git checkout -b new-master |
| 15 | + ) |
| 16 | +' |
| 17 | + |
| 18 | +test_expect_success 'pack_refs() not allowed' ' |
| 19 | + test_must_fail $RUN pack-refs 3 |
| 20 | +' |
| 21 | + |
| 22 | +test_expect_success 'peel_ref(new-tag)' ' |
| 23 | + git -C sub rev-parse HEAD >expected && |
| 24 | + git -C sub tag -a -m new-tag new-tag HEAD && |
| 25 | + $RUN peel-ref refs/tags/new-tag >actual && |
| 26 | + test_cmp expected actual |
| 27 | +' |
| 28 | + |
| 29 | +test_expect_success 'create_symref() not allowed' ' |
| 30 | + test_must_fail $RUN create-symref FOO refs/heads/master nothing |
| 31 | +' |
| 32 | + |
| 33 | +test_expect_success 'delete_refs() not allowed' ' |
| 34 | + test_must_fail $RUN delete-refs 0 FOO refs/tags/new-tag |
| 35 | +' |
| 36 | + |
| 37 | +test_expect_success 'rename_refs() not allowed' ' |
| 38 | + test_must_fail $RUN rename-ref refs/heads/master refs/heads/new-master |
| 39 | +' |
| 40 | + |
| 41 | +test_expect_success 'for_each_ref(refs/heads/)' ' |
| 42 | + $RUN for-each-ref refs/heads/ | cut -c 42- >actual && |
| 43 | + cat >expected <<-\EOF && |
| 44 | + master 0x0 |
| 45 | + new-master 0x0 |
| 46 | + EOF |
| 47 | + test_cmp expected actual |
| 48 | +' |
| 49 | + |
| 50 | +test_expect_success 'resolve_ref(master)' ' |
| 51 | + SHA1=`git -C sub rev-parse master` && |
| 52 | + echo "$SHA1 refs/heads/master 0x0" >expected && |
| 53 | + $RUN resolve-ref refs/heads/master 0 >actual && |
| 54 | + test_cmp expected actual |
| 55 | +' |
| 56 | + |
| 57 | +test_expect_success 'verify_ref(new-master)' ' |
| 58 | + $RUN verify-ref refs/heads/new-master |
| 59 | +' |
| 60 | + |
| 61 | +test_expect_success 'for_each_reflog()' ' |
| 62 | + $RUN for-each-reflog | sort | cut -c 42- >actual && |
| 63 | + cat >expected <<-\EOF && |
| 64 | + HEAD 0x1 |
| 65 | + refs/heads/master 0x0 |
| 66 | + refs/heads/new-master 0x0 |
| 67 | + EOF |
| 68 | + test_cmp expected actual |
| 69 | +' |
| 70 | + |
| 71 | +test_expect_success 'for_each_reflog_ent()' ' |
| 72 | + $RUN for-each-reflog-ent HEAD >actual && cat actual && |
| 73 | + head -n1 actual | grep first && |
| 74 | + tail -n2 actual | head -n1 | grep master.to.new |
| 75 | +' |
| 76 | + |
| 77 | +test_expect_success 'for_each_reflog_ent_reverse()' ' |
| 78 | + $RUN for-each-reflog-ent-reverse HEAD >actual && |
| 79 | + head -n1 actual | grep master.to.new && |
| 80 | + tail -n2 actual | head -n1 | grep first |
| 81 | +' |
| 82 | + |
| 83 | +test_expect_success 'reflog_exists(HEAD)' ' |
| 84 | + $RUN reflog-exists HEAD |
| 85 | +' |
| 86 | + |
| 87 | +test_expect_success 'delete_reflog() not allowed' ' |
| 88 | + test_must_fail $RUN delete-reflog HEAD |
| 89 | +' |
| 90 | + |
| 91 | +test_expect_success 'create-reflog() not allowed' ' |
| 92 | + test_must_fail $RUN create-reflog HEAD 1 |
| 93 | +' |
| 94 | + |
| 95 | +test_done |
0 commit comments