Repository navigation
Fix vendored gem bytes changed by its own .gitattributes (#2483) - #2488
Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
Conversation
Refs #2483. Assisted-by: Claude Code:claude-fable-5-2
Two of the three cases fail on main: a .gitattributes the gem ships whose rules convert a file of the vendored copy (*.rb text eol=lf over CRLF files) is kept as shipped, for a gem vendored as its own tree and as platform gems, so a clone of the commit holds other bytes than the ledger recorded. The third pins what repair does for a copy vendored before the fix. Refs #2483. Assisted-by: Claude Code:claude-fable-5-2
Git reads a .gitattributes at any depth, and one a gem ships inside its own tree wins over the uuid dir's `* -text` for the files below it. solargraph ships `*.rb text eol=lf` over files with CRLF line endings, so git committed other bytes than the vendor ledger recorded: every fresh clone failed vendor --check, vex left the gem out, and repair restored bytes git would not commit. A shipped .gitattributes whose rules turn a conversion on for a file of the copy (text in any form but -text, a filter or working-tree-encoding value, ident) is now emptied while the tree is staged and named by vendor_gem_gitattributes_neutralized, for a gem's own tree and for platform gems, the way a shipped .gitignore is. One that converts nothing and one the patch rewrites are kept. The rules are read as git reads them, which a test checks against git itself. Repair restores such a file as the ledger inventory records it, so a copy an earlier release vendored still verifies. An in-sync run over such a copy says so (vendor_gem_copy_gitattributes) and names what vendors it afresh. Refs #2483. Assisted-by: Claude Code:claude-fable-5-2
The CLI contract and the ecosystem guide describe the two new advisories: a .gitattributes the gem ships that is emptied in the vendored copy, and a copy an earlier release vendored that keeps one. Refs #2483. Assisted-by: Claude Code:claude-fable-5-2
Review of the reader for a gem-shipped .gitattributes found rules git applies that it took for harmless, so the file was kept: - a byte order mark before the first rule; - a quoted pattern with octal or other C escapes, or one that starts with `#`; - `!text=auto` and `-text=auto`, whose value git drops; - a pattern that differs only in letter case, which git matches under core.ignorecase (the default on macOS and Windows); - a POSIX class such as `[[:space:]]`, and a pattern the matcher refuses. Both now stand for every file. For platform gems the stub gemspec is written before the shipped rules are read, so a rule that names only it counts, and the in-sync advisory leaves out the files each platform's own patch rewrites rather than the lead patch's. Refs #2483. Assisted-by: Claude Code:claude-fable-5-2
|
bugbot run Generated by Claude Code |
PR SummaryLow Risk Overview Existing copies vendored before this behavior still get Reviewed by Cursor Bugbot for commit 2e96d45. Configure here. |
The reader of a gem-shipped .gitattributes dropped a leading byte order mark by itself, which the guard on production BOM handling (formats::text) refuses. It calls strip_bom now, which also drops exactly one mark, as git does. Refs #2483. Assisted-by: Claude Code:claude-fable-5-2
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2483
Summary
A gem can ship a
.gitattributesinside its own tree. Git reads one at any depth, and for the files below it its rules win over the* -text -filter -ident -working-tree-encodingthat vendored mode writes beside the gem. solargraph 0.62.2 ships*.rb text eol=lfover 30.rbfiles with CRLF line endings, so git committed them with LF. Every fresh clone then held other bytes than the vendor ledger recorded:vendor --checkfailed withvendor_inventory_mismatch,vexleft the gem out, and therepairthe message names restored bytes git would not commit.With this change:
.gitattributeswhose rules turn a conversion on for a file of the copy is emptied while the tree is staged, and the run warnsvendor_gem_gitattributes_neutralizedwith the files named. This is what a shipped.gitignorealready gets. It applies to a gem's own tree and to each platform gem's tree. One that converts nothing (merge=ours,eolwithouttext, a pattern that matches no file) and one the patch itself rewrites are kept byte for byte.repairrestores a shipped.gitattributesas the ledger inventory records it, so such a copy still verifies. Every in-sync vendored run over one warnsvendor_gem_copy_gitattributesand names a remedy that works: delete the copy directory and scan again, which vendors it afresh with the file emptied.CLI_CONTRACT.md(the gem row and the two new warning codes) anddocs/ecosystems.md.No install is touched: Bundler still loads the same patched files. The only change to a gem's content is an emptied
.gitattributes, which Ruby never reads.Root cause
crates/socket-patch-core/src/vendor/gem.rsemptied a shipped.gitignoreand nothing else, so no code read a shipped.gitattributes. The uuid dir's own.gitattributessits one level above the gem, where a deeper file overrides it.How a rule is judged
converts_a_filereads the file the way git does under the uuid dir's-text: for each file the last matching line that names an attribute decides it. A conversion istextin any form but-text(!texthands the file back tocore.autocrlf), afilterorworking-tree-encodingwith a value, orident.eolalone does nothing to a file that is not text, andbinaryis-text.Where git's answer depends on the checkout, or the pattern is one the matcher cannot read as git does, the rule counts as a conversion: letter case is ignored (git does that under
core.ignorecase), and a POSIX class or a pattern the matcher refuses stands for every file. That errs toward emptying a file and warning about it.Evidence
All in
crates/socket-patch-core/src/vendor/gem.rs:a_gitattributes_the_gem_ships_is_emptied_in_the_copygit commitandgit clonewithcore.autocrlfoff and on, and the clone holds the recorded bytes and passes the artifact check. Harmless, template and patch-owned files are kept; a re-run is in sync;repairreproduces the tree.a_gitattributes_a_prebuild_ships_is_emptied_in_the_copya_shipped_gitattributes_is_read_as_git_reads_itcore.autocrlfoff and on, and git changes a file's bytes exactly when the reader calls the rule a conversion.a_shipped_gitattributes_an_earlier_release_kept_is_reportedrestore_keeps_a_shipped_gitattributes_an_earlier_release_recordedrepairon an older copy.a_prebuilds_gitattributes_over_the_stub_gemspec_is_emptied,a_gitattributes_a_platform_patch_rewrites_is_not_reportedCommands run locally:
cargo clippy -p socket-patch-core --all-targets --all-features -- -D warningsreports 81 errors in test code on this toolchain, none in lines this PR adds; the same command fails onmain, and CI's clippy job does not lint test targets.Review
/code-review highreturned eight findings. Seven are fixed in the last commit, each with a test case: a byte order mark, quoted patterns with octal escapes or a leading#,!text=autoand-text=auto, letter case, POSIX classes and unreadable patterns, the stub gemspec being written after the rules were read (platform gems), and the advisory using the lead patch's file list for every platform tree.Not fixed: a
.gitattributesthat the patch itself rewrites, with rules that convert a file, is kept and not reported. Its bytes are the patch's and must stay as recorded, so it cannot be emptied; the alternative is to refuse the gem. A security patch that adds line-ending rules to a gem is not a case I could find, and a refusal path would add unwinding to both copy paths, so I left it out.Follow-ups
git addand does not depend on Bundler, and the core tests go through a real commit and clone; solargraph's dependency tree would add a large network install to every Bundler leg.vendor_inventory_mismatchmessage still namesrepair. In a clone of an older copy that does not help; the new advisory in the vendoring checkout is what names the working remedy.https://claude.ai/code/session_011f9aeP7hTMRyxriRbp2zJU
Generated by Claude Code