]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: default to compile-time default hash if not set
authorbrian m. carlson <sandals@crustytoothpaste.net>
Fri, 20 Jun 2025 01:19:38 +0000 (01:19 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Jun 2025 14:17:36 +0000 (07:17 -0700)
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>
t/test-lib-functions.sh
t/test-lib.sh

index bee4a2ca3472e1b79e2a7bba5abdaa81235704c7..6ec95ea51f08dc1ad291ad462e93df49a40bccc7 100644 (file)
@@ -1695,7 +1695,7 @@ test_set_hash () {
 
 # Detect the hash algorithm in use.
 test_detect_hash () {
-       case "$GIT_TEST_DEFAULT_HASH" in
+       case "${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}" in
        "sha256")
            test_hash_algo=sha256
            test_compat_hash_algo=sha1
@@ -1767,6 +1767,9 @@ test_oid () {
        --hash=compat)
                algo="$test_compat_hash_algo" &&
                shift;;
+       --hash=builtin)
+               algo="$GIT_TEST_BUILTIN_HASH" &&
+               shift;;
        --hash=*)
                algo="${1#--hash=}" &&
                shift;;
index 92d0db13d7429dee4b20a5fa722498ecb001908b..be7189067898fc433eb707f9127db84a36dcbf84 100644 (file)
@@ -536,7 +536,8 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
 export EDITOR
 
-GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-sha1}"
+GIT_TEST_BUILTIN_HASH=sha1
+GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}"
 export GIT_DEFAULT_HASH
 GIT_DEFAULT_REF_FORMAT="${GIT_TEST_DEFAULT_REF_FORMAT:-files}"
 export GIT_DEFAULT_REF_FORMAT
@@ -1895,6 +1896,10 @@ test_lazy_prereq SHA1 '
        esac
 '
 
+test_lazy_prereq DEFAULT_HASH_ALGORITHM '
+       test "$GIT_TEST_BUILTIN_HASH" = "$GIT_DEFAULT_HASH"
+'
+
 test_lazy_prereq DEFAULT_REPO_FORMAT '
        test_have_prereq SHA1,REFFILES
 '