Skip to content

Commit c470ac4

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6e616c commit c470ac4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

t/test-lib-functions.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@ test_set_hash () {
16951695

16961696
# Detect the hash algorithm in use.
16971697
test_detect_hash () {
1698-
case "$GIT_TEST_DEFAULT_HASH" in
1698+
case "${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}" in
16991699
"sha256")
17001700
test_hash_algo=sha256
17011701
test_compat_hash_algo=sha1
@@ -1767,6 +1767,9 @@ test_oid () {
17671767
--hash=compat)
17681768
algo="$test_compat_hash_algo" &&
17691769
shift;;
1770+
--hash=builtin)
1771+
algo="$GIT_TEST_BUILTIN_HASH" &&
1772+
shift;;
17701773
--hash=*)
17711774
algo="${1#--hash=}" &&
17721775
shift;;

t/test-lib.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
536536
export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
537537
export EDITOR
538538

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}"
540541
export GIT_DEFAULT_HASH
541542
GIT_DEFAULT_REF_FORMAT="${GIT_TEST_DEFAULT_REF_FORMAT:-files}"
542543
export GIT_DEFAULT_REF_FORMAT
@@ -1895,6 +1896,10 @@ test_lazy_prereq SHA1 '
18951896
esac
18961897
'
18971898

1899+
test_lazy_prereq DEFAULT_HASH_ALGORITHM '
1900+
test "$GIT_TEST_BUILTIN_HASH" = "$GIT_DEFAULT_HASH"
1901+
'
1902+
18981903
test_lazy_prereq DEFAULT_REPO_FORMAT '
18991904
test_have_prereq SHA1,REFFILES
19001905
'

0 commit comments

Comments
 (0)