| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test reftable backend consistency check' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_REF_FORMAT=reftable |
| 6 | export GIT_TEST_DEFAULT_REF_FORMAT |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success "no errors reported on a well formed repository" ' |
| 11 | test_when_finished "rm -rf repo" && |
| 12 | git init repo && |
| 13 | ( |
| 14 | cd repo && |
| 15 | git commit --allow-empty -m initial && |
| 16 | |
| 17 | for i in $(test_seq 20) |
| 18 | do |
| 19 | git update-ref refs/heads/branch-$i HEAD || return 1 |
| 20 | done && |
| 21 | |
| 22 | # The repository should end up with multiple tables. |
| 23 | test_line_count -gt 1 .git/reftable/tables.list && |
| 24 | |
| 25 | git refs verify 2>err && |
| 26 | test_must_be_empty err |
| 27 | ) |
| 28 | ' |
| 29 | |
| 30 | for TABLE_NAME in "foo-bar-e4d12d59.ref" \ |
| 31 | "0x00000000zzzz-0x00000000zzzz-e4d12d59.ref" \ |
| 32 | "0x000000000001-0x000000000002-e4d12d59.abc" \ |
| 33 | "0x000000000001-0x000000000002-e4d12d59.refabc"; do |
| 34 | test_expect_success "table name $TABLE_NAME should be checked" ' |
| 35 | test_when_finished "rm -rf repo" && |
| 36 | git init repo && |
| 37 | ( |
| 38 | cd repo && |
| 39 | git commit --allow-empty -m initial && |
| 40 | |
| 41 | git refs verify 2>err && |
| 42 | test_must_be_empty err && |
| 43 | |
| 44 | EXISTING_TABLE=$(head -n1 .git/reftable/tables.list) && |
| 45 | mv ".git/reftable/$EXISTING_TABLE" ".git/reftable/$TABLE_NAME" && |
| 46 | sed "s/${EXISTING_TABLE}/${TABLE_NAME}/g" .git/reftable/tables.list > tables.list && |
| 47 | mv tables.list .git/reftable/tables.list && |
| 48 | |
| 49 | git refs verify 2>err && |
| 50 | cat >expect <<-EOF && |
| 51 | warning: ${TABLE_NAME}: badReftableTableName: invalid reftable table name |
| 52 | EOF |
| 53 | test_cmp expect err |
| 54 | ) |
| 55 | ' |
| 56 | done |
| 57 | |
| 58 | test_expect_success 'worktree stacks can be verified' ' |
| 59 | test_when_finished "rm -rf repo worktree" && |
| 60 | git init repo && |
| 61 | test_commit -C repo initial && |
| 62 | git -C repo worktree add ../worktree && |
| 63 | |
| 64 | git -C worktree refs verify 2>err && |
| 65 | test_must_be_empty err && |
| 66 | |
| 67 | REFTABLE_DIR=$(git -C worktree rev-parse --git-dir)/reftable && |
| 68 | EXISTING_TABLE=$(head -n1 "$REFTABLE_DIR/tables.list") && |
| 69 | mv "$REFTABLE_DIR/$EXISTING_TABLE" "$REFTABLE_DIR/broken.ref" && |
| 70 | |
| 71 | for d in repo worktree |
| 72 | do |
| 73 | echo "broken.ref" >"$REFTABLE_DIR/tables.list" && |
| 74 | git -C "$d" refs verify 2>err && |
| 75 | cat >expect <<-EOF && |
| 76 | warning: broken.ref: badReftableTableName: invalid reftable table name |
| 77 | EOF |
| 78 | test_cmp expect err && |
| 79 | |
| 80 | echo garbage >"$REFTABLE_DIR/tables.list" && |
| 81 | test_must_fail git -C "$d" refs verify 2>err && |
| 82 | cat >expect <<-EOF && |
| 83 | error: reftable stack for worktree ${SQ}worktree${SQ} is broken |
| 84 | EOF |
| 85 | test_cmp expect err || return 1 |
| 86 | |
| 87 | done |
| 88 | ' |
| 89 | |
| 90 | test_expect_success 'invalid symref gets reported' ' |
| 91 | test_when_finished "rm -rf repo" && |
| 92 | git init repo && |
| 93 | test_commit -C repo initial && |
| 94 | git -C repo symbolic-ref refs/heads/symref garbage && |
| 95 | test_must_fail git -C repo refs verify 2>err && |
| 96 | cat >expect <<-EOF && |
| 97 | error: refs/heads/symref: badReferentName: points to invalid refname ${SQ}garbage${SQ} |
| 98 | EOF |
| 99 | test_cmp expect err |
| 100 | ' |
| 101 | |
| 102 | test_done |