git_config: Support SHA-256 object IDs

Update ID_RE to match both 40-char (SHA-1) and 64-char (SHA-256) IDs as
part of Git 3.0 support.

Bug: 483758905
Change-Id: Ie5d9a2a5df4c6e7adda7f1d89f1bfb7724846057
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/600341
Reviewed-by: Brian Gan <brgan@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Gavin Mak
2026-06-23 22:47:32 +00:00
committed by gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 6586efe79a
commit c21a41c7cc
3 changed files with 28 additions and 4 deletions
+24
View File
@@ -244,3 +244,27 @@ def test_remote_save_with_push_url_without_projectname(
assert (
written_config.GetString("remote.origin.pushurl") == "ssh://example.com"
)
@pytest.mark.parametrize(
"rev, expected",
(
("a" * 40, True),
("0" * 40, True),
("f" * 40, True),
("a" * 64, True),
("0" * 64, True),
("f" * 64, True),
("a" * 39, False),
("a" * 41, True),
("a" * 63, True),
("a" * 65, False),
("g" * 40, False),
("g" * 64, False),
("refs/heads/master", False),
("refs/tags/v1.0", False),
),
)
def test_is_id(rev: str, expected: bool) -> None:
"""Test IsId identifies both SHA-1 and SHA-256 hashes."""
assert git_config.IsId(rev) == expected