Files
w3cjandClaude Opus 5.5 cda2d09f42 feat(gitprotect): on Linux, warn at each launch and report .git hooks and config that changed (#20)
Linux hosts have no unprivileged immutable flag, so devvm can't lock
.git there. It now warns at every launch of a VM that mounts a folder
with a .git (git_unprotected), unless it's a --clone VM or the user
chose devvm git-protect off (git.chosen), and it names, after the fact,
the hooks and config that changed (git_changed). It sums what a lock
would cover, .git/commondir, include.path targets and the folder
core.hooksPath names, never through a symlink out of the project folder
and within bounds (git_watch_blind names what it can't fully watch), at
each launch that finds the VM stopped and at devvm stop.

A check on such a host runs protect's reports without locking:
git_replaced, git_commondir, stray worktrees, git dirs that appeared,
core.hooksPath and delegations into the project folder, and a
submodule's folder that isn't a git dir (git_gitdir_not_git), in which
nothing is created and which the watch doesn't sum as a git dir.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-07 19:16:30 -07:00

80 lines
2.6 KiB
Plaintext

# On a host without .git locks (Linux), each launch warns that the VM can
# change the hooks and config in .git, until devvm git-protect off says
# the user knows. Each launch that finds the VM stopped, and devvm stop,
# name what changed of what a lock would cover since the last check: the
# new VM's first sums are recorded when it's made, and a VM with none
# recorded (an older devvm's) records its first without naming anything.
# A --clone VM mounts no .git, so neither applies.
[!linux] skip 'macOS locks .git: git_protect.txtar'
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
# A new VM: warned, its first sums recorded, nothing named.
project web git
exec devvm --network open
vm_name WEB web
stderr '^devvm: git_unprotected vm=devvm-web-[0-9a-f]{14}$'
! stderr git_changed
vm_state $WEB_dir/vm.json
stdout '^git.watched.scanned=true$'
stdout '^git.watched.sums..git/config=sha256 [0-9a-f]{64}$'
! stdout 'git.chosen'
# While it runs, a launch warns again and checks nothing.
exec git config core.fsmonitor ./evil
cp $WORK/hook .git/hooks/pre-commit
exec devvm
stderr '^devvm: git_unprotected vm=devvm-web-[0-9a-f]{14}$'
! stderr git_changed
# devvm stop names what changed, once.
exec devvm stop
stderr '^devvm: git_changed paths=\.git/config, \.git/hooks/pre-commit vm=devvm-web-[0-9a-f]{14}$'
! stderr git_unprotected
exec devvm stop
! stderr git_changed
# So does a launch that finds it stopped, before it starts.
exec limactl stop $WEB
rm .git/hooks/pre-commit
exec devvm
stderr '^devvm: git_changed paths=\.git/hooks/pre-commit vm=devvm-web-[0-9a-f]{14}$'
# devvm git-protect off is the user's choice: the warning stops, the watch
# goes on.
exec devvm git-protect off
stdout '^==> git_unprotected_quiet vm=devvm-web-[0-9a-f]{14}$'
vm_state $WEB_dir/vm.json
stdout '^git.chosen=true$'
exec devvm
! stderr git_unprotected
exec git config core.sshCommand ./evil
exec devvm stop
stderr '^devvm: git_changed paths=\.git/config vm=devvm-web-[0-9a-f]{14}$'
# A VM an older devvm made has no sums: its first check records them and
# names nothing.
json_set $WEB_dir/vm.json git.watched:=null
exec git config core.pager ./evil
exec devvm stop
! stderr git_changed
vm_state $WEB_dir/vm.json
stdout '^git.watched.scanned=true$'
# --no-git-protect is the user's choice too.
project quiet git
exec devvm --no-git-protect --network open
! stderr git_unprotected
# A --clone VM: neither.
project cloned
exec git init -q -b main
exec git commit -q --allow-empty -m one
exec devvm --clone --network open
! stderr git_unprotected
exec git config core.fsmonitor ./evil
exec devvm stop
! stderr git_changed
-- hook --
#!/bin/sh