Repository navigation
Fix vendored Gemfile line endings on CRLF (#1821) - #1822
Conversation
Assisted-by: Claude Code:claude-opus-5-5
Vendoring a gem into a Gemfile with CRLF line endings wrote the rewired `gem` line, or the appended managed block, with bare LF endings, so the committed Gemfile ended up with mixed line endings. Reverting a Gemfile that was re-checked-out in the other style also put the original line back in its old style, and a managed block whose endings changed was no longer found. New and appended lines now take the line ending of the line they replace (or the file's), a re-vendor recognises its managed fence in a CRLF file, and revert restores lines in the file's current style. Fixes #1821 Assisted-by: Claude Code:claude-opus-5-5
Adds an e2e case with a real bundler: vendoring over a CRLF Gemfile keeps every line CRLF, a frozen install accepts the result, and revert restores the Gemfile and lock byte for byte. Refs #1821 Assisted-by: Claude Code:claude-opus-5-5
A Gemfile vendored by an older release has an LF wired line beside a CRLF original in the ledger. Revert now keeps the original's ending unless the wired line's ending changed since vendor wrote it, so such files still come back byte for byte. A hand-restored original line also counts as reverted whatever its line ending. Refs #1821 Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 6cb35bc. Configure here.
|
Burn-down agent: labeled Ready for review at
Generated by Claude Code |
Final review briefWhat it does. Vendoring a gem into a CRLF Gemfile used to write the rewired Risk: low. Confined to the Gemfile writer/reverter in Look here
Verified. Read the full diff and the revert paths around it ( Changes I made. None. Open questions. None. Pre-existing, not changed here: a managed block whose closing fence is the file's last line with no trailing newline is recorded with a newline it doesn't have. Auto-merge is armed, so approving sends it straight to the merge queue. Generated by Claude Code |
Resolve the gem.rs import conflict with #1822, which writes Gemfile edits in the Gemfile's own line ending. The CRLF eject test now also checks that a CRLF Gemfile keeps CRLF on every line. Assisted-by: Claude Code:claude-opus-5-5
A hosted scan or get over a CRLF Gemfile (a Windows checkout, or core.autocrlf=true) wrote the Socket `source ... do` block with bare LF endings, so the committed Gemfile ended up with mixed line endings and churned under editors and .gitattributes normalization. The rewritten block now takes the ending of the gem line it replaces (the file's ending for an unterminated last line), and the block appended for a transitive gem takes the file's ending. This matches what vendored mode does since #1822. Fixes #1831 Assisted-by: Claude Code:claude-opus-5-5
LLM Description written by Claude Code:claude-opus-5-5
Fixes #1821
Summary
Vendoring a gem over a CRLF
Gemfilewrote the rewiredgemline (or the appended managed block) with bare LF endings, so the committed Gemfile ended up with mixed line endings. Now every line the vendored gem backend writes into the Gemfile, and every line it restores on revert, uses the file's own line endings.Root cause
The Gemfile writer in
crates/socket-patch-core/src/vendor/gem.rsalways built lines with LF, whatever the file used:plan_gemfile_edit'sRewritearm builtnew_linefrom scratch, so the\rof the line it replaced was lost. It survived only when a trailing option or comment happened to carry it.Appendarm's managed block was LF-only, andapply_gemfile_planadded an LF before it.RewireOurs(a re-vendor after a patch update) only recognised the managed fence when the fence lines had no\r. In a CRLF file it recorded the block as a plainRewrittenline.restore_gemfile_linerestored the recorded original with the ending it had at vendor time. AnAddedblock was only found byte for byte, so a Gemfile re-checked-out in the other style (core.autocrlf) reverted to mixed endings or was reported as drift. This is the related shape described at the end of Vendored gem mode writes the rewiredgemline of a CRLF Gemfile with an LF ending, leaving the Gemfile with mixed line endings #1821.Changes
line_endings::terminatorof the file.Addedblock is looked up as written, then in the file's current style. A hand-restored original counts as converged whatever its ending.revert_commented_gemfile_line_keeps_crlfasserted the old LF wired line (its comment called it "a separate line-ending gap"). It now expects the CRLF line.The npm, pypi and gem wrappers don't touch this code path, so they need no changes.
Tests (red → green)
mainvendor_keeps_a_crlf_gemfile_crlf(direct case)Appendmanaged block (transitive gem)vendor_keeps_a_crlf_gemfile_crlf(transitive case)plan_gemfile_edit_keeps_the_lines_crlfrevendor_crlf_managed_block_keeps_the_fencerevert_follows_a_recheckout_line_ending_changerestore_gemfile_line_endinge2e_vendor_gem_build::gem_vendor_keeps_a_crlf_gemfile_crlf...path: ".socket/vendor/gem/.../rack-3.2.7"\n)Commands run locally:
cargo fmt --all -- --check: okcargo clippy --workspace --all-features -- -D warnings: okcargo test -p socket-patch-core --all-features --lib -- vendor::gem: 153 passedcargo test -p socket-patch-cli --all-features --test e2e_vendor_gem_build --test e2e_redirect_gem_build -- --ignored: 36 + 10 passedcargo test --workspace --all-features --no-fail-fast: everything passed except 11 tests that can't pass in this sandbox and are unrelated to this diff:e2e_bun_lockbtests needpatches-api.socket.dev, which the sandbox proxy blocks.CI runs all of them.
/code-review high
The fixes for findings 1 (old-ledger CR on revert), 5 (convergence check ignored a CR change), 7 (double scan in the
Addedrevert) and 8 (a stricter CRLF check in the tests) are in 6cb35bc. Not fixed, and why:Appendto a file with no final newline. Both behave the same onmainand don't depend on line endings.line_endings::split_lines. That's the broader refactor tracked in Tracking: classify line endings in one place instead of five drifting rules #814 / Pick the line terminator for spliced lines through one line_endings::terminator #815. This PR keeps the fix local.Generated by Claude Code