threads / patch / 65206

patcht3200: replace hardcoded null OID with $ZERO_OID

Subject: [PATCH] t3200: replace hardcoded null OID with $ZERO_OID

## tl;dr

5 messages between Mar 11, 2026 and Mar 12, 2026. Diffs are folded; open one to read it.

replies: 4people: 3as markdown or json

Siddharth Shrimali· Mar 11, 2026, 10:58 UTC · lore

Taking into consideration the SHA-256 transition, the test suite must be updated to support the length of the underlying hash algorithm. Tests that rely on hardcoded 40-character strings to represent the null object ID will fail when run in a SHA-256 environment, which expects a 64-character hash.

Replace the hardcoded 40-zero string in the 'git branch --merged' test with the '$ZERO_OID' variable which is provided by the test framework. This ensures the test dynamically adapts to the correct null OID length and functions correctly regardless of the active hash algorithm.

Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
---
 t/t3200-branch.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to t/t3200-branch.sh +1 −1
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index c58e505c43..ed317a75f5 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -1494,7 +1494,7 @@ test_expect_success 'refuse --edit-description on unborn branch for now' '
 '
 
 test_expect_success '--merged catches invalid object names' '
-	test_must_fail git branch --merged 0000000000000000000000000000000000000000
+	test_must_fail git branch --merged $ZERO_OID
 '
 
 test_expect_success '--list during rebase' '
-- 
2.51.2
Patrick Steinhardt· Mar 11, 2026, 11:20 UTC · re: Siddharth Shrimali · lore

Re: [PATCH] t3200: replace hardcoded null OID with $ZERO_OID

On Wed, Mar 11, 2026 at 04:28:10PM +0530, Siddharth Shrimali wrote:
Show 28 quoted lines
> Taking into consideration the SHA-256 transition, the test suite must
> be updated to support the length of the underlying hash algorithm.
> Tests that rely on hardcoded 40-character strings to represent the
> null object ID will fail when run in a SHA-256 environment, which
> expects a 64-character hash.
> 
> Replace the hardcoded 40-zero string in the 'git branch --merged' test
> with the '$ZERO_OID' variable which is provided by the test framework.
> This ensures the test dynamically adapts to the correct null OID
> length and functions correctly regardless of the active hash
> algorithm.
> 
> Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
> ---
>  t/t3200-branch.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index c58e505c43..ed317a75f5 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -1494,7 +1494,7 @@ test_expect_success 'refuse --edit-description on unborn branch for now' '
>  '
>  
>  test_expect_success '--merged catches invalid object names' '
> -	test_must_fail git branch --merged 0000000000000000000000000000000000000000
> +	test_must_fail git branch --merged $ZERO_OID
>  '

I expect that the failure reason before and after this change is different, right? And likewise, I expect that before the change, the failure with SHA1 is likely different than the one with SHA256.

Taking a peek, that's indeed the case. With SHA1 we get:
    error: option `merged' must point to a commit
But with SHA256 we get:
    fatal: malformed object name 0000000000000000000000000000000000000000

So the only reason why we didn't detect that the test is broken with SHA256 is that we didn't verify the error message. Do we maybe want to make the test a bit less fragile by using something like `test_grep "must point to a commit"` on the error message?

Patrick
Siddharth Shrimali· Mar 11, 2026, 17:41 UTC · re: Patrick Steinhardt · lore

[PATCH v2] t3200: replace hardcoded null OID with $ZERO_OID

To support the SHA-256 transition, replace the hardcoded 40-zero string in 'git branch --merged' with '$ZERO_OID'. The current 40-character string causes the test to fail prematurely in SHA-256 environments because Git identifies a "malformed object name" (due to the 40 vs 64 character mismatch) before it even validates the object type.

By using '$ZERO_OID', we ensure the hash length is always correct for the active algorithm. Additionally, use 'test_grep' to verify the "must point to a commit" error message, ensuring the test validates the object type logic rather than just string syntax.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
---
Changes in V2:
- Updated the test to capture stderr and use 'test_grep' to verify the 
  error message. This ensures the failure is due to the object type 
  check ("must point to a commit") rather than a hash length mismatch.
- Improved the commit message to add detail to the 40 vs 64 character
  mismatch and the "premature failure" in SHA-256.
 t/t3200-branch.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Show changes to t/t3200-branch.sh +2 −1
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index c58e505c43..e7829c2c4b 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -1494,7 +1494,8 @@ test_expect_success 'refuse --edit-description on unborn branch for now' '
 '
 
 test_expect_success '--merged catches invalid object names' '
-	test_must_fail git branch --merged 0000000000000000000000000000000000000000
+	test_must_fail git branch --merged $ZERO_OID 2>err &&
+	test_grep "must point to a commit" err
 '
 
 test_expect_success '--list during rebase' '
-- 
2.51.2
brian m. carlson· Mar 11, 2026, 21:17 UTC · re: Siddharth Shrimali · lore

Re: [PATCH v2] t3200: replace hardcoded null OID with $ZERO_OID

On 2026-03-11 at 17:41:20, Siddharth Shrimali wrote:
Show 12 quoted lines
> diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
> index c58e505c43..e7829c2c4b 100755
> --- a/t/t3200-branch.sh
> +++ b/t/t3200-branch.sh
> @@ -1494,7 +1494,8 @@ test_expect_success 'refuse --edit-description on unborn branch for now' '
>  '
>  
>  test_expect_success '--merged catches invalid object names' '
> -	test_must_fail git branch --merged 0000000000000000000000000000000000000000
> +	test_must_fail git branch --merged $ZERO_OID 2>err &&
> +	test_grep "must point to a commit" err
>  '

Yeah, this seems reasonable. It's failing, but for the wrong reasons, so checking the error message in addition to switching to `$ZERO_OID` seems like the right thing to do.

-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Patrick Steinhardt· Mar 12, 2026, 06:07 UTC · re: Siddharth Shrimali · lore

Re: [PATCH v2] t3200: replace hardcoded null OID with $ZERO_OID

On Wed, Mar 11, 2026 at 11:11:20PM +0530, Siddharth Shrimali wrote:
Show 12 quoted lines
> To support the SHA-256 transition, replace the hardcoded 40-zero string
> in 'git branch --merged' with '$ZERO_OID'. The current 40-character
> string causes the test to fail prematurely in SHA-256 environments
> because Git identifies a "malformed object name" (due to the 40 vs 64
> character mismatch) before it even validates the object type.
> 
> By using '$ZERO_OID', we ensure the hash length is always correct for
> the active algorithm. Additionally, use 'test_grep' to verify the
> "must point to a commit" error message, ensuring the test validates
> the object type logic rather than just string syntax.
> 
> Suggested-by: Patrick Steinhardt <ps@pks.im>

"Suggested-by" is a bit strong, as it indicates that I have suggested to work on this in the first place. "Helped-by" would have been a bit of a better fit.

No reason to reroll though, this patch looks good to me. Thanks!
Patrick

← back to recent threads