Repository navigation
fix(git): pin autocrlf=false on the uncached fallback clone and checkout - #3409
Conversation
The fallback working-tree clone freezes the host's effective git config into GIT_CONFIG_KEY_n, so a host with core.autocrlf=true wrote CRLF bytes while the follow-up `git checkout <locked sha>` ran without that snapshot and saw every text file as modified, failing the install after the producer gained a commit. Pin core.autocrlf=false on both commands, as the GitCache and bare-cache paths already do (microsoft#2982), so the materialized bytes are the committed bytes and the two commands agree. Closes microsoft#3368
There was a problem hiding this comment.
🟡 Changes recommended
The fixture commits retain CRLF bytes on Windows when the host’s core.autocrlf is false or unset, causing the LF assertions and Windows compatibility gate to fail.
1 open issue
What changed in this PR
Fixes #3368 by making the uncached Git fallback clone and checkout use consistent line-ending settings, preventing locked-commit installs from failing on hosts with core.autocrlf=true.
Changes:
- Adds a shared
core.autocrlf=falseargument helper to both working-tree operations. - Adds argument checks and a real-Git regression test for checking out an older commit.
- Documents the fallback fix in the changelog.
| File | Description |
|---|---|
tests/unit/cache/test_git_env.py |
Adds pin assertions and a CRLF-host regression scenario. |
src/apm_cli/utils/git_env.py |
Pins autocrlf off for working-tree clone and checkout. |
CHANGELOG.md |
Adds an Unreleased entry describing the install fix. |
Review effort: Balanced
|
|
||
| def _commit(message: str) -> None: | ||
| subprocess.run( | ||
| [git, "-C", str(src), "-c", "user.name=t", "-c", "user.email=t@t", "add", "f.txt"], |
There was a problem hiding this comment.
Fixed in 8c332e5, slightly differently from the suggestion. The fixture now writes LF bytes with write_bytes, so the commits hold LF whatever the host's autocrlf setting is, without pinning anything on git add. I could not run this on Windows, so the Windows gate is the real check.
write_text produces CRLF on Windows, and with core.autocrlf off those bytes would reach the fixture commits and fail the LF assertions.
|
Thank you for the fix and the detailed regression evidence. The linked #2971 issue is status/accepted, so this recommendation is ready for human review, not merge approval. The specific fallback-path report #3368 remains open and unaccepted; maintainers should confirm whether it is covered by the accepted scope. Current review requests include Daniel Meppiel (@danielmeppiel) and Sergio Sisternes (@sergio-sisternes-epam). Generated by autopilot-pr-triage-worker. This comment is AI-generated and may contain errors. |
…tocrlf # Conflicts: # CHANGELOG.md
Build the fixture remote with Path.as_uri() so the real-Git regression uses a well-formed file URL on every OS, and assert "-c" immediately precedes the checkout autocrlf pin, matching the clone assertion (a second "-c" from the no-hooks pin made the old membership check weak). Addresses panel test-coverage-expert follow-up on PR microsoft#3409. Co-authored-by: Copilot <[email protected]>
Per changelog.instructions.md each entry ends with the PR number and credits external contributors inline; the entry cited issue microsoft#3368. Co-authored-by: Copilot <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Test Coverage Expert | 0 | 0 | 0 | Prior lean findings (Path.as_uri() fixture URL, checkout argv adjacency) are folded; regression-trap coverage is complete. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Recommendation
All panel findings are resolved, mutation-break evidence holds, and CI is green including the Windows gate. Recommend the pending CODEOWNERS reviewers complete their pass. No follow-ups to track.
Folded in this run
- (copilot) Fixture files written as LF bytes so commits hold LF regardless of host autocrlf -- resolved in 8c332e5 (by the author).
- (panel) Real-Git regression builds the fixture remote with
Path.as_uri()and asserts-cimmediately precedes the checkout autocrlf pin -- resolved in 13e0b41. - (panel) CHANGELOG entry ends with the PR number and credits the contributor inline per changelog.instructions.md -- resolved in 3b68842.
Copilot signals reviewed
tests/unit/cache/test_git_env.py:1668-- LEGIT: fixture text could carry host CRLF into commits; fixed by writing LF bytes (resolved in 8c332e5).
Regression-trap evidence (mutation-break gate)
tests/unit/cache/test_git_env.py::TestUncachedFallbackLineEndings::test_locked_sha_checks_out_from_a_crlf_host-- deletedgit_autocrlf_pin_args()return value; test FAILED as expected; guard restored.tests/unit/cache/test_git_env.py::TestUncachedFallbackLineEndings::test_clone_and_checkout_pin_autocrlf_false-- deleted*git_autocrlf_pin_args()from the checkout argv; test FAILED as expected; guard restored.
Lint contract
uv run --extra dev ruff check src/ tests/ and
uv run --extra dev ruff format --check src/ tests/ both silent, plus pylint R0801, lint-auth-signals.sh and lint-architecture-boundaries.sh clean after merging current main.
CI
All checks green on 3b68842 (CI run 42861974096 incl. Windows Compatibility Gate, Build & Test shards, Lifecycle Smoke, Lint; the gate check, Spec conformance, CodeQL, NOTICE Drift Check) (after 0 CI fix iteration(s)). Fork workflow runs for this push were authorized by a maintainer.
Mergeability status
| PR | head SHA | CEO stance | iters | folds | defers | Copilot rounds | CI | mergeable | mergeStateStatus | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| #3409 | 3b68842 |
ship_now | 1 | 3 | 0 | 2 | green | MERGEABLE | BLOCKED | pending required review |
Convergence
1 outer iteration(s); 2 Copilot round(s). Final panel stance: ship_now.
Ready for maintainer review.
Full per-persona findings
Test Coverage Expert
No findings.
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-merge-worker. This comment is AI-generated and may contain errors.
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
8317b05
into
microsoft:main
Resolve git_env.py conflict: keep both the core.symlinks pin helpers (this PR) and git_autocrlf_pin_args (#3409); checkout_git_worktree now applies both pins and keeps symlink-capability classification. Co-authored-by: Copilot App <[email protected]>

Fixes #3368.
Problem
The uncached fallback materializes a full working-tree clone and then checks out the locked SHA. The clone inherits the host's effective git config frozen into
GIT_CONFIG_KEY_nbygit_clone_env, so on a host withcore.autocrlf=trueit writes CRLF bytes for LF-committed files. The checkout runs under the downloader's isolated env (GIT_CONFIG_NOSYSTEM=1, emptyGIT_CONFIG_GLOBAL), which has no such snapshot, compares that CRLF worktree against the LF index, and refuses:apm installthen fails withFailed to checkout commit <sha>— but only once the locked SHA falls behind the branch head, which is why it looks intermittent.#2982pinnedcore.autocrlf=falseon the GitCache and bare-cache paths; the uncached fallback never got the pin.Fix
Added
git_autocrlf_pin_args()and applied it to bothclone_git_worktreeandcheckout_git_worktree, so the working tree the fallback writes and the checkout that follows agree on line-ending handling and the materialized bytes are the committed LF bytes regardless of host config.-coutranks the frozenGIT_CONFIG_KEY_nsnapshots, which is the same precedence argument#2971relies on. Both call sites ofcheckout_git_worktreeare the fallback commit path, so the blast radius is that path.Tests
TestUncachedFallbackLineEndings:test_clone_and_checkout_pin_autocrlf_false— asserts the pin is present, adjacent to-c, and precedesclone/checkout.test_locked_sha_checks_out_from_a_crlf_host— builds a two-commit repo, sets a host gitconfig withcore.autocrlf=truefor the clone snapshot, clones, then checks out the older SHA with the isolated env.Red/green on this Windows host: without the change the clone writes
a\r\nb\r\nc\r\nand the checkout raises the exact error above; with it the clone writesa\nb\nc\nand the checkout lands on the locked SHA.Verification
tests/unit/cache/test_git_env.py: 103 passed, 2 failed — the twotest_real_lookup_rejects_symlink_into_projectcases, which fail identically onmainhere (no Windows symlink privilege).tests/unit/cache tests/unit/deps/test_clone_connect_retry.py tests/integration/test_git_hook_env_isolation.py: 10 failures, byte-for-byte the same set asmainin this environment (symlink privilege and Windows case-sensitivity), with the two new tests passing.ruff checkandruff format --checkclean on both touched files.