Skip to content
These docs are for the next devvm, which isn’t released yet. The docs for the current release are at devvm.dev.
.git protection

.git protection

This page explains what devvm locks in a project’s git folder, when it locks and checks the locks again, and what the locks can’t stop. .git protection covers what still works, turning protection on or off, VMs that were strict, and what isn’t covered.

On macOS devvm locks with the user-immutable flag (chflags uchg), which even root in the VM can’t clear. A read-only mount wouldn’t hold, because root in the VM can unmount it.

On Linux devvm makes the same paths read-only in the user and mount namespace it runs the VM’s QEMU in (on Linux hosts), so the VM, which reaches the folder only through QEMU, can’t change them.

Each check reads each repo’s .git once, the folder’s own and those nested in it, finding its git folders, submodules, what it would lock, what the locked files hand over and what points git elsewhere, and then locks, unlocks, watches and reports from what it found. The host’s locker does the locking: the flag on macOS, and on Linux nothing at the check itself, because the VM’s next start makes the paths read-only. A Linux host whose kernel refuses devvm the namespace locks nothing, and devvm watches .git there instead.

What’s locked

devvm locks these paths, of the folder’s own repo and of each nested repo it protects:

  • .git/hooks and .git/config. A repo without a hooks folder gets an empty one, locked, so the VM can’t make one.
  • The same paths for each submodule devvm finds, submodules of submodules included. Those are the git folders under .git/modules, and those in the working tree, which are sub/.git or the folder that a sub/.git file points to. devvm finds the submodules from the index, which it reads with core.fsmonitor off. It takes a folder for a git folder only when it has what git looks for in one, which is a HEAD, and objects and refs in the folder or in the folder its commondir names, as git’s own test has it. The VM can point a sub/.git file at any folder in the project, such as src, and locking that folder’s hooks and config would lock your own files, so devvm locks and creates nothing in a folder that fails the check and reports it instead.
  • .git/config.worktree, when extensions.worktreeConfig is on. devvm creates it empty if it’s missing.
  • What linked worktrees elsewhere on your machine read from here, which is .git/worktrees/<name>/commondir and config.worktree.
  • The project folder’s .git file, if the project folder is itself a linked worktree. The repo it points to is outside the VM.

When devvm locks

devvm records a new VM’s mode in its state before its backend makes the VM, so the mode is never unset: on with locks (macOS, and Linux where the kernel lets devvm use a user namespace), off when you pass --no-git-protect or on hosts without locks, and clone for a --clone VM, which mounts no .git. devvm locks once the backend has made the VM, and again on each launch that finds the VM stopped and on devvm stop, so nothing in the VM can race the locks. A VM whose creation stopped before its first locks, or that devvm adopt moved to this folder, is locked on its next launch as a new VM is, without reports. A running VM keeps the locks it had, and devvm stop or the next launch that finds the VM stopped, such as devvm restart, sets new ones. devvm git-protect on a running VM saves the mode in the VM’s state (the git section’s next).

Each time it locks, devvm records in the VM’s state what it locked and found: the identity of .git (its device and inode, and its birth time where the file system keeps one), every git folder it locked besides .git (those under .git/modules and the submodules’ in the working tree, in one list), and a hash of what the locked files hand over to the project folder. The next check compares with those, so it reports what changed since. When only the device of .git differs, and it’s at the same path with no link on it and has the same inode and birth time, it’s the .git that devvm locked, on a disk that macOS numbered anew at boot, as for one VM per folder. The check then records its identity as it is now and doesn’t report a replaced .git. The same places first check .git under the mode the VM ran with, so a .git that the VM replaced meanwhile is still named (git_replaced), and then set the new mode, which locks .git as it is then.

A new VM that’s interrupted before its first shell is deleted, and devvm takes its locks off. When devvm rm deletes a VM, devvm also takes its locks off. It unlocks what it would lock now and every git folder the VM’s state records locking, so a submodule whose entry the VM dropped from the index since is unlocked too.

Symlinks

devvm never locks or creates anything through a symlink, because the VM could plant one under .git so that devvm would lock a file elsewhere. devvm reports a path that is a symlink, or is under one, instead of locking it (git_not_locked). devvm also checks each lock again once it’s set. If the path moved in the meantime, devvm unlocks it where it landed and reports it (git_lock_raced).

On each launch

Every launch of an existing VM, every export of its agents’ history, and devvm stop check .git again. devvm reports each of these once:

  • A .git that was replaced since devvm locked it (git_replaced). devvm then does nothing else, so check the new .git, and look for the old one, renamed.
  • A repo that appeared in the folder after the VM was made (git_appeared), which devvm then locks, and a nested repo that appeared since the last check (git_nested_appeared).
  • A nested repo devvm protected that’s gone (git_nested_gone).
  • A submodule git folder that appeared, in the working tree or under .git/modules (git_embedded_new), which devvm then locks. devvm compares with the git folders it recorded last time, so devvm git-protect on after a VM was made without protection names none: it locks .git as it is then, as trusted.
  • Hooks in a hooks folder that wasn’t locked, because it wasn’t there to lock or belongs to a new submodule (git_hooks_unlocked).

devvm also reports these, the first two on every launch and the last two when they change:

  • A commondir (git_commondir).
  • Linked worktrees whose commondir leads elsewhere (git_worktree_stray).
  • Includes and hook links into the project folder (git_include_inside, git_hook_link_inside), which not covered describes.
  • Submodules whose git folder, in the working tree, isn’t a git folder (git_gitdir_not_git), which devvm doesn’t lock.

Nested repos

devvm protects each git repo nested in the project folder as it protects the folder’s own: it locks the same paths of each, checks each at every launch, pins each on Linux and watches each where the host can’t lock (nested repos).

The walk

devvm finds the nested repos by walking the project folder when it creates the VM, at each launch that finds the VM stopped and at devvm stop, at devvm git-protect on a stopped VM, and when devvm clone off mounts the folder again. It’s one walk that also finds the set-id files on a Linux host, which only the start runs (the checks on owners), and a launch into a running VM never walks. The walk stays on the project folder’s file system, follows no symlink and never enters a .git folder, so it never finds the repos of .git/modules, which are the folder’s own repo’s to protect. It takes a folder for a repo when the folder has anything named .git, a folder, a file, which a linked worktree or a repo with its git folder elsewhere has, a symlink or anything else, whether git takes it for a repo’s now or not, because the VM can make it one at any time. On macOS, whose file systems fold case, .GIT is .git to git, so the walk takes any case of the name there. It looks for repos at most four folders below the project folder, and not in node_modules, vendor, .venv, __pycache__ or .terraform, which package managers and build tools fill with what they fetch, so on macOS, where there are no set-id files to look for, the walk doesn’t enter those folders at all. On Linux it walks them for set-id files anyway, and counts the .git it sees there and below four folders (git_nested_skipped). It counts the folders it doesn’t enter because they’re on another file system (git_nested_devices). It keeps the first 100 repos it finds, in the walk’s order, and counts the rest, keeping the names of the first ten of those (git_nested_past_bound).

The walk also names each folder up to four folders down that git could take for a bare repo (git_nested_bare), one shaped like a git folder by git’s own test: a HEAD, and objects and refs, files or folders, in the folder or in the folder its commondir names. A git folder that a repo’s scan locks, or that a nested repo’s .git file names, isn’t named. devvm doctor reads safe.bareRepository from git’s global and system config, the files that GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM name included, which it reads by name because devvm’s host git ignores every GIT_* variable, and it gives a tip unless the setting is explicit (doctor_git_bare).

A check takes the repos the walk found, the ones the VM’s state records first. A recorded repo stays protected, whether the walk found it or not, while its folder is a real folder of the project with anything at its .git, because the VM can make a .git that the walk or git’s own test passes over while git still takes it: objects and refs renamed with a commondir that leads to a git folder of its own, a .GIT, or a .git it can’t read, which devvm can’t lock and names (git_not_locked). A check without a walk, such as devvm rm and the start that pins, takes the repos the state records. A launch into a running VM checks the folder’s own repo alone and keeps the nested repos’ records as they are, because it locks nothing and the VM can change them until it stops, so it never pays for scanning them, and the check of a running VM’s pins goes by those records without scanning them. devvm scans each repo as it scans the folder’s own, eight at once, because each scan runs a few host git commands: a check of a stopped VM with 50 nested repos, the walk and the locks included, takes under a second on an M3 Max.

Two bounds

Each repo has two bounds. Its own top folder is where its .git is, where .git/modules and a relative core.hooksPath are read from, and where its submodules’ folders are. The project folder, which the VM mounts, is what the VM can write, so it’s the bound for everything else: devvm locks only a real path in the project folder, through no symlink, an include or a hooks path leads inside when it leads into the project folder, and a submodule’s git folder outside the project folder is one devvm can’t lock (git_gitdir_outside). A nested repo’s hooks path that leads into a sibling repo is inside, because the VM can write it.

A nested repo is left to another repo only when that repo’s scan locks its git folder whole: the git folder is that repo’s .git, one under its .git/modules that reads its config from itself, with no commondir that leads elsewhere, or one of its linked worktrees under .git/worktrees whose commondir leads back. Anything else below a .git, such as a .git/evil the VM made for a src/.git file to name, isn’t locked by anything, so the repo is scanned on its own, and named as one that appeared and as one devvm doesn’t protect. A submodule in the working tree is scanned as a repo of its own as well as its parent’s submodule, because the index that names it is the VM’s to write: a gitlink the VM adds, whose .git file names a nested repo’s git folder, would otherwise hide that repo’s own submodules and worktrees behind a scan from the wrong folder. Locking a path twice changes nothing, and unlocking goes by path once. A nested repo whose .git is a file is locked as the folder’s own is when it’s a linked worktree, by its .git file. When the git folder that file names is in the project folder and no repo’s scan locks it, devvm names the repo as one it doesn’t protect, and when it’s outside the project folder, it names the repo as one whose git folder it can’t lock (git_nested_gitdir_outside), as it does a submodule’s.

A scan follows each submodule git folder once, by its resolved path, and one check’s scans follow at most 1,000 of them across every repo, so gitlinks that the VM points back at a git folder already followed, or through a symlinked folder at the repo itself, or many repos full of submodules, can’t make a check run git without end. A repo whose scan stopped there is named at every check (git_scan_bounded).

What’s recorded

The VM’s state records each protected nested repo in the git section’s made.repos, by its folder relative to the project folder, with the same fields as the folder’s own repo: .git’s identity, the git folders locked besides .git, and a hash of what its locked files hand over. made.nested is set once the VM protects its nested repos, which a new VM does, and so do devvm git-protect on and the watch on a Linux host that can’t lock. A nested repo without a record is scanned for the first time, which records it as a new VM’s repo is recorded, without reporting its git folders. At a check of a VM whose made.nested is set, devvm also reports it as one that appeared, such as a repo the VM cloned while it ran, naming each key of its config that runs a program or reads another config (core.fsmonitor, core.hooksPath, core.sshCommand, core.pager, filters, aliases that start with !, includes and the like) and each hook that isn’t one of git’s samples (git_nested_appeared_runs, else git_nested_appeared), because it locks the repo as it is. A recorded repo with nothing at its .git, or whose folder isn’t a real folder of the project any more, is reported (git_nested_gone), and a recorded repo whose .git is another one is reported as the folder’s own is (git_replaced). The record of a repo devvm stops protecting, as it’s gone or another repo’s protection covers it, moves to made.left, so devvm rm and devvm git-protect off take its locks off with the rest, and name one that isn’t in the folder any more (git_locks_left), whose locks only chflags can take off.

A VM an earlier devvm made has no made.nested, so it protects only the folder’s own repo. The first check of it that finds nested repos names them once (git_nested_protectable, recorded as nested_noticed), and devvm git-protect on protects them. The nested repos that a check finds and the protection doesn’t cover are recorded in nested, with nested_more for how many more the walk counted, and named (git_nested_unprotected, git_nested_past_bound): on a host that locks, all of them when devvm creates the VM and at devvm git-protect on, and at a check of a stopped VM those it hadn’t recorded, and how many are past the bound at every check, because the VM could keep their count and change which they are. On a Linux host that can’t lock, each launch names those the last walk recorded, after git_unprotected, which a folder without a .git of its own gets too when it has nested repos, and devvm git-protect off quiets both.

A VM that devvm 0.1.0 or 0.1.1-rc.1 made strict has strict as its mode, and its repos’ configs have the diff.ignoreSubmodules = all that strict set. devvm reads that mode as on: it locks, pins and keeps the VM’s paths as it does for on, and devvm git-protect, its --json and devvm ls show on. The first check that finds the VM stopped, at a launch, devvm stop, devvm clone on or the undo of a devvm clone off, runs as an on VM’s does, and then converts the VM. Under the host’s lock of .git protection, it takes the value all out of the .git/config of each repo that the VM’s state recorded protecting before that check, the folder’s own and the nested ones, with git config --unset-all diff.ignoreSubmodules '^all$', and leaves any other value. It acts only on a repo whose .git has the identity the state recorded (git_id), so a .git the VM replaced, which the check names and locks nothing in, and a VM with no record, as after devvm adopt, keep their setting, which devvm names once when it’s all (git_strict_unknown). It reads the config through devvm’s reader of files a VM can write first, so a FIFO or a symlink there is never read, and after git writes it, it checks that the config is still a regular file in that .git, else it names the path (git_lock_raced). On a host that watches as well as locks, it leaves a config whose sum isn’t the one the check just recorded, and puts the new sum of each config it changed into the watch’s, so the next check doesn’t name devvm’s own change. It locks each config again even after an interrupt, on a context the interrupt doesn’t cancel, and an interrupt records nothing, so the next check goes again. Then it records on in mode, and in next when an earlier devvm saved strict there for the VM’s next stop, and warns once (git_strict_converted), unless next is off. A config that git can’t change keeps the setting, and devvm names it (git_strict_left). devvm git-protect on and off and the unlock at devvm rm take the setting out the same way, without the warning (the packages names the code).

Two VMs, one repo

A nested repo with a VM of its own is protected by two VMs, the parent folder’s and its own. On macOS both set the same flag on the same files, so when one VM’s protection comes off, at devvm rm or devvm git-protect off, devvm leaves locked every path that another VM’s protection still covers, which is a git folder that VM recorded locking, of its own repo or of a nested one, and names that VM (git_kept_locked). The inventory reads every VM’s state for that. It fails closed: a state it can’t read keeps locked every path in the folder whose hash names that state’s folder, and when it can’t read the VMs’ folder at all, everything stays locked, each named with the state to fix (git_kept_unread). Locking a VM’s repos and recording them, and unlocking another’s, take the host’s lock of .git protection first, before any VM’s own lock, so one VM’s unlock never runs between another’s locks and their record. Taking a strict VM’s diff.ignoreSubmodules out never unlocks a config another VM keeps locked, because that VM, running, could race the unlocked file, so the setting stays there, and devvm names the file, that VM and how to take it out by hand (git_strict_kept). The repo goes in the state’s strict_left, as does one whose config changed since the check, and each later check that finds the VM stopped tries again, until none is left. When git can’t change a config, devvm locks it again all the same. On Linux each VM’s pins are in its own QEMU’s namespace, and the watch locks nothing, so neither needs this.

On Linux hosts

Linux hosts have no immutable flag that a user can set, so devvm makes what it locks read-only where the VM sees it, in the VM’s QEMU process, which serves the project folder to the guest over 9p. Lima starts QEMU through devvm’s wrapper (devvm _qemu exec), and a start of a VM that’s on gives the wrapper what to pin in a file of its own, run/git-pins.json in the VM’s folder, written private, which DEVVM_QEMU_PINS names, because a VM with many nested repos has more pins than one environment variable holds. The wrapper reads the file through no symlink, and it pins, for the folder’s own repo and each nested repo the VM’s state records protecting, .git and each git folder it locks besides, which stay writable, and every path of what’s locked that’s there, which become read-only. They’re the paths the check before the start found and checked, each a real path in the project folder with no symlink, and the check made a missing hooks folder and config.worktree first, so each has a place to pin. devvm then starts devvm _qemu pinned in a user and mount namespace of its own, as you, with only CAP_SYS_ADMIN, and only in that namespace. It makes the namespace’s mounts private, so nothing it mounts reaches this machine’s, and pins each path in order, a folder before what’s under it. It opens each path once, by the kernel, below the project folder and through no symlink (openat2 with RESOLVE_BENEATH and RESOLVE_NO_SYMLINKS), refuses anything but a file or a folder, and refuses a file with another name, or a folder holding a regular file with one, because a bind covers one name and macOS’s flag covers the file itself (git_pin_linked, which the check before the start names first). Then it binds what it opened over itself with open_tree, mount_setattr and move_mount, which act on that file descriptor and never on a path again, because mount(2) would follow a symlink that the VM planted. A path it can’t pin, or folders it can’t watch, stop the start (qemu_pins_failed), so the VM never runs unlocked. Then it starts devvm _qemu drop as its child, which clears every capability it has, ambient, permitted, effective and inheritable, sets no-new-privileges and replaces itself with QEMU, which runs as you with no capability at all. Its bounding set stays whole, which only CAP_SETPCAP could change, and gives nothing with no new privileges. QEMU is killed if devvm _qemu pinned ends (PR_SET_PDEATHSIG), which runs as long as QEMU does, keeping the pins, so QEMU never outlives what keeps them. devvm _qemu exec waits for both and passes them the signals Lima sends, and if it’s killed, QEMU is killed with it, an unclean stop for the guest, as if its power went.

The guest reaches the project folder only through QEMU, so a write to a pinned path gets EROFS, and a rename or a removal of one, .git itself included, gets EBUSY, because it’s a mount point. A mount can’t be undone from the guest, and QEMU, which has no capability, can’t undo it either. A bind mount over a folder is a file system of its own to the guest, so a rename between the working tree and .git gets EXDEV. The namespace ends with QEMU, so nothing persists once the VM stops, and nothing changes on this machine’s side, where git works as usual.

A git command on this machine that writes .git/config writes a new file and renames it over the old one, and the new file isn’t pinned in the namespace. devvm _qemu pinned watches each pinned path’s folder with inotify, a few folders for each repo, so the 100 nested repos devvm protects at most stay far below the kernel’s limit of watches, and it pins again whatever lost its pin as soon as one changes, and every two seconds besides. A pin can race the rename, because the kernel takes the old file’s mount away before the new file has its name, so the pin may open the old file and find it gone by the time it binds (move_mount’s ENOENT). devvm _qemu pinned then opens the path again and pins what the rename left, up to 50 times, so on a busy host it never mistakes a rename for a lost pin. Until then the guest can write the new file, rename it away and put its own in its place, which then gets the pin, open it for writing, a handle the pin doesn’t take back, or give it another name. So each pin it makes again, and each it can’t, it records in the VM’s run folder (run/git-pins.jsonl), a JSON object a line, after a first line that says it keeps the pins from then on, which it writes before QEMU starts and without which QEMU doesn’t start (qemu_pins_failed). The next check of the stopped VM, at devvm stop or at the next launch, names them before anything else, one line for each path and kind however often it happened (git_pin_again, git_pin_linked_run, git_pin_lost), then removes the file. An event devvm _qemu pinned can’t add goes to Lima’s log, with a warning, and to the file as a mark if it still takes one. A record the check can’t trust is named (git_pins_unrecorded): one it can’t read, which it keeps, a line that isn’t an event, a mark, or a file that doesn’t start with a run’s first line, as when it was removed while the VM ran and made again. The check also sums what a lock covers, as the watch does, and names what changed since the VM’s last check, so a file the guest changed in that window, or through a handle it kept, is named too. macOS’s flag has no window, because a locked config can’t be replaced on the host either.

Each launch of a running VM that’s on, and devvm stop before it stops it, read QEMU’s mounts (/proc/<pid>/mountinfo, QEMU’s pid from Lima’s qemu.pid) and name what of .git and of the git folders it locked QEMU lacks (git_pins_missing): .git and each git folder that isn’t a mount point of its own, and each read-only path that QEMU doesn’t see read-only,, such as all of them for a VM that limactl start started. A VM that’s on whose .git has nothing devvm can pin, such as one whose .git is a symlink, is named at its start (git_pins_none).

devvm checks that the host can pin by doing it: it pins a file in a namespace of its own, with its own binary, and checks that writing it fails (devvm _qemu probe). Lima’s read-only-paths feature is native where that works and none elsewhere, and a VM that’s on needs it to start, so where the kernel stops letting devvm in, the start is refused (backend_lacks) and never goes on unlocked. Where the probe fails, new VMs get off, devvm watches .git instead, and devvm doctor says why: Ubuntu’s kernel.apparmor_restrict_unprivileged_userns, kernel.unprivileged_userns_clone or user.max_user_namespaces at 0, or the probe’s own error. devvm offers no AppArmor profile for Ubuntu, because a profile for a binary in a folder you can write gives any program running as you what Ubuntu’s restriction holds back (Ubuntu). devvm makes the namespace itself rather than through unshare(1), so the program that asks for it is devvm.

devvm doesn’t pin .git/commondir against the VM making one, which would point git on this machine at another config: a file has to be there to be pinned, and devvm puts no file in .git that git doesn’t, so it reports a commondir at each check, as on macOS.

The watch

Where the host can’t pin, devvm locks nothing, and every VM that mounts its folder gets off as its mode. devvm watches the paths it would lock instead, and names what changed after the fact (git_changed), which Linux hosts tells the user how to check.

devvm hashes the same paths that what’s locked lists, found in the same way, and .git/commondir, there or not, the files that include.path and includeIf.*.path lead to in the project folder, and the folder that core.hooksPath names in it. For a hooks folder, it hashes each entry below it, except git’s .sample files, which git never runs, starting with the entries at its top that have a hook’s name (githooks(5)), which git runs, and then the rest. It hashes a regular file’s contents with SHA-256, opened with O_NOFOLLOW and O_NONBLOCK and checked to be a regular file once it’s open, as devvm reads every file a VM can write. It records a symlink by where it points, and a path under a symlink, such as .git/config when .git is a symlink, by that fact. When the link resolves to a file or folder inside the project folder, it adds that file’s hash, or a hash of that folder’s hashes, and it never follows a link out of the project folder. Anything else, such as a FIFO, is recorded by its type. The work is bounded: past 1,000 entries, a hooks folder is recorded by that count, its inode and its change time, a file larger than 16 MiB by its size, inode and change time, and a watch keeps at most 2,000 hashes of the folder’s own repo and 200 of each nested repo, so a folder with many nested repos never overflows it. The VM can’t set a change time back over 9p, so a change that keeps a large file’s size is still named. Each check names, in its own warning (git_watch_blind), every path that is a symlink or under one, past a bound, or past the 2,000, because the watch can’t see every change there.

The same checks first run what a lock’s check reports, without locking (protect with watching): a .git replaced since the last check (git_replaced), after which the next check compares with the new one, a commondir (git_commondir), linked worktrees whose commondir leads elsewhere, a repo or submodule git folder that appeared, a submodule’s folder that isn’t a git folder (git_gitdir_not_git), which the watch doesn’t hash as one and where devvm creates nothing, and includes, hook links and core.hooksPath into the project folder. They don’t report hooks in folders that aren’t locked, because nothing is, and the watch names their changes. .git’s identity and the git folders and delegations found are recorded in the git section’s made, as a lock’s check records them. A VM whose made isn’t set yet reports as a new VM does.

The watch reads .git only when the VM is stopped, so it misses a change the VM made and undid before it stopped. It’s a report, not a security boundary.

The hashes go in the VM’s state, in the git section’s watched, by each path relative to the project folder, with scanned set once a check has recorded them. devvm records them when it creates the VM, and checks them again on each launch that finds the VM stopped and on devvm stop, the same places that check the locks on macOS. Each check names every path whose hash changed, appeared or went since the last one, in one warning, at most ten of them and then how many more (git_changed_more), and then records the new hashes. A launch of a running VM checks nothing. A VM whose state has no watched yet, such as one an older devvm made, or one that devvm adopt gave this folder, records its first hashes without naming anything.

Each launch also warns that the VM can change .git (git_unprotected), unless the folder has no .git or the VM is a --clone VM. The warning stops once the user has chosen the mode, which devvm records as the git section’s chosen: devvm git-protect off sets it, and so does --no-git-protect when devvm creates the VM.

What a lock can’t stop

The VM can rename .git and put a new one in its place, add .git/commondir to point git at another config, or do the same with a linked worktree’s folder in .git/worktrees. When devvm creates the VM, and on each launch, it reports a commondir that’s there, linked worktrees whose commondir leads somewhere else, and paths it couldn’t lock because they’re symlinks. devvm reads git’s own small files, a .git file, a commondir and a linked worktree’s gitdir, through a symbolic link as git does, but only when each is a regular file of at most 16 MiB, opened without blocking, so a FIFO the VM leaves there can’t hang devvm. devvm doesn’t repair anything, so check what it names before you run git in the folder. When you don’t trust what runs in the VM, use --clone, which mounts no .git at all.

The VM writes .git/index, because it has to in order to commit, so it can also add a submodule with its own config, which git status on the host reads. A submodule’s core.fsmonitor therefore also runs on the host. devvm names a new submodule at the next check that finds the VM stopped, but git on the host reads it before that. No setting in the locked config keeps git on the host out of it. The VM writes .gitmodules, whose ignore line for a submodule beats diff.ignoreSubmodules, and git falls back to the index’s and HEAD’s copies of the file when the working tree has none. git add -A, -u and . enter a submodule whatever any setting says, and git diff-index, git diff-files and git describe --dirty enter one that .gitmodules doesn’t name. A setting for a submodule’s name in .git/config holds only for the name the VM chooses in .gitmodules. Only --clone keeps the VM’s code away from git on the host.

devvm’s own git commands on the host run no program that a repo’s config or .git names, a submodule’s included, whatever the VM wrote there. devvm runs each one with these settings, given as GIT_CONFIG_COUNT pairs, which git takes over any config file:

  • core.fsmonitor=false, core.hooksPath=/dev/null and core.alternateRefsCommand=true, so git runs no fsmonitor, no hook from a hooks folder and no command for an alternate object store’s refs.
  • hook.EVENT.enabled=false for every event githooks(5) lists, and hook.NAME.enabled=false for each hook the repo’s config names, so git 2.54 and newer run no hook that a config defines.
  • filter.NAME.clean, smudge and process emptied, and filter.NAME.required=false, for each filter driver the repo’s config names, so git hashes files without running a filter and doesn’t fail on a required one.
  • protocol.allow=never and protocol.ssh.allow=always, so git reaches nothing but ssh, not a path, file://, ext::, git:// or http. A repo’s config could still allow one protocol by its own key, such as protocol.ext.allow=always, which git takes over protocol.allow, so devvm also sets GIT_ALLOW_PROTOCOL=ssh, which git takes over every protocol setting.
  • maintenance.auto=false and gc.auto=0, so a fetch starts no maintenance or gc.
  • log.showSignature=false, and gpg.program, gpg.ssh.program and gpg.x509.program all false, so no log or reflog command runs the signing program a repo’s config names to check a signed commit.
  • advice.graftFileDeprecated=false, so git doesn’t warn about the grafts file that the next paragraph sets.

Its ssh is false, which reaches nothing, in place of a repo’s core.sshCommand (GIT_SSH_COMMAND=false, with GIT_SSH_VARIANT=ssh over a repo’s ssh.variant), unless the command is a --clone VM’s fetch, and it fetches nothing lazily (GIT_NO_LAZY_FETCH=1), so a repo that says it’s a partial clone can’t make git rev-list or git status connect anywhere for an object it lacks. It sees a repo’s real objects and history, not what its replace refs (GIT_NO_REPLACE_OBJECTS=1) or a grafts file (GIT_GRAFT_FILE=/dev/null) would show, so what it walks, packs or looks up is what the repo holds.

It runs without any GIT_* variable of devvm’s own environment, such as GIT_DIR, GIT_WORK_TREE or GIT_CONFIG_GLOBAL, so a hook or a rebase you run devvm from can’t point it at another repo or config, and it reads your global config from its usual place. It keeps only the absolute folders of PATH, because git looks programs up, ssh among them, from the repo’s folder, and it runs with GIT_TERMINAL_PROMPT=0. Its git status adds --no-optional-locks, so it writes no index, and --ignore-submodules=all, so it never enters a submodule, whose own config could name filters of its own.

A --clone VM’s fetch adds --no-recurse-submodules and an empty --refmap=, so it updates only the branches its own refspecs name, never those of a remote that the repo’s config names after the clone’s address. It runs git with devvm’s own GIT_SSH_COMMAND, which ignores the host, port and options git passes to ssh. It always connects to the VM’s own address and port, the host’s loopback port that the VM’s backend gives, as the VM’s user with the VM’s own key, and it reads no ssh config (-F none). It checks the host keys devvm pinned for the VM’s current start, with the VM’s own known hosts file and no global one, -o HostKeyAlias= the VM’s name and -o StrictHostKeyChecking=yes, and it runs with -o BatchMode=yes, -o ForwardAgent=no and -o ClearAllForwardings=yes. In the VM it runs only git-receive-pack or git-upload-pack, whichever git asks for, on the clone’s path, and it refuses any other command. So no url.*.insteadOf or remote URL in the repo’s config can send the fetch to another host or to another path, and it forwards neither your agent nor any port. devvm’s own copy into the VM uses no git transport at all (the copy into a clone VM). A repo’s core.sshCommand doesn’t apply, because devvm sets GIT_SSH_COMMAND, and its diff.external, textconv drivers and pager never run, because none of devvm’s commands shows a diff or writes to a terminal.

Before a --clone VM is made, and again before its copy, devvm checks that what git reads in the folder is the repo’s own, so the copy can’t take another repo into the VM. The folder’s .git is a folder with no commondir, or it’s the .git file of a linked worktree whose link git made both ways. That .git file names <repo>/.git/worktrees/<name>, that entry’s gitdir file names the folder’s .git back, and its commondir leads to that <repo>/.git, which has no commondir of its own. Or it’s the .git file of a submodule, whose git dir is below its parent repo’s: the parent is the nearest folder above with a .git, itself its own repo by these same checks, and the .git file names a folder modules/<name> below the parent’s git dir, a nested submodule’s below its parent submodule’s, where it resolves, so no symbolic link leads it out of that git dir, with no commondir, and whose config’s one core.worktree, in a file that includes no other, leads back to the folder. Neither the git dir nor the common dir has objects/info/alternates, or a packed-refs or reftable that’s a symlink, or anything in objects or refs that’s a symlink, such as a pack folder or a loose object’s folder that leads to another repo’s objects. Then git rev-parse --absolute-git-dir --git-common-dir must name the same two folders. The common dir has no info/grafts, because the copy carries each commit with its own parents. A partial clone’s copy carries every object the repo has that its tips reach, and leaves the rest to its promisor remote (below). A worktree’s copy sends its branch, that branch’s upstream when the upstream is one ref, the repo’s default branch, the remote-tracking branches and the tags, so the repo’s other local branches stay on this machine. A branch.<name>.merge that’s a pattern, such as refs/heads/*, would make the upstream every branch, so devvm then copies no upstream.

devvm finds the hook and filter names to turn off with one git config before each command, so a VM that keeps swapping the repo’s config could show that git config one config and the command another. Every hook event is turned off by its name as well, which covers config hooks on git that has the event setting, so the gap is a filter that the swap hides, which git status could then run on a file whose stat changed. It needs a VM that writes the repo’s .git, so on macOS, where .git/config is locked, it needs a repo devvm doesn’t lock, such as a nested repo past the walk’s bounds (nested repos).

Two things a repo’s config can still do, and neither runs code. An include.path can make devvm’s git config --get user.name read your name and email from another file in git’s config format, which then go into the VM as its git identity. A config file or included file that is a FIFO makes git, and so devvm, wait until you press Ctrl+C.

The copy into a clone VM

devvm copies a repo into a --clone VM without git push, because git receive-pack in the VM refuses repos that users have: a shallow clone’s push fails with shallow update not allowed, and a SHA-256 repo’s push into a SHA-1 repo fails with the receiving end does not support this repository's hash algorithm. The copy is a snapshot instead, made by devvm’s own git on this machine and applied by plain git in the VM, through the backend’s command channel, which also carries the VM’s agent. The structure test keeps git push out of devvm’s code, so the copy can’t drift back to a second transport (where the code is).

The copy takes three commands in the VM:

  1. One script makes every repo the clone has. For each repo, it gets the repo’s path and the host repo’s object format. A repo that’s copied already is printed as landed and left alone. That’s a repo whose .git/devvm-seeded says done, or one with no such file whose HEAD resolves, which an older devvm’s push made. A repo that isn’t there yet is made with git init, with --object-format=sha256 only for a SHA-256 repo, because git before 2.29 doesn’t know the option. One that’s there, from a copy that didn’t finish, isn’t made again, because git 2.54’s git init in a reftable repo drops its extensions.refStorage setting and breaks the repo. It takes receive.denyCurrentBranch=updateInstead and receive.shallowUpdate=true, for your own git push devvm BRANCH later, and .git/devvm-seeded says pending. A git init that fails for a SHA-256 repo prints the VM’s git --version, and devvm stops before it sends anything (clone_vm_git_old), showing the version only when it reads as git prints one.
  2. A tar of small files goes into .git/devvm-seed in the VM’s repo, never /tmp, which is in memory on some systems. It holds the refs to set, each an object and its name, the symbolic refs, such as refs/remotes/origin/HEAD, each with the ref it points to, what to check out, a branch’s name or, for a detached HEAD, its commit, and the host repo’s shallow file, read from the repo’s common dir as a regular file only, never through a link, so a link there can’t send another file. It also holds the working tree (the working tree): the repo’s index, normalised, the paths to check out from it, and the working copies of the tracked files that differ from it. And it holds the repo’s state (the state in the copy): an operation in progress, the stash, and the info files.
  3. The pack of the objects those refs and a detached HEAD reach, with the index’s blobs and the commits the state names, from git pack-objects --revs --stdout, goes straight into git index-pack --stdin in the VM, which checks every object it writes, so devvm doesn’t run git fsck as well. pack-objects --revs walks with the repo’s commit-graph and bitmaps when it has them, so a VM that once wrote this repo’s .git, through a mount before .git protection, could have forged one to put objects in the pack that the refs don’t reach, which are this repo’s own objects, never another repo’s or a file’s. Neither end holds the whole pack in memory, and when the command in the VM ends early, devvm closes the pipe so pack-objects stops. The same command then copies the shallow file and sets the refs with git update-ref --stdin, and each symbolic ref with git symbolic-ref, unless a ref of that name is there already. It points HEAD at the branch, with git symbolic-ref, or detaches it at the commit, with git update-ref --no-deref, and puts the host’s index in place, with the working copies sent where the VM has no file. It does that only when HEAD was unborn, is on the branch the copy just set, or is detached at the commit or at one an earlier try set, so a VM that checked out a branch of its own keeps it, and one that moved its detached HEAD keeps it too. A HEAD left where the VM put it, away from this machine’s, is named (clone_kept_head), which covers a repo here switched between a branch and a detached HEAD since the copy that didn’t finish. It checks out the listed paths with git checkout-index -u -z --stdin, or every path with -a when it kept the VM’s HEAD, without -f, so it writes only the files that aren’t there. It removes .git/devvm-seed and writes done to .git/devvm-seeded last.

The refs are those of refs/heads, refs/tags, refs/notes, refs/replace and refs/remotes, read in one git for-each-ref, less the remote-tracking branches of each remote any of whose URLs, as git resolves them (git remote get-url --all), reaches a devvm VM by its full name or its shorter one, in any URL form or case, and less a branch that’s no commit, which git won’t set. A linked worktree’s copy takes the smaller set above, and its upstream and default branch pass the same rules, so neither can be another VM’s remote-tracking branch or a ref outside the namespaces, such as refs/stash through branch.<name>.remote=.. A symbolic ref goes only when the ref it points to goes. Nothing outside those namespaces goes, such as refs/original, refs/prefetch or refs/stash. The pack carries what a push of the same refs would: the commits, trees, blobs and tags they reach, and nothing unreachable. devvm’s git runs pack-objects with replace refs and grafts off, so each commit goes with its own parents, and a repo with a grafts file is refused before the VM is made (clone_grafts).

A partial clone, one whose config names a promisor remote (remote.<name>.promisor, or an older git’s extensions.partialClone), lacks objects its remote has, and pack-objects --revs would want them in its walk, which fails with GIT_NO_LAZY_FETCH=1, missing trees and all. Its pack is made from a list instead: git rev-list --objects --missing=allow-promisor --stdin of the tips the repo has, which git cat-file --batch-check picks, as a sparse checkout’s index can name blobs the repo never fetched, piped into git pack-objects --stdout through a pipe of their own, whose ends devvm closes once both have started, so when pack-objects ends early, rev-list’s next write fails and it ends too. devvm holds back the pack’s last 64 bytes, more than its trailing hash, until the pack ends, then waits for rev-list, and when rev-list failed, it ends the pack there, so the VM’s git index-pack gets a pack cut short and refuses it, and the copy fails with rev-list’s error, never with a pack that lacks objects and says nothing. The VM reads the pack with git index-pack --promisor, so it’s a promisor pack, and the settings give the VM’s clone the promisor remote, with its filter, and promisor as git reads it, so yes, 1 or no value at all goes as true. Its git then fetches a missing object from that remote when a command needs one. That fetch goes through the VM’s own network policy, with no credential of this machine’s, as the remote’s URL has none, so a private remote needs the VM’s own login.

devvm reads each ref’s object type with git cat-file --batch-check after listing the refs, because git for-each-ref’s %(objecttype) fails on a ref whose object the repo lacks, such as a partial clone’s tag of a blob it never fetched. Such a ref stays out of the copy, named (clone_partial_refs_kept), and in a repo that isn’t partial, it fails the copy, as that repo is broken (clone_ref_no_object). devvm reads the promisor remotes as git here reads them, includes followed, each remote.<name>.promisor on its own, so one value git can’t read as a boolean drops only its own remote, and a remote’s last value wins. It names those whose settings don’t go, as their URL is of a kind that stays or reaches a devvm VM (clone_partial_promisor_kept), and copies the repo anyway, as the VM’s clone works with what it has. For each promisor remote that goes, in name order, it compares the remote’s host and port with the VM’s tier: on the none tier it names the host with how to reach it (clone_partial_blocked_none), on the allowlist tier one the allowlist doesn’t allow (clone_partial_blocked), and on the internet tier one a deny rule blocks or an address that isn’t public, which that tier never reaches (clone_partial_denied). A host it names on a port other than 80 or 443, such as an ssh remote’s 22, is named as the rule that allows that port alone, such as github.com:22, which devvm network allow takes. When devvm can’t read the VM’s policies, it judges nothing against them, and names only the none tier’s hosts and private addresses. A name that resolves to a private address isn’t reached either, which devvm can’t tell before the VM looks it up. It also names a remote on this machine, a file:// URL or a path, which the VM can’t reach (clone_partial_unreachable). A scp-like URL’s host is read as git reads it, up to its first colon, past a bracketed one such as [::1], and a URL whose port isn’t a number names no host.

devvm’s own fetch from the VM keeps GIT_NO_LAZY_FETCH=1, so a VM can’t make this machine’s git fetch anything, and the VM’s git upload-pack fetches no missing object to send it, as git 2.45.1 and newer turn that off. So when the VM’s work names an object its partial clone lacks, such as a blob restored from an old commit, the fetch fails, and devvm says to have git in the VM read the work’s objects first, which fetches them, then fetch again (clone_fetch_partial). devvm doesn’t turn lazy fetching on in the VM’s upload-pack.

A copy that fails before its end leaves pending, so the next launch copies again in full. git index-pack of a pack the repo has, git symbolic-ref and the checkout are all safe to run again. The refs follow one rule, so a copy never moves a branch the VM moved: before it sets a ref, the script records its name and the commit in .git/devvm-seeded-refs, and it then sets a ref that’s missing, at the host’s commit already, or at a commit an earlier try recorded. It leaves any other as it is and prints it, and devvm names those branches (clone_kept_branches). After the checkout, git update-index --refresh and git diff-files -z list the files whose content isn’t the index’s. devvm leaves out the paths that the copy itself sent or deleted, adds the VM’s own files at those paths, and names what’s left as the files the VM wrote (clone_kept_files). What the VM prints is untrusted, so devvm reads at most 1 MiB of it, shows at most 20 names, each cut to 200 bytes and quoted, and acts on none of it. devvm rm and devvm clone off check a clone whose copy didn’t finish as any other, so the VM’s work there is offered for fetching too.

An older devvm made each VM’s repo with plain git init, so with SHA-1 object names. In such a VM whose copy failed, a SHA-256 repo’s empty repo has the wrong object format, which the script prints. devvm then asks whether to make that repo again (clone_repo_format). The repo has no commit, but it may hold the VM’s own hooks or config, so only you can say, and no flag answers the question. Without a terminal devvm refuses, saying what to run (clone_repo_format_kept). On yes, the script deletes that .git only when it still has no HEAD and no ref, and makes it again.

Submodules in the copy

Once a repo’s copy is in, and before devvm records it as copied, each of its initialised submodules gets a clone of its own in the VM, nested ones after their parent, so a copy that didn’t finish copies the rest on the next launch. devvm takes the list from this machine’s repo alone, never from the VM or .gitmodules: a submodule is one whose name the repo’s own config gives a URL (submodule.<name>.url, as git submodule init sets it), whose git dir is modules/<name> in the repo’s common dir, whose core.worktree there leads to a folder below the repo where its index has a submodule (a gitlink), and which is its own repo there by the checks above, at a path a terminal can show. An uninitialised submodule has no such git dir, so its folder stays as the parent’s copy left it, empty, and so does one initialised after the copy, or in a VM made before devvm copied submodules. One that’s initialised but fails a check stays on this machine, named (clone_submodule_kept), and so does each of a linked worktree’s, whose submodules’ git dirs are in the common dir, which devvm doesn’t read for them. Each submodule’s copy is a repo’s, checked again just before, as a folder of repos’ repo is: still its own repo’s top, with no grafts and a HEAD, and no other VM mounting it. One that fails that, or any step of its copy, such as a VM that refuses it, is named (clone_submodule_kept), with its own submodules left out, and the repo’s copy goes on without it and is recorded as done, so it’s tried again only on a launch before that, when the repo’s copy didn’t finish. Its record is taken out only when nothing of it can be in the VM: it failed before this launch recorded it, with no record from an earlier launch. Otherwise its record stays, not copied, so whatever of it the VM has is still fetched from and checked by devvm rm, which checks a repo that wasn’t copied when the VM has it, and devvm clone fetch adds its remote. Its remote is chosen as a repo’s is, recorded with its path in the VM’s state before its copy (submodules, in its repo’s entry, nested ones in theirs). The submodule is then made in the VM, in the folder the parent’s checkout left empty, as a repo with a .git folder of its own, which git submodule status reads as a submodule’s, and copied, so its HEAD is detached at the commit the submodule has checked out here, with its refs, its changes, its state and its settings; then its remote added in its repo here, which is its git dir’s config, and the copy recorded. The parent’s settings give it submodule.<name>.url and active (the settings in the copy), so git in the VM takes it for initialised.

devvm clone fetch, devvm rm’s and devvm clone off’s check and the remotes’ removal go over each submodule the state records, each named by its path in the folder, as a folder of repos’ repos are, so a submodule you remove or deinitialise here later isn’t passed over: as one another VM mounts, it’s named as one devvm can’t check (clone_submodule_unchecked), and devvm rm and devvm clone off ask before the VM goes, while devvm clone fetch names it and leaves it. devvm clone add of a recorded submodule says it’s the clone’s already. An older devvm ignores the record, so its devvm rm wouldn’t check a submodule, which matters only after a downgrade. A folder of repos’ walk passes over a repo that’s a submodule of a repo in the folder, among that repo’s initialised submodules, which its clone has.

A submodule’s own folder isn’t a repo that --clone takes by itself: its .git file leads into the parent’s .git/modules, or for a parent that’s a linked worktree, into the main repo’s .git, and a VM that mounts the folder of either could swap that git dir under host git, which the check for a VM mounting the repo, looking at the folder and a worktree’s common dir, wouldn’t see. So devvm --clone there, and a folder of repos’ copy of one, refuses it as a .git that points into another repo (clone_git_elsewhere). Only as a submodule of a --clone repo is it copied, and every check of it as one, before its copy, before a fetch and in the clone check, takes that shape.

Git LFS in the copy

Base’s image has git-lfs, pinned like every other download, but nothing in the image sets its filter, so a VM that mounts its folder sees each LFS file as the pointer git stores. The copy sets the filter in each clone repo it makes, submodules included, with git lfs install --local --skip-repo, which writes the repo’s own config and no hooks, and when that fails, devvm says the clone’s LFS files may be pointers there (clone_lfs_setup_failed). No git-lfs runs on this machine for the copy or for what comes back, and when the repo’s lfs.storage puts its objects outside .git, devvm copies none either way and says so (clone_lfs_storage).

Every object file devvm reads or writes on this machine is opened beneath the repo’s common dir through a root that no path can leave, and before that, each folder on the way, lfs, lfs/objects, both two-character folders and lfs/tmp, must be a folder, never a link, as such a root still follows a link that stays inside it. So a link planted in .git/lfs can’t make devvm send a file from elsewhere on this machine or write the VM’s content anywhere else.

On the way in, devvm reads the pointers among the index’s blobs: those of at most 1,024 bytes, git cat-file --batch-check says, which, read with git cat-file --batch, are a pointer as git-lfs’s spec has it, with its version line first, an oid sha256: of 64 lowercase hex characters and a size, each once, and a newline at its end. Both outputs are read as they come, and at most 200,000 blobs are taken as maybe pointers. Each object the repo has, at lfs/objects/<oid[0:2]>/<oid[2:4]>/<oid> in its common dir, a regular file of its pointer’s size, is hashed before anything is sent, and one whose SHA-256 isn’t its oid stays on this machine, named (clone_lfs_bad), while the copy goes on. The rest go in the tar as lfs/<oid>, hashed again as they’re sent, so one that changed in between fails the copy, its tar cut short. The VM moves each into its repo’s lfs/objects, where it has no file of that name, before the checkout. The checkout runs with GIT_LFS_SKIP_SMUDGE=1, so git-lfs never fetches during the copy, then git lfs checkout, which reads only the objects the repo has, writes each file’s content; a file whose object isn’t there stays a pointer.

On the way back, once each fetch from the VM is in, devvm clone fetch’s and devvm rm’s and devvm clone off’s, devvm lists the objects that what it fetched (FETCH_HEAD) reaches past this repo’s own refs, with git rev-list --objects --missing=allow-promisor, and reads the pointers among them as above. Its own refs are every ref but the saved/ branches and the remote-tracking branches of a devvm VM’s remote, so a commit that a plain git fetch devvm brought earlier, without its LFS objects, still has them looked for. Once that work is merged into a branch of this repo, though, its commits are past that branch, so devvm also has the script in the VM list the files in the clone’s lfs/objects, by name and size, none followed through a link, and takes those this repo lacks whose pointer the history of what it fetched names since the copy. That walk stops at what the copy set the clone’s refs to, which the VM keeps in .git/devvm-seed-tips, so an object the VM fetched for the history it was given isn’t taken for its work, and a long history never has every blob read, or, for a clone an older devvm made, at this repo’s own refs, as above. When the objects this repo lacks come to more than 2 GiB in all, a total that can’t overflow, devvm asks first (clone_lfs_large), and refuses without a terminal. A script in the VM then writes all of them in one stream, its connection carrying no SSH agent: for each, a line with the oid and its size and then the clone’s own .git/lfs/objects/…/<oid>, a regular file that isn’t a link, or a line that says the clone lacks it or has it at another size. devvm reads exactly the pointer’s size of each into a new file in this repo’s lfs/tmp and moves it into lfs/objects only when its SHA-256 is the oid. One that the VM lacks, or that isn’t what its pointer names, stays out, named (clone_lfs_kept), and its file is a pointer here until git lfs pull fetches it. A failure is named too (clone_lfs_failed), with its reason in the run log.

An object that the VM’s clone has and that didn’t come back, for a reason other than its content, such as a link in .git/lfs or a stream cut short, would go with the VM, so devvm rm and devvm clone off keep the VM then, as for a commit they couldn’t fetch. Their check also looks for the objects that only the VM’s clone has, of commits this repo has already: it lists them as above from the clone’s refs, merged ones included, asks the script in the VM which it has, sizes only, stopping the script once it writes more than a line for each, or more than 64 MiB of the list, and names them (clone_lfs_unfetched), then asks before the VM goes, which devvm clone fetch answers by bringing them here.

The working tree in the copy

The copy sends your uncommitted changes as git’s own index and the working copies of the files that differ from it, so git status in the VM shows what it shows here. devvm reads the repo’s index, at the path git rev-parse --git-path index gives, as a regular file only, never through a link, into a temporary file of its own, registered for removal before any git command runs, so it goes however the copy ends. The copy keeps the index’s modification time, so git tells a file changed in the second the index was written from one that wasn’t, as it would with the repo’s own index. devvm’s git then refreshes the copy, so a file whose stat changed but not its content isn’t sent, without entering any submodule (--ignore-submodules), and rewrites it as version 3, even when it’s that already (--force-write-index), with no split index, no sparse directories, no untracked cache, no fsmonitor data, no resolve-undo and a real trailing hash. The untracked cache names untracked files and the repo’s path on this machine, so none of that goes, and any git since 1.7 reads the result. Resolve-undo, which git checkout -m uses to bring back a conflict you resolved, can name blobs that no ref reaches and that the pack doesn’t carry, so the VM’s repo would fail git fsck with it. What’s staged is staged in the VM, conflicts, intent-to-add entries and skip-worktree bits included, and the pack carries every blob the index names, but no gitlink’s commit, which isn’t this repo’s. An index with a path that git never checks out, one with a .git part in any case, as macOS and Windows also read one, or with an empty, . or .. part, fails the copy.

git ls-files -s -z on the copy lists the paths, and git diff-files --ignore-submodules=all --name-only -z on it lists those whose working copy differs. Without --ignore-submodules, git diff-files runs git status in each submodule and embedded repo, where that repo’s own config can name a filter that devvm’s git hasn’t turned off, so devvm runs diff-files only through the helper that adds it. Each path that differs is sorted out through a root opened at the repo, and each folder on the way to it is opened from its parent, refusing a symbolic link, so neither a link out of the repo nor one inside it, such as a tracked folder replaced by a link to an ignored folder or to .git, sends another file:

  • A regular file or a symbolic link, where the index has one of those, goes as it is, under changed/ in the tar, with its permissions and modification time, read without following a link. A file that’s a link now goes as the link, so git status in the VM shows the same type change.
  • A path that’s gone, or whose folder is a symbolic link here, which git takes for a deletion, goes as gone: the VM doesn’t check it out, so it’s deleted there too.
  • Anything else, such as a tracked file that’s a folder now, goes as gone, and devvm names it (clone_typechange_kept), so nothing inside that folder goes.
  • A gitlink, a submodule’s or an embedded repo’s, is checked out as git does, as an empty folder, without its .git or anything in it.
  • A path that a filter attribute names a filter for, in the working tree’s attributes or the index’s, such as git-crypt’s or Git LFS’s, is checked out from the index, as git stores it, and named as one that may differ (clone_filtered_kept). devvm’s git runs no filter, so it can’t tell a real change from the filter’s own. Such a file that’s gone goes as gone.

In the VM, when the copy sets HEAD, it puts the index in place, notes which of the paths sent or gone it already has a file at, copies each working copy sent where the VM has no file, with cp -P -p, and checks out the other paths from the index, without -f, except a conflict’s, which has no entry to check out, and a path with the skip-worktree bit that the working tree doesn’t have, which a sparse checkout leaves out, in the VM as here. A skip-worktree path that the working tree has, marked by hand with git update-index --skip-worktree or left by a git older than 2.37 outside a sparse checkout, is checked out from the index, never sent as it is here, because git hides its edits, which are often local settings or secrets: the VM turns the bit off for those paths (skip.list), checks them out and turns it on again, and devvm names them (clone_skip_worktree_kept). An assume-unchanged file’s edits are hidden from git diff-files too, so it goes as the index has it. The VM’s files that the copy didn’t write over are named (clone_kept_files): those at a path you changed or deleted here, and those elsewhere that differ from the index. When the copy keeps the VM’s HEAD, the VM’s index stays, nothing of the working tree is applied, because your changes would apply to something else, and devvm says so (clone_uncommitted_kept) instead of naming the files it would have left out.

The state in the copy

The copy sends what git keeps beside the refs and the index that you’d miss in the VM. Every file is read from the repo’s git dir, at the path git rev-parse --git-path gives, so a linked worktree’s own are read, as a regular file only, never through a link, at most 16 MiB each and 64 MiB in all, and a folder is opened from its parent, refusing a link. info/sparse-checkout and info/attributes always go. info/exclude goes too, added below the VM’s own, which holds the lines that keep a folder of repos’ other repos out of each one’s git status.

An operation’s files go only while it’s in progress, and an operation is never told by a file that a reftable repo keeps as a ref:

  • A rebase, by its folder, rebase-merge or rebase-apply: the folder’s files, the pseudo-refs REBASE_HEAD and AUTO_MERGE, and the refs below refs/rewritten/, with ORIG_HEAD only during git am (rebase-apply/applying), whose --abort needs it.
  • A merge, by its MERGE_HEAD file: MERGE_HEAD, MERGE_MSG, MERGE_MODE, MERGE_AUTOSTASH and SQUASH_MSG, and the pseudo-ref AUTO_MERGE.
  • A cherry-pick or a revert, by the pseudo-ref CHERRY_PICK_HEAD or REVERT_HEAD, or by the sequencer folder: MERGE_MSG, the folder’s files, and the pseudo-refs CHERRY_PICK_HEAD, REVERT_HEAD and AUTO_MERGE.
  • Bisect, by its BISECT_START file: the BISECT_* files, BISECT_FIRST_PARENT included, the pseudo-ref BISECT_HEAD, and the refs below refs/bisect/.

A pseudo-ref is read with git rev-parse -q --verify, and only when --symbolic-full-name gives its own name back, so a branch or tag named CHERRY_PICK_HEAD isn’t taken for one. It’s set in the VM with git update-ref, never copied as a file, so a reftable repo, which keeps CHERRY_PICK_HEAD and the rest as refs, works as a files one does. ORIG_HEAD never goes otherwise, not even while an operation is in progress, because a reset made meanwhile points it at what it took back, such as a commit that held a secret, and a stopped rebase or a sequencer folder left behind would carry it along.

The pack carries the commits the operation needs, and only those that its files hold as object ids: the first word of rebase-merge’s onto, orig-head, stopped-sha, amend, autostash and squash-onto, every id in its update-refs, the first two of each line of its rewritten-list and rewritten-pending, rebase-apply’s onto, orig-head and abort-safety, each line of MERGE_HEAD, MERGE_AUTOSTASH, sequencer’s head and abort-safety, BISECT_EXPECTED_REV, and the ids on BISECT_LOG’s lines that mark a commit good, bad, skipped, or with the terms BISECT_TERMS names. Each must be an object the repo has, which git cat-file --batch-check says. Free text never counts, so a commit that only a merge message or a revert’s message names stays on this machine. A new state file that holds object ids needs its entry in that list. The commits the todo lists still have to pick, rebase-merge/git-rebase-todo and sequencer/todo, are never scanned into the pack: devvm resolves each and names those that the copy’s refs and the ids above don’t reach (clone_todo_missing), as that step will fail in the VM.

The stash goes as its entries, oldest first, each with its message, read with git reflog show --format='%H %gs' refs/stash, the newest 1,000, the rest named (clone_stash_over_kept), and the VM stores each with git stash store -m, the commits it was made on with it. An entry with untracked files, a third parent, is taken for one of git stash --all and stays, named (clone_stash_all_kept), because it may hold ignored files, such as .env, when any of those files is a .gitignore, when the entry changes a .gitignore (git stash --all takes back an uncommitted edit of one, so the rules that ignored a file are gone from the working tree), or when the ignore rules ignore any of its untracked files (git check-ignore --no-index), as they are now or as the entry’s own .gitignore files had them, which devvm writes into a folder of their own to check against. The check errs toward keeping an entry back. A linked worktree’s copy sends no stash, which is the whole repo’s. The VM records each entry it stores in .git/devvm-seeded-stash, so a copy that runs again skips as many as the record has, an entry that the stash holds twice is stored twice, and the clone check leaves those entries out of the VM’s own.

The script that reads the clone’s state prints every other entry as SHA stash@{N}, devvm names it as stash-N when this repo doesn’t have its commit, and fetches it by that commit. devvm clone fetch does the same, with a script of its own whose lines devvm takes only for a detached HEAD’s commit and stash entries, so the VM can’t have it save a branch of another name, and an entry it can’t fetch is named, the others saved. For rm and clone off, an entry that can’t be fetched keeps the VM. A stash entry is never saved with its untracked files, because git stash apply writes them, ignored ones too, such as a virtualenv’s sitecustomize.py that Python runs on its own, while git stash show doesn’t list them. devvm makes the entry again with git commit-tree, from its tree and its first two parents, with its own message, author and committer, so the same entry is always the same commit, and saves that as saved/devvm/stash-N. The untracked files go to saved/devvm/stash-N-untracked, and devvm names them, and those that git on this machine ignores (clone_stash_untracked, clone_stash_untracked_ignored). Every fetch from a VM checks each object it receives (transfer.fsckObjects). No ref names an older entry, and devvm’s ssh passes no GIT_PROTOCOL to the VM, so its git upload-pack speaks protocol v0, which refuses a commit no ref names unless the fetch runs it with uploadpack.allowAnySHA1InWant, as devvm’s does. That only lets the host ask the VM for its own objects. The stubs drop GIT_PROTOCOL too, so the tests fetch over v0.

The state goes in only when the copy sets HEAD, as the working tree does, since an operation applies to the commit it started from, and so do the refs of an operation, below refs/rewritten/ and refs/bisect/. The stash goes in either way.

The settings in the copy

The copy reads the repo’s own config with git config --local --no-includes --null --list, and, when extensions.worktreeConfig is on, the worktree’s config.worktree after it with --worktree, where git sparse-checkout writes its settings, so neither your global config nor an included file goes. It sends only the keys of an allowlist, each value checked, never the config as a file, and a key written with no value, which git reads as true, goes as true. The VM sets them with git config --add, each key unset first, then writes .git/devvm-seeded-config, so a copy that runs again sets nothing over what the VM changed since:

  • remote.<name>.url, as git remote get-url --all gives them, with insteadOf applied, and pushurl, when git remote get-url --push --all gives other URLs, as it does with a push URL or a pushInsteadOf. Each URL is cleaned: an http or https URL without its user name, password, query or fragment, any of which can be a token; an ssh://, git+ssh:// or ssh+git:// URL without its password, query or fragment, its user kept, as git@ is a name, not a secret; a scp-like [user@]host:path as it is; and a file:// URL or a path as it is. git reads a scp-like URL’s host up to its first colon, past a bracketed host such as [::1], so its user, before an @ there, holds no colon, and one whose path has an @ and then a colon, as in user:token@host:path, which git reads as the host user and a path holding the token, stays. Any other kind, such as git:// or a transport helper’s ext::, stays, named (clone_urls_kept), and a remote with no URL that goes stays with the rest of its settings. A remote that reaches a devvm VM stays, as its refs do, and so does a push URL that reaches one. A remote whose push URLs all stay goes without them, so git push in the VM pushes to its URL, named (clone_push_urls_kept). A remote whose URLs git remote get-url can’t give stays, named (clone_urls_unread).
  • remote.<name>.fetch, promisor, partialclonefilter and tagOpt, for a remote that goes.
  • branch.<name>.remote, merge, rebase and pushRemote, for a branch the copy sends, so the VM of a worktree learns no other branch’s name, but an upstream on a remote that stays.
  • submodule.<name>.url, resolved with git ls-remote --get-url and cleaned as a remote’s, and its active, branch and update, but an update that runs a command (!command).
  • core.sparseCheckout, core.sparseCheckoutCone and index.sparse.
  • core.hooksPath, the last one, when it’s a relative folder inside the repo, never through .. or a .git part, and not one that git expands, as it does ~/ and %(prefix)/.
  • user.name and user.email.

Nothing else goes, such as credential.*, http.* and its extra headers, url.*.insteadOf, which the URLs have applied already, core.sshCommand, core.fsmonitor, filter.*, include*, alias.*, or the keys that describe this machine’s filesystem, core.ignorecase, precomposeunicode, filemode and symlinks.

The hooks go as they are, and only as git here runs them, from the common dir’s hooks folder, which git rev-parse --git-path hooks can’t give, as it gives /dev/null under devvm’s own git’s core.hooksPath. They go when the core.hooksPath git uses is none, .git/hooks or that folder. It’s the last of the repo’s own config and its worktree’s, includes followed (git config --includes --show-scope --get-all, its local and worktree ones), so an include after the repo’s own wins, as in git, else your global or system config’s, read from the files that GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM name when they’re set. In a linked worktree, whose .git is a file, a relative .git/hooks names no folder, so git there runs no hook, and none goes. A core.hooksPath elsewhere inside the repo goes as the setting alone: the hooks in it are files of the working tree, so the tracked ones reach the VM with the checkout, and the untracked ones, such as husky’s _ folder, stay, as every untracked file does. One outside the repo, or one an included file sets, stays, named (clone_hooks_path_kept), and no hook goes. The hooks folder is opened from the common dir, never through a link, and one that’s missing, a link or unreadable is named (clone_hooks_dir_kept). Only files named as git’s hooks go, the names devvm’s own git turns off, each a regular file of at most 1 MiB and 16 MiB in all. A link, a folder or a bigger file stays, named (clone_hooks_kept). In the VM, a hook goes into the git dir’s hooks folder only where the VM has no file of that name, with its executable bit.

The settings and hooks go in last, after the checkout, and the script’s git runs with core.hooksPath=/dev/null, so neither a hook the copy brings nor one of the VM’s own runs during the copy, and none can fail it or a copy that runs again.

The record of what was copied

So that devvm rm and devvm clone off don’t take your own uncommitted changes for the VM’s work, the copy leaves a record of them in the VM’s repo, .git/devvm-seeded-tree, written with the index. It covers each path that git status in the VM would list once the copy is in: those whose staged entry isn’t HEAD’s, found with git diff-index --cached on the normalised index, and those whose working copy differs. For each path it holds what devvm put there: the blob of the working copy, which devvm hashes as it sends the file, with a mark for an executable file, = for one checked out from the index, dir for a gitlink’s empty folder or - for none, and the path’s index entries, each with its mode, blob and stage.

The clone check reads the record back in the VM. For each path, git in the VM hashes the working copy with git hash-object --no-filters, or the link’s target for a symbolic link, or, for one checked out from the index, asks git diff-files --quiet after a refresh whether it’s still the index’s, so a file that info/attributes converts, such as with eol=crlf, matches as git checked it out, and it lists the index entries with git ls-files --format, and the VM prints the paths whose state matches the record. devvm leaves the git status lines that name only those paths out of what it counts and shows, so a path counts once the VM changes its content, its executable bit or what’s staged for it. A deletion that’s still deleted matches. Untracked files’ lines always count, as the copy sends none.

The record is the VM’s side of the copy, not a comparison with the repo here, so it stays right when your working copy changes after the copy, and it needs nothing in devvm’s own state. The VM can write the record, and it can answer for it anything it likes, but all a forged record or answer can do is make the VM’s own work look unchanged, so that devvm rm deletes it without asking, which hurts only the VM’s work. A VM without the record, such as one an older devvm made, or whose git has no ls-files --format (before 2.38), counts every change as before.

Last updated on