Skip to content

fix(git): pin autocrlf=false on the uncached fallback clone and checkout - #3409

Merged
Daniel Meppiel (danielmeppiel) merged 8 commits into
microsoft:mainfrom
abhishekacharya200:fix/fallback-clone-autocrlf
Nov 11, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 8 commits into
microsoft:mainfrom
abhishekacharya200:fix/fallback-clone-autocrlf

Conversation

@abhishekacharya200

Copy link
Copy Markdown
Contributor

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_n by git_clone_env, so on a host with core.autocrlf=true it writes CRLF bytes for LF-committed files. The checkout runs under the downloader's isolated env (GIT_CONFIG_NOSYSTEM=1, empty GIT_CONFIG_GLOBAL), which has no such snapshot, compares that CRLF worktree against the LF index, and refuses:

error: Your local changes to the following files would be overwritten by checkout:
        f.txt

apm install then fails with Failed to checkout commit <sha> — but only once the locked SHA falls behind the branch head, which is why it looks intermittent. #2982 pinned core.autocrlf=false on the GitCache and bare-cache paths; the uncached fallback never got the pin.

Fix

Added git_autocrlf_pin_args() and applied it to both clone_git_worktree and checkout_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. -c outranks the frozen GIT_CONFIG_KEY_n snapshots, which is the same precedence argument #2971 relies on. Both call sites of checkout_git_worktree are 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 precedes clone / checkout.
  • test_locked_sha_checks_out_from_a_crlf_host — builds a two-commit repo, sets a host gitconfig with core.autocrlf=true for 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\n and the checkout raises the exact error above; with it the clone writes a\nb\nc\n and the checkout lands on the locked SHA.

Verification

  • tests/unit/cache/test_git_env.py: 103 passed, 2 failed — the two test_real_lookup_rejects_symlink_into_project cases, which fail identically on main here (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 as main in this environment (symlink privilege and Windows case-sensitivity), with the two new tests passing.
  • ruff check and ruff format --check clean on both touched files.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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=false argument 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"],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@sergio-sisternes-epam

Copy link
Copy Markdown
Collaborator

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.

@sergio-sisternes-epam Sergio Sisternes (sergio-sisternes-epam) added theme/portability triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented. labels Nov 3, 2026
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]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_now

Community fix pins core.autocrlf=false on the uncached worktree clone/checkout fallback, eliminating a Windows install failure when host git config rewrites line endings.

panel-mode=delta; personas=test-coverage-expert,apm-ceo (after a lean pass this run: supply-chain-security-expert, test-coverage-expert, apm-ceo)

cc Abhishek Acharya (@abhishekacharya200) Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

Panel signals converge across both passes. The lean pass found no supply-chain concerns (no new surface, hook and template guards intact, materialized bytes now equal committed bytes) and one recommended test-hygiene item; the delta pass confirms it landed cleanly. Mutation-break evidence is strong: removing the pin makes the real-Git clone write a\r\nb\r\nc\r\n and both regression tests fail, and removing it from checkout alone fails the argv test. The Windows Compatibility Gate ran and passed both regression tests on windows-latest at this head.

This is a bounded community contribution against the accepted scope record on #3368: the existing #2982 pin applied to the one remaining uncached fallback path, with GitCache and bare_clone_with_fallback untouched. Material delta since the contributor's last push: maintainer merge of current main, the test fold, and CHANGELOG credit (listed below). Required reviews from Daniel Meppiel (@danielmeppiel) and Sergio Sisternes (@sergio-sisternes-epam) remain pending.

Aligned with: portable by manifest -- a locked SHA now materializes identically regardless of host core.autocrlf; secure by default -- determinism improves with no new surface; multi-harness multi-host -- Windows CI exercises both clone and checkout pins; OSS community driven -- contributor credited inline in CHANGELOG after responsive fold iterations.

Growth signal. A community fix for a real Windows pain point, shipped with full CI proof, supports the "APM works on Windows" narrative and is worth calling out in release notes.

Panel summary

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 -c immediately 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 -- deleted git_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.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 8317b05 into microsoft:main Nov 11, 2026
2 checks passed
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 11, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage/recommended Automated advice completed; not human scope approval. type/bug Something does not work as documented.

Projects

None yet

4 participants