Files
git-mirror/t/t0614-reftable-fsck.sh
brian m. carlson bf25fca31c t0614: use numerical comparison with test_line_count
In this comparison, we want to know whether the number of lines is
greater than 1.  Our test_line_count function passes the first argument
as the comparison operator to test, so what we want is a numerical
comparison, not a string comparison.  While this does not produce a
functional problem now, it could very well if we expected two or more
items, in which case the value "10" would not match when it should.

Furthermore, the "<" and ">" comparisons are new in POSIX 1003.1-2024
and we don't want to require such a new version of POSIX since many
popular and supported operating systems were released before that
version of POSIX was released.

Finally, zsh's builtin test operator does not like the greater-than sign
in "test", since it is only supported in the double-bracket extension.
This has been reported and will be addressed in a future version, but
since our code is also technically incorrect, as well as not very
compatible, let's fix it by using a numeric comparison.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2025-11-27 19:06:01 -08:00

59 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
test_description='Test reftable backend consistency check'
GIT_TEST_DEFAULT_REF_FORMAT=reftable
export GIT_TEST_DEFAULT_REF_FORMAT
. ./test-lib.sh
test_expect_success "no errors reported on a well formed repository" '
test_when_finished "rm -rf repo" &&
git init repo &&
(
cd repo &&
git commit --allow-empty -m initial &&
for i in $(test_seq 20)
do
git update-ref refs/heads/branch-$i HEAD || return 1
done &&
# The repository should end up with multiple tables.
test_line_count -gt 1 .git/reftable/tables.list &&
git refs verify 2>err &&
test_must_be_empty err
)
'
for TABLE_NAME in "foo-bar-e4d12d59.ref" \
"0x00000000zzzz-0x00000000zzzz-e4d12d59.ref" \
"0x000000000001-0x000000000002-e4d12d59.abc" \
"0x000000000001-0x000000000002-e4d12d59.refabc"; do
test_expect_success "table name $TABLE_NAME should be checked" '
test_when_finished "rm -rf repo" &&
git init repo &&
(
cd repo &&
git commit --allow-empty -m initial &&
git refs verify 2>err &&
test_must_be_empty err &&
EXISTING_TABLE=$(head -n1 .git/reftable/tables.list) &&
mv ".git/reftable/$EXISTING_TABLE" ".git/reftable/$TABLE_NAME" &&
sed "s/${EXISTING_TABLE}/${TABLE_NAME}/g" .git/reftable/tables.list > tables.list &&
mv tables.list .git/reftable/tables.list &&
git refs verify 2>err &&
cat >expect <<-EOF &&
warning: ${TABLE_NAME}: badReftableTableName: invalid reftable table name
EOF
test_cmp expect err
)
'
done
test_done