Skip to content

Commit 4d6ae91

Browse files
codexByron
authored andcommitted
fix(gix): defer compatibility object formats to Git
GixPython opens repositories with `extensions.compatObjectFormat`, but native translation and object-write compatibility have not been validated. The local Git build reports that compatibility hash support requires Rust, so its failed translation probe does not establish a defect in GixPython's object mappings. Reject this capability in the shared native repository adapter before reads or mutations. Git retains responsibility for repositories using the extension, and the coverage report identifies the conservative guard as `GIX-19`. The new SHA-1 and SHA-256 regression cases failed before this guard. They verify CLI dispatch for reads and writes without depending on Git's optional compatibility support, and forbid any native write attempt. All 36 focused backend tests and Ruff lint/format checks pass.
1 parent 162e2b8 commit 4d6ae91

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎git/_backend.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ def _repository(command: Any, env: Dict[str, Any], *, query_config: bool = False
8383
["core.fsmonitor=false", "gc.auto=0", "maintenance.auto=false", "core.hooksPath=" + os.devnull]
8484
)
8585
repo = gix.open_opts(path, options)
86-
if repo.config_snapshot().string("extensions.refStorage") == b"reftable":
86+
snapshot = repo.config_snapshot()
87+
if snapshot.string("extensions.refStorage") == b"reftable":
8788
raise _Unsupported("reftable (GIX-1)")
89+
if snapshot.string("extensions.compatObjectFormat") is not None:
90+
raise _Unsupported("compatibility object format (GIX-19)")
8891
if effective.get("GIT_WORK_TREE"):
8992
workdir = effective["GIT_WORK_TREE"]
9093
if not os.path.isabs(workdir):

‎test/test_gix_backend.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ def test_unknown_command_and_storage_environment_use_cli(repo):
110110
assert cli.call_count == 3
111111

112112

113+
def test_compatibility_object_format_uses_cli_before_writing(repo):
114+
repo.git.config("core.repositoryFormatVersion", "1")
115+
repo.git.config("extensions.compatObjectFormat", "sha256" if repo.object_format == "sha1" else "sha1")
116+
# Check dispatch without requiring Git's optional compatibility-hash support.
117+
with patch.object(_backend, "_write", side_effect=AssertionError("unexpected native mutation")):
118+
with patch.object(Git, "execute", return_value="fallback") as cli:
119+
assert repo.git._call_process_safe("rev_parse", "--show-object-format") == "fallback"
120+
assert (
121+
repo.git._call_process_safe("hash_object", "-t", "blob", "-w", "--stdin", istream=BytesIO(b"content"))
122+
== "fallback"
123+
)
124+
assert cli.call_count == 2
125+
126+
113127
def test_native_command_queries_match_cli(repo, monkeypatch):
114128
Path(repo.working_dir, "file").write_bytes(b"content")
115129
repo.index.add(["file"])

0 commit comments

Comments
 (0)