|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +test_description='Test different reference backend URIs' |
| 4 | + |
| 5 | +. ./test-lib.sh |
| 6 | + |
| 7 | +test_expect_success 'empty uri provided' ' |
| 8 | + test_when_finished "rm -rf repo" && |
| 9 | + git init --ref-format=files repo && |
| 10 | + ( |
| 11 | + cd repo && |
| 12 | + GIT_REF_URI="" && |
| 13 | + export GIT_REF_URI && |
| 14 | + ! git refs list 2>err && |
| 15 | + test_grep "reference backend uri is empty" err |
| 16 | + ) |
| 17 | +' |
| 18 | + |
| 19 | +test_expect_success 'invalid uri provided' ' |
| 20 | + test_when_finished "rm -rf repo" && |
| 21 | + git init --ref-format=files repo && |
| 22 | + ( |
| 23 | + cd repo && |
| 24 | + GIT_REF_URI="reftable@/home/reftable" && |
| 25 | + export GIT_REF_URI && |
| 26 | + ! git refs list 2>err && |
| 27 | + test_grep "invalid reference backend uri format" err |
| 28 | + ) |
| 29 | +' |
| 30 | + |
| 31 | +test_expect_success 'empty path in uri' ' |
| 32 | + test_when_finished "rm -rf repo" && |
| 33 | + git init --ref-format=files repo && |
| 34 | + ( |
| 35 | + cd repo && |
| 36 | + GIT_REF_URI="reftable://" && |
| 37 | + export GIT_REF_URI && |
| 38 | + ! git refs list 2>err && |
| 39 | + test_grep "invalid path in uri" err |
| 40 | + ) |
| 41 | +' |
| 42 | + |
| 43 | +test_expect_success 'unknown reference backend' ' |
| 44 | + test_when_finished "rm -rf repo" && |
| 45 | + git init --ref-format=files repo && |
| 46 | + ( |
| 47 | + cd repo && |
| 48 | + GIT_REF_URI="db://.git" && |
| 49 | + export GIT_REF_URI && |
| 50 | + ! git refs list 2>err && |
| 51 | + test_grep "unknown reference backend" err |
| 52 | + ) |
| 53 | +' |
| 54 | + |
| 55 | +ref_formats="files reftable" |
| 56 | +for from_format in $ref_formats |
| 57 | +do |
| 58 | + for to_format in $ref_formats |
| 59 | + do |
| 60 | + if test "$from_format" = "$to_format" |
| 61 | + then |
| 62 | + continue |
| 63 | + fi |
| 64 | + |
| 65 | + test_expect_success 'read from other reference backend' ' |
| 66 | + test_when_finished "rm -rf repo" && |
| 67 | + git init --ref-format=files repo && |
| 68 | + ( |
| 69 | + cd repo && |
| 70 | + test_commit 1 && |
| 71 | + test_commit 2 && |
| 72 | + test_commit 3 && |
| 73 | +
|
| 74 | + git refs migrate --dry-run --ref-format=reftable >out && |
| 75 | + REFTABLE_PATH=$(cat out | sed "s/.* ${SQ}\(.*\)${SQ}/\1/") && |
| 76 | + git refs list >expect && |
| 77 | + GIT_REF_URI="reftable://$REFTABLE_PATH" git refs list >actual && |
| 78 | + test_cmp expect actual |
| 79 | + ) |
| 80 | + ' |
| 81 | + |
| 82 | + test_expect_success 'write to other reference backend' ' |
| 83 | + test_when_finished "rm -rf repo" && |
| 84 | + git init --ref-format=files repo && |
| 85 | + ( |
| 86 | + cd repo && |
| 87 | + test_commit 1 && |
| 88 | + test_commit 2 && |
| 89 | + test_commit 3 && |
| 90 | +
|
| 91 | + git refs migrate --dry-run --ref-format=reftable >out && |
| 92 | + git refs list >expect && |
| 93 | +
|
| 94 | + REFTABLE_PATH=$(cat out | sed "s/.* ${SQ}\(.*\)${SQ}/\1/") && |
| 95 | + GIT_REF_URI="reftable://$REFTABLE_PATH" git tag -d 1 && |
| 96 | +
|
| 97 | + git refs list >actual && |
| 98 | + test_cmp expect actual && |
| 99 | +
|
| 100 | + GIT_REF_URI="reftable://$REFTABLE_PATH" git refs list >expect && |
| 101 | + git refs list >out && |
| 102 | + cat out | grep -v "refs/tags/1" >actual && |
| 103 | + test_cmp expect actual |
| 104 | + ) |
| 105 | + ' |
| 106 | + done |
| 107 | +done |
| 108 | + |
| 109 | +test_done |
0 commit comments