Repository navigation
feat: clone with cow-clone on macOS, Linux and Windows instead of a compiled helper - #6550
Merged
Merged
Conversation
janicduplessis
force-pushed
the
feat/6548-cow-clone
branch
from
November 27, 2026 05:12
feb8cff to
6d4261b
Compare
…ompiled helper worktree warm, worktree add and the engine store clone through one layer that runs the prebuilt binary of cow-clone 0.1.0. The C helper, its compile step and the xcode-select probe are gone. worktree add tests a clone of one tracked file before git registers anything and names cow-clone's reason when it takes the plain path. It now clones on btrfs and XFS. On Windows git still checks out the tracked files, since it writes through the junctions a clone keeps, and the warm clones the ignored folders on ReFS and a Dev Drive, pointing links that led into the source checkout at the new worktree. Adds clone lanes on ext4, btrfs, XFS, NTFS and ReFS to the full suite. Closes #6548
janicduplessis
force-pushed
the
feat/6548-cow-clone
branch
from
November 27, 2026 05:24
6d4261b to
d0028f1
Compare
…not give new files' modes, and removes an immutable probe Under a set-group-ID folder or a default ACL a checkout writes other permission bits than the umask's, which the clone step set. On macOS a probe cloned from a file with the uchg flag could not be removed.
janicduplessis
marked this pull request as ready for review
November 27, 2026 07:03
janicduplessis
enabled auto-merge (squash)
November 27, 2026 07:04
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
Stim cloned directories with
stim-clonefile, a C helper compiled withxcrun clangon first use. It existed only on macOS and needed the Xcode Command Line Tools, sostim worktree addtook its one-pass clone path on macOS only andstim worktree warmcopied on Linux and Windows even on a file system that clones.This replaces the helper with
cow-clone, a package with prebuilt binaries for macOS, Linux and Windows (x64 and arm64):clonefile(2)on APFS,ioctl(FICLONE)file by file on btrfs and XFS, block cloning file by file on ReFS and a Dev Drive. A clone that is not possible reportsunsupported,cross-deviceorfailedwith an errno name.The dependency is
"cow-clone": "0.1.1"from npm, pinned likereal-size, withcow-clone@0.1.1inminimumReleaseAgeExclude.Solution
One clone layer,
packages/stim-cli/src/clone.ts:clonePairs(operation, pairs)runs thecow-clonebinary through Stim's executor, asprivate-size.tsrunsreal-size, so the child is declared for the operation and a cancel kills it. Pairs go on stdin, so no pair count reaches a command-line limit and the 256-pair batches are gone. It returns one result per pair.worktree warm,worktree addand the engine store'scloneTreeuse it. The C source, the compile step, thexcode-selectprobe and the macOS gate are removed.worktree addclones the checkoutworktree warmclones ignored entriescp -Rc)unsupportedcp -Rfs.cpas beforeworktree addon macOS and Linux:st_devcomparison (two btrfs subvolumes have different device numbers and clone into each other). Without it, every run on ext4 would register a worktree and a branch, fail at the first file, remove both and add them again.because the file system cannot clone (unsupported, ENOTSUP),because the source and the destination are on different volumes (cross-device, EXDEV), orbecause cloning failed (<message>: <path> (failed, <errno>)).cloneCheckoutthrows on the first failed result and the existing rollback removes the worktree.xattrandchflags(cow-clone copies no extended attribute or flag on Linux) andlchmod(a Linux link's mode is always 0777). Before setting modes it makes a folder and a file in the new worktree and takes the plain path when their modes are not the umask's, which is the case under a set-group-ID folder or a default ACL, where a checkout writes other bits.uchgflag.worktree warm:cp -R, or on Windowsfs.cpwith its link handling. The intermediatecp -Rcattempt is gone.node_moduleswould resolve into the source checkout (Windows: worktree warm cannot carry a pnpm node_modules (cp -R fails on its links) #6464 fixed this for the copy). After cloning an entry the warm walks it and points links that lead into the source checkout at the new worktree, with the code the copy uses. The walk does not enter a junction that Node reads as a directory (a volume mount point).On Windows
worktree adddoes not clone the checkout (maintainer-approved; #6554 tracks what it would need). Git for Windows takes a junction for a directory (compat/mingw.cfile_attr_to_st_mode;entry.cremove_subtreehas no mount-point check), and a clone keeps every junction's target. Agit reset --hardin a cloned tree can therefore delete or overwrite through a junction into the source checkout or wherever it leads, and a ReFS clone is stat-identical to its source for Git for Windows (no inode, creation time as change time), so a copied index hides an edit that kept size and modification time. So on Windows git checks out into an empty directory and the warm, which runs no git write, clones the ignored folders. The cost is the disk of the tracked files only. LLP 0029 records it under "On Windows only the warm clones".Result equality between the clone path and
git worktree addplus warm (macOS, Linux): the tracked files are what #6553 guarantees, now checked by itstree()comparison (bytes, modes, names, link targets) on btrfs and XFS too. A cloned ignored folder keeps each file's mode and modification time, where the warm's copy applies the umask and the current time, as on macOS before.Limits:
copyAppAside(cp -c -Rof an .app) is a separate copy and is not moved to the clone layer.worktree addnow runs its index checks and one probe before taking the plain path, where it returned at once.Maintainer decision:quote.Test plan
worktree-add.integration,worktree-warm.integration,api-worktree-warm.integration, the engine store tests,cli-parity,guide,guide-budget,test/e2e/storage-volumes.e2e.js, lint, typecheck, knip, format, and one run of the built CLI on a scratch repository.clone (<fs>)jobs inci.ymlunderfull, for ext4, btrfs, XFS, NTFS and ReFS. The btrfs and XFS loopback mounts and the ReFS virtual disk are set up as cow-clone's CI does, with the tests' temporary directory on them.worktree addassertsas a clone ofand the clone-only cases run;worktree warmassertscloned.unsupported.worktree addasserts the plain path with the Windows reason; on ReFS the warm tests assertclonedand that pnpm junctions resolve inside the new worktree.cow-clonebinary and read pairs from stdin; a failing clone is simulated with cow-clone's exit 1 and JSON; a new case covers across-deviceprobe, another a cloned folder with a link into the source checkout where the commit has a file.clone (refs)run of an earlier state of this branch that cloned the checkout there.test (node 22)andtest (node 24), which packstimand install it elsewhere inengine-store.e2e.js, pass with the registry dependency.Fixes #6548