From fea697d62c1782a8fbf3bd26fa81fe2b15b64fef Mon Sep 17 00:00:00 2001 From: ethernet Date: Thu, 29 Oct 2026 16:10:06 -0400 Subject: [PATCH] fix(bundles): snapshot the revision bytes regardless of builder eol config (cherry picked from commit e5548831796d3223f37a1dc65b274fd07103b35e) --- scripts/bundles/payload.py | 7 ++++++- tests/scripts/test_bundle_payload.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/scripts/bundles/payload.py b/scripts/bundles/payload.py index f06ae764b0..38178c4701 100644 --- a/scripts/bundles/payload.py +++ b/scripts/bundles/payload.py @@ -38,8 +38,13 @@ def snapshot(repo: Path, ref: str, destination: Path, exclude: tuple[str, ...] = with tempfile.TemporaryDirectory(prefix="hermes-archive-") as temp: archive = Path(temp) / "source.tar" pathspecs = [f":(exclude){name}" for name in exclude] + # git archive applies checkout eol conversion. Git for Windows sets + # core.autocrlf=true system-wide, which would rewrite every text file + # lacking an eol attribute to CRLF: the payload must carry the + # revision's bytes (plus .gitattributes rules), not builder config. subprocess.run( - ["git", "archive", "--format=tar", "--output", str(archive), ref, "--", *pathspecs], + ["git", "-c", "core.autocrlf=false", "-c", "core.eol=lf", + "archive", "--format=tar", "--output", str(archive), ref, "--", *pathspecs], cwd=repo, check=True) if destination.exists(): shutil.rmtree(destination) diff --git a/tests/scripts/test_bundle_payload.py b/tests/scripts/test_bundle_payload.py index 7c6c215f48..1d3e0b3f32 100644 --- a/tests/scripts/test_bundle_payload.py +++ b/tests/scripts/test_bundle_payload.py @@ -22,6 +22,26 @@ def test_release_version_comes_from_the_release_identity_not_the_checkout(tmp_pa assert release_version(tmp_path, "v1.2.4") == "1.2.4" +def test_snapshot_carries_revision_bytes_regardless_of_builder_eol_config(tmp_path): + # Git for Windows ships core.autocrlf=true system-wide; set it on the + # fixture repo so every platform exercises the same builder config. + repo = tmp_path / "repo" + repo.mkdir() + git = ["git", "-c", "user.name=Fixture", "-c", "user.email=fixture@example.test"] + subprocess.run(["git", "init", "-q", str(repo)], check=True) + subprocess.run(["git", "config", "core.autocrlf", "true"], cwd=repo, check=True) + (repo / ".gitattributes").write_bytes(b"*.ps1 text eol=crlf\n") + (repo / "plain.json").write_bytes(b'{\n"a": 1\n}\n') + (repo / "script.ps1").write_bytes(b"one\ntwo\n") + subprocess.run([*git, "add", "."], cwd=repo, check=True, capture_output=True) + subprocess.run([*git, "commit", "-qm", "fixture"], cwd=repo, check=True) + out = tmp_path / "out" + snapshot(repo, "HEAD", out) + assert (out / "plain.json").read_bytes() == b'{\n"a": 1\n}\n' + # Committed eol attributes still apply: only builder config is ignored. + assert (out / "script.ps1").read_bytes() == b"one\r\ntwo\r\n" + + def test_wrapper_rejects_unresolved_template_fields(tmp_path, monkeypatch): from scripts.build import launchers