Repository navigation
fix(git): check out out-of-cone link targets with Git's own checkout - #3673
Conversation
A link whose target a sparse checkout left out was read with `git --attr-source=HEAD cat-file --filters`, falling back to plain `cat-file --filters` when that call failed. cat-file reads no index, so in a sparse checkout the fallback silently skipped the target's .gitattributes and wrote e.g. an eol=crlf file with LF. That is the post-merge red on macOS x86_64 since 90e76bf: the path: transport link to shared/notes.crlf returned LF while the checked-out target was CRLF. Out-of-worktree targets are now written by `checkout-index` into a throwaway work tree from a throwaway full index (`read-tree HEAD`), in one batch per materialization. Attributes come from that index exactly as `git checkout` reads them, on every Git version, with no version-gated option and no silent fallback. In-worktree targets still read the bytes Git already wrote. The line-ending pins (#3599) still apply; the content_hash domain is unchanged. Regression: test_out_of_sparse_eol_target_keeps_checkout_bytes_without_attr_source emulates a Git that rejects --attr-source; it fails on main with the CI assertion and passes here. Also re-points two #3603 downloader tests at the persistent-checkout seam that #3640 changed underneath them. Refs #3457 apm-spec-waiver: Git checkout byte fidelity for link targets; no OpenAPM statement or hash-domain change. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Previously pinned sparse shards retain incorrect LF link bytes and fail cross-platform frozen verification, while the new scratch directory ignores configured temporary paths and can fail in restricted environments.
2 open issues
What changed in this PR
This follow-up to #3457 fixes how APM reads symlink targets outside a sparse checkout, using Git’s checkout machinery to preserve repository-defined line endings and consistent package hashes.
Changes:
- Replaces the
cat-file --filtersfallback with a batched checkout using a temporary index and work tree. - Adds a regression test for Git environments that reject
--attr-source. - Updates downloader test fixtures and records the follow-up in the changelog.
| File | Description |
|---|---|
tests/unit/deps/test_git_file_transport_links.py |
Verifies out-of-cone targets retain CRLF bytes without --attr-source. |
tests/integration/test_sparse_cone_symlink_repair.py |
Stubs the persistent-checkout boundary in two downloader tests. |
src/apm_cli/utils/git_sparse.py |
Loads target bytes before materialization and batches missing targets through Git checkout. |
CHANGELOG.md |
Adds this PR to the existing cross-platform symlink fix entry. |
Review effort: Balanced
A target that checkout-index leaves unwritten raised a bare FileNotFoundError; it now raises the 'did not check out ... as a regular file' diagnostic before any link is written. Panel follow-up (test-coverage-expert). Co-authored-by: Copilot App <[email protected]>
…TEMP_DIR Review follow-ups (Copilot): - The shard marker is versioned to apm.linkMaterialization=git-objects-checkout. A sparse shard pinned by the first Git-object materializer could hold an out-of-cone eol=crlf target with LF and would otherwise be served as is; it is now rematerialized on its next cache hit. Regression: test_cache_hit_rematerializes_shard_without_link_materialization[pre-checkout-marker] (fails if the marker value is reverted). - The throwaway checkout scratch directory uses get_apm_temp_dir(), like the downloader's own scratch space, so APM_TEMP_DIR / temp_dir keep working on hosts with a restricted system temp directory. Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Supply Chain Security Expert | 0 | 0 | 0 | Net security improvement; contained scratch index/tree, validated paths, silent attribute-dropping fallback removed. |
| Test Coverage Expert | 0 | 1 | 0 | Regression trap reproduces the CI failure on every lane; diagnostic-path gap folded. |
| Performance Expert | 0 | 3 | 0 | Two subprocesses per batch instead of one per file; read-tree only for out-of-cone targets; lazy fetch limited to named blobs. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 1 follow-up
- [Performance Expert] Consider one
_CheckoutBytesper install soread-tree HEADis built once when several packages have out-of-cone targets. -- It is O(repo files) per materialization today; bounded and only on the out-of-cone path, so track only if measured.
Recommendation
No findings remain open, CI is green at this head (including Windows Compatibility Gate and Windows Native Symlink Acceptance), and the regression trap ties the fix to the reported red. Recommend landing it; the macOS x86_64 lane on main confirms on the next post-merge run.
Full per-persona findings
Supply Chain Security Expert
No findings.
Test Coverage Expert
- [recommended] No test exercises the RuntimeError raised when checkout-index fails to produce a regular file at
src/apm_cli/utils/git_sparse.py
New user-facing diagnostic on a defensive path had no assertion.
Folded:tests/unit/utils/test_git_sparse.py::test_target_git_does_not_check_out_fails_instead_of_writing(also fixed the bare FileNotFoundError).
Performance Expert
- [recommended] Batch checkout is a net subprocess and round-trip win for multi-target packages.
- [recommended]
read-tree HEADbuilds a full-tree index at O(files) cost, only when out-of-cone targets exist. Suggested: hoist_CheckoutBytesper install if profiling shows it. - [recommended]
checkout-indexin partial clones fetches only the named blobs; no full-repo lazy-fetch risk.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
APM Review Panel:
|

Description
TL;DR
Fixes the post-merge red on Build & Validate (macOS x86_64) since 90e76bf (#3603). When a link's target sat outside a sparse checkout, APM read the target with
git --attr-source=HEAD cat-file --filters. If that call failed it fell back to plaincat-file --filters. That fallback never reads the index, so it skipped the target's.gitattributesand wrote aneol=crlffile with LF. Out-of-worktree targets are now written by Git's own checkout path (read-tree HEADinto a throwaway index, thencheckout-indexinto a throwaway work tree). The bytes equal whatgit checkoutwrites, on every Git version.Refs #3457
Problem (WHY)
tests/unit/deps/test_git_file_transport_links.py::test_sparse_file_fetch_returns_link_target_content[pkg/notes.crlf-shared/notes.crlf]fails withassert b'line one\nline two\n' == b'line one\r\nline two\r\n'on macos-15-intel. It has failed every main run from 90e76bf through 9e0a4a8; PR CI (Linux x64) passes.--attr-sourcecall to fail yields exactly that assertion.git cat-file --filterswithout--attr-sourcereturns LF in a sparse checkout even thoughgit check-attrreportseol: crlf, because cat-file does not load the index.--attr-source, Git 2.40+) and had a silent wrong-bytes fallback. Local Git 2.50/2.56 do not reproduce the failure, so the exact trigger on the runner's Git 2.55 is not pinned down. Any--attr-sourcefailure lands in the same wrong fallback.ubuntu-24.04-arm) red on the same runs is unrelated. It is theGLIBC_2.35 dist/apm-linux-arm64/_internal/libgcc_s.so.1packaging check.Approach (WHAT)
_CheckoutBytes.prime()collects every source of a materialization. Targets Git already wrote in the work tree are read as before (no subprocess).GIT_INDEX_FILE=<tmp> git read-tree HEAD, thengit --work-tree=<tmp> checkout-index --stdin -z.core.sparseCheckout=falseandindex.sparse=falsekeep the throwaway index full, so nothing can hide a path. Attributes are read from that index exactly asgit checkoutreads them.--attr-source, nocat-file --filters, no fallback. A path Git did not write as a regular file raises.content_hashdomain is unchanged; only the wrong LF bytes become the checkout bytes.Implementation (HOW)
src/apm_cli/utils/git_sparse.py:_CheckoutBytesrewritten (prime,_worktree_bytes,_check_out).materialize_tracked_symlinksprimes all sources before writing.tests/unit/deps/test_git_file_transport_links.py: new regressiontest_out_of_sparse_eol_target_keeps_checkout_bytes_without_attr_source. It emulates a Git that rejects--attr-source(exit 129), so the condition reproduces on every CI lane, Linux x64 included.tests/integration/test_sparse_cone_symlink_repair.py: two fix(git): materialize package links from Git objects on every host #3603 downloader tests built a bareobject.__new__downloader. Since fix(cache): clone SSH-declared non-GitHub deps over SSH in the persistent cache #3640 (_persistent_cache_remote), that downloader lacks transport attributes, so the cache path fell through to clone. They now stub the persistent-checkout seam directly. These tests run only in integration lanes, so main CI did not show it.Trade-offs
--attr-source.read-tree HEADwalks the whole tree once per materialization, but only when some target is outside the work tree. It uses the same machinery asgit checkouton every Git version. Rejected: keeping--attr-sourcewith a better fallback, because any fallback must reimplement attribute lookup.checkout-indexfor all out-of-cone targets, replacing onecat-fileper file.build-releasedispatch on this branch.build-release.ymlhas noworkflow_dispatch, and itsrepository_dispatchruns on the default branch only. The new regression test reproduces the failing condition deterministically in PR CI instead.Benefits
Issue and approved scope
Issue: Refs #3457
Human scope-approval comment: #3457 (comment) (extended scope: same bytes and content_hash as the POSIX result on every platform).
Does this PR complete the issue, or what remains? #3457 is closed by #3603; this repairs a platform-specific defect in that delivery.
Type of change
Testing
Local (macOS arm64, Git 2.56.0), one process at a time, no xdist:
pytest tests/unit/deps/test_git_file_transport_links.pysrc/apm_cli/utils/git_sparse.pyfrom mainassert b'line one\nline two\n' == b'line one\r\nline two\r\n'(the CI assertion)pytest tests/unit/utils/test_git_sparse.pypytest tests/unit/cache/test_git_cache_symlinks.py tests/unit/cache/test_git_text_eol_pin.py tests/unit/cache/test_git_symlink_config.pypytest tests/unit/cache/test_git_cache_sparse.py tests/unit/deps/test_github_downloader_phase3.py tests/test_gitlab_git_transport.pypytest tests/integration/test_sparse_cone_symlink_repair.pyAPM_BINARY_PATH=.venv/bin/apm pytest tests/integration/test_git_object_links_lifecycle.pySpec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedCo-authored-by: Copilot [email protected]