t: default to compile-time default hash if not set

Right now, the default compile-time hash is SHA-1. However, in the future, this might change and it would be helpful to gracefully handle this case in our testsuite. To avoid making these assumptions, let's introduce a variable that contains the built-in default hash and use it in our setup code as the fallback value if no hash was explicitly set. For now, this is always SHA-1, but in a future commit, we'll allow adjusting this and the variable will be more useful. To allow us to make our tests more robust, allow test_oid to take the --hash=builtin option to specify this hash, whatever it is. Additionally, add a DEFAULT_HASH_ALGORITHM prerequisite to check for the compile-time hash. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jul 1, 2025 at 21:22 UTC c470ac4ac41b02994f2f10b4134c40661d7435be
2 files changed +10 -2
t/test-lib-functions.sh
+4 -1
@@ -1695,7 +1695,7 @@ test_set_hash () {
1695
1696 # Detect the hash algorithm in use.
1697 test_detect_hash () {
1698 - case "$GIT_TEST_DEFAULT_HASH" in
1698 + case "${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}" in
1699 "sha256")
1700 test_hash_algo=sha256
1701 test_compat_hash_algo=sha1
@@ -1767,6 +1767,9 @@ test_oid () {
1767 --hash=compat)
1768 algo="$test_compat_hash_algo" &&
1769 shift;;
1770 + --hash=builtin)
1771 + algo="$GIT_TEST_BUILTIN_HASH" &&
1772 + shift;;
1773 --hash=*)
1774 algo="${1#--hash=}" &&
1775 shift;;
t/test-lib.sh
+6 -1
@@ -536,7 +536,8 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
536 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
537 export EDITOR
538
539 -GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-sha1}"
539 +GIT_TEST_BUILTIN_HASH=sha1
540 +GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}"
541 export GIT_DEFAULT_HASH
542 GIT_DEFAULT_REF_FORMAT="${GIT_TEST_DEFAULT_REF_FORMAT:-files}"
543 export GIT_DEFAULT_REF_FORMAT
@@ -1895,6 +1896,10 @@ test_lazy_prereq SHA1 '
1896 esac
1897 '
1898
1899 +test_lazy_prereq DEFAULT_HASH_ALGORITHM '
1900 + test "$GIT_TEST_BUILTIN_HASH" = "$GIT_DEFAULT_HASH"
1901 +'
1902 +
1903 test_lazy_prereq DEFAULT_REPO_FORMAT '
1904 test_have_prereq SHA1,REFFILES
1905 '