Repository navigation
fix: worktree add gives the files git worktree add writes, in bytes, modes, names and extended attributes - #6553
Merged
Conversation
janicduplessis
force-pushed
the
fix/6551-clone-equals-checkout
branch
from
November 27, 2026 04:31
9098571 to
b523d05
Compare
janicduplessis
force-pushed
the
fix/6551-clone-equals-checkout
branch
from
November 27, 2026 04:49
b523d05 to
23b78d1
Compare
janicduplessis
marked this pull request as ready for review
November 27, 2026 04:56
janicduplessis
enabled auto-merge (squash)
November 27, 2026 04:56
This was referenced Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On the clone path,
stim worktree addkeeps the source checkout's files wherever git reports them unchanged. #6551 lists the ways that differs fromgit worktree addthenstim worktree warm, each reproduced on main: an untracked.gitattributesapplied to the files git writes, an LF file kept where the commit asks for CRLF,attr.tree, a name spelled another way on disk, permission bits beyond the owner's execute bit, and extended attributes.This makes the tracked files of a cloned worktree equal what
git worktree addwrites, in bytes, permission bits, names and extended attributes. Three things a cloned file still keeps from the source checkout: its modification time, usually a BSD file flag such ashidden, and thecom.apple.provenanceattribute, which macOS sets andxattrcannot remove.Solution
One step between the clone and the refresh (
packages/stim-cli/src/workspace/clone-as-checkout.ts) walks the paths of the target commit and either makes a cloned file what a checkout writes or removes it, sogit reset --hardwrites it:ident,filter,working-tree-encoding, aneolother thanlf), a file whose size is not its blob's, a file spelled another way on disk in case or Unicode form, and a link or file standing where the commit has a folder.entry.cdoes) and extended attributes (xattr -c -s). When auchgflag stops a change, that flag is cleared from the paths of thatxattrbatch, or from the whole new worktree for achmodor a removal (ignored files included), and the step runs again.clonefile(2)as Stim calls it does not copy access control lists; the test checks that.core.autocrlf=truein any spelling git reads as true,core.eol=crlf,core.symlinks=false,attr.treeorGIT_ATTR_SOURCE, acore.attributesFileinside the worktree (read in the new worktree, whose configuration can differ from the source's), a git older than 2.41, which lacks--attr-source(checked before anything is registered; I could not run an older git, so this is untested), a path that names.gitor..(git refuses the commit), two tracked paths that differ only in case or Unicode form, and a tracked folder spelled another way on disk, which holds ignored files a removal would take.core.autocrlf=inputforces nothing.The refresh and the reset now run with
--attr-source=HEAD, so they read.gitattributesfrom the target commit and not from the working tree, where the clone put the source's files, untracked ones included. That replaces removing those files. They also run withcore.checkStat=defaultandcore.fsmonitor=false: underminimala clone matches its source's entry without being read, and the copied index's fsmonitor bitmap makes git skip files. Both are wrong-bytes cases on main. Blob sizes are read withGIT_NO_LAZY_FETCH=1, so a partial clone does not fetch blobs one at a time; a file whose blob is missing is left to the reset.Why this is enough for content: the refresh proves that a file cleans to its blob. Once the paths a checkout converts are left to git, the only clean conversion left is CRLF to LF, which changes the size, so a file of its blob's size that the refresh accepts holds the blob's bytes. This holds because the step, the refresh and the reset read the same attributes.
Every removal,
chmodandxattrcall reaches a path only through folders that are real folders in the new worktree, since a cloned link can lead into the source checkout. A test with an absolute link into the source checks that the source is untouched.Cost: files a filter,
ident, an encoding oreol=crlfapplies to are always written by git and share no disk blocks with the source, as on the plain path. Time, medians of 4 alternating runs after a discarded round, load average 10 to 24:git worktree add+ warmHEADHEAD~200node_modulesfoldersHEAD~50The step adds about 0.6 s on expo, half of it
xattr(0.74 s for 19,021 paths in sequence, 0.28 s four calls at a time, which is what ships), and about 0.2 s on stim by the minimums (6.76 s against 6.54 s; the stim medians are within noise). At the source's commit git wrote 0 of 19,020 files on expo and 1 of 3,811 on stim. The clone path is still slower than the plain path on a large checkout without dependency folders, as on main: the full refresh is unchanged.The docs state the equality again and list the plain-path cases; this supersedes #6552.
Test plan
worktree-add.integration.test.ts(macOS only, needsclonefile; PR CI does not run it, I ran it locally: 46 pass). The comparison helper now records, for every entry outside.git, the on-disk name, permission bits, extended attribute names and raw bytes or link target, and every existing case that compares withgit worktree add+ warm uses it. One new case per class runs both commands from the same source, compares the two worktrees andgit status, and checks that the source checkout is unchanged:.gitattributesasking for CRLF, at an older commit; LF where the commit asks for CRLF; a CRLF file left fromcore.autocrlf=true; a CRLF file clean undercore.autocrlf=input;identwith another blob's identifier; a smudge filter whose output the source does not hold; the output of a filter the commit no longer names; the output of a filter only an untracked.gitattributesnames;working-tree-encoding;core.checkStat=minimalwith an edit that kept size and time; an fsmonitor hook that hides an edit; a link created under another umask; an immutable file with an extended attribute and one with other permission bits;core.autocrlf=true, the same as a bare key,core.eol=crlf,core.symlinks=false,attr.tree,core.autocrlf=1included only for the new branch, acore.attributesFilenaming an untracked file;.git, added inside the source checkout: git refuses it and the source checkout, with a staged file, is unchanged.Each guard was removed in turn in a copy of the worktree and the suite rerun; every removal fails at least one case:
--attr-sourceon the reset.gitattributes; filter the commit no longer names--attr-sourceon the refresh.gitattributesnameseolattributeident/filter/ encoding attributescore.autocrlf=inputcore.autocrlf/core.eol,attr.treexattrcore.checkStat=default,core.fsmonitor=false,core.symlinks, link mode,chflagsretry,.gitpathReal tool calls exercised by these tests:
git ls-tree -r -l -z,git check-attr -z --stdin --source=HEAD,git config --type=bool-or-str,git --attr-source=HEAD update-index/reset,/usr/bin/xattr -c -s,/usr/bin/chflags -h nouchgand-R nouchg(Apple Git 2.54, macOS 27).Fixes #6551