t4042: choose the built-in hash outside of a repo

Right now, the built-in default hash is always SHA-1, but that will change in a future commit. Instead of assuming that operating outside of a repository will always use SHA-1, provide constants for both algorithms and then simply ask test_oid for the built-in hash instead, which will always be correct. 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 f957ce078f61266b3212b88d9c357a1b7f071a6f
1 file changed +10 -2
t/t4042-diff-textconv-caching.sh
+10 -2
@@ -120,6 +120,14 @@ test_expect_success 'log notes cache and still use cache for -p' '
120 '
121
122 test_expect_success 'caching is silently ignored outside repo' '
123 + test_oid_cache <<-\EOM &&
124 + oid1 sha1:5626abf
125 + oid1 sha256:a4ed1f3
126 + oid2 sha1:f719efd
127 + oid2 sha256:aa9e7dc
128 + EOM
129 + oid1=$(test_oid --hash=builtin oid1) &&
130 + oid2=$(test_oid --hash=builtin oid2) &&
131 mkdir -p non-repo &&
132 echo one >non-repo/one &&
133 echo two >non-repo/two &&
@@ -129,9 +137,9 @@ test_expect_success 'caching is silently ignored outside repo' '
137 -c diff.test.textconv="tr a-z A-Z <" \
138 -c diff.test.cachetextconv=true \
139 diff --no-index one two >actual &&
132 - cat >expect <<-\EOF &&
140 + cat >expect <<-EOF &&
141 diff --git a/one b/two
134 - index 5626abf..f719efd 100644
142 + index $oid1..$oid2 100644
143 --- a/one
144 +++ b/two
145 @@ -1 +1 @@