git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 06/10] t: default to compile-time default hash if not set

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jun 20, 2025, 01:19 UTC
Message-ID
<20250620011943.586596-7-sandals@crustytoothpaste.net>
In-Reply-To
<20250620011943.586596-1-sandals@crustytoothpaste.net>

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>
---
 t/test-lib-functions.sh | 5 ++++-
 t/test-lib.sh           | 7 ++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index bee4a2ca34..6ec95ea51f 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -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;;
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 51370a201c..ef3759ec80 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -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
@@ -1908,6 +1909,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
 '
Previous: brian m. carlsonNext: brian m. carlson
Message 23 of 47 in “Add SHA-256 by default as a breaking change”
  1. 00/10 Add SHA-256 by default as a breaking changebrian m. carlson, Jun 20, 2025
  2. 01/10 hash: add a constant for the default hash algorithmbrian m. carlson, Jun 20, 2025
  3. 03/10 builtin: use default hash when outside a repositorybrian m. carlson, Jun 20, 2025
  4. Junio C HamanoJun 20, 2025
  5. Patrick SteinhardtJul 1, 2025
  6. brian m. carlsonJul 1, 2025
  7. Patrick SteinhardtJul 2, 2025
  8. 04/10 Use original hash for legacy formatsbrian m. carlson, Jun 20, 2025
  9. Junio C HamanoJun 20, 2025
  10. brian m. carlsonJun 20, 2025
  11. Junio C HamanoJun 20, 2025
  12. Patrick SteinhardtJul 1, 2025
  13. 02/10 hash: add a constant for the original hash algorithmbrian m. carlson, Jun 20, 2025
  14. Junio C HamanoJun 20, 2025
  15. brian m. carlsonJun 20, 2025
  16. Patrick SteinhardtJul 1, 2025
  17. 05/10 setup: use the default algorithm to initialize repo formatbrian m. carlson, Jun 20, 2025
  18. Junio C HamanoJun 20, 2025
  19. brian m. carlsonJun 20, 2025
  20. Junio C HamanoJun 20, 2025
  21. 08/10 t4042: choose the built-in hash outside of a repobrian m. carlson, Jun 20, 2025
  22. 07/10 t1007: choose the built-in hash outside of a repobrian m. carlson, Jun 20, 2025
  23. 06/10 t: default to compile-time default hash if not setbrian m. carlson, Jun 20, 2025
  24. 09/10 t5300: choose the built-in hash outside of a repobrian m. carlson, Jun 20, 2025
  25. 10/10 Enable SHA-256 by default in breaking changes modebrian m. carlson, Jun 20, 2025
  26. Junio C HamanoJun 20, 2025
  27. brian m. carlsonJun 20, 2025
  28. Junio C HamanoJun 20, 2025
  29. brian m. carlsonJun 20, 2025
  30. Junio C HamanoJun 20, 2025
  31. brian m. carlsonJun 20, 2025
  32. Patrick SteinhardtJul 1, 2025
  33. 00/11 Add SHA-256 by default as a breaking changebrian m. carlson, Jul 1, 2025
  34. 02/11 hash: add a constant for the legacy hash algorithmbrian m. carlson, Jul 1, 2025
  35. 01/11 hash: add a constant for the default hash algorithmbrian m. carlson, Jul 1, 2025
  36. 04/11 Use legacy hash for legacy formatsbrian m. carlson, Jul 1, 2025
  37. 03/11 builtin: use default hash when outside a repositorybrian m. carlson, Jul 1, 2025
  38. 06/11 t: default to compile-time default hash if not setbrian m. carlson, Jul 1, 2025
  39. 05/11 setup: use the default algorithm to initialize repo formatbrian m. carlson, Jul 1, 2025
  40. 08/11 t4042: choose the built-in hash outside of a repobrian m. carlson, Jul 1, 2025
  41. 07/11 t1007: choose the built-in hash outside of a repobrian m. carlson, Jul 1, 2025
  42. 10/11 help: add a build option for default hashbrian m. carlson, Jul 1, 2025
  43. 11/11 Enable SHA-256 by default in breaking changes modebrian m. carlson, Jul 1, 2025
  44. 09/11 t5300: choose the built-in hash outside of a repobrian m. carlson, Jul 1, 2025
  45. Junio C HamanoJul 1, 2025
  46. Patrick SteinhardtJul 2, 2025
  47. Kristoffer HaugsbakkJul 2, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.