mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
devvm git-protect strict (0.1.0, 0.1.1-rc.1) set diff.ignoreSubmodules = all in the locked .git/config, which can't keep git on this machine out of a submodule the VM adds: a .gitmodules ignore line the VM writes overrides it, and git add -A/-u, describe --dirty, diff-index, diff-files, fetch and pull recursion and --ignore-submodules on the command line enter submodules anyway (#37). --clone is the only way to keep VM code away from host git. - devvm git-protect takes on|off; strict is a usage error (git_protect_strict_refused) naming devvm clone on. Use, help, completion (Modes) and --json reflect it. - A VM left strict reads as on (Mode, Next) and is pinned and kept as on. The first check that finds it stopped (Check, then converter.unstrict: launches, devvm stop, devvm clone on and its undo) removes the value all from the .git/config of each repo its state recorded before that check, under the host's git lock, and only where .git's identity is the recorded git_id (a replaced .git, or a VM with no record after devvm adopt, is left alone, its all named with the manual remedy: git_strict_unknown). Each config is read through safefile first, unlocked for the edit and locked again even after an interrupt (context.WithoutCancel), and checked to still be a regular file in that .git afterwards (git_lock_raced). On a watching host, a config whose sum isn't the check's is left, and the new sums go into the watch's. An interrupt records nothing. Then on is recorded (mode and next) with one warning (git_strict_converted), none when next is off. Set on/off and Unlock (devvm rm) remove it the same way, silently (strictLeft). - strict recorded nothing about a value it overwrote, so nothing can be restored: only all is removed (--unset-all '^all$'); any other value is the user's and stays. This fixes off, which unset any local value. - A config another VM keeps locked keeps it, named with the manual remedy (git_strict_kept, via msg.M.Value), and its repo goes in the state's strict_left, retried at each later stopped check until empty. A config git can't change is named (git_strict_left). - Messages: git_locked and git_embedded_new say what on can't stop; git_locked_strict and git_config_failed go. - Docs: .git protection's Strict section becomes VMs that were strict, with the remedies; on and Not covered say a submodule or repo the VM adds runs through host git until the next check names it, and only --clone keeps VM code away; attack vectors, How it works, the design notes, the commands table, ls, the cli skill and the CLI reference follow. - Tests: strict_test.go (conversion, values kept, off/on/unlock, nested, kept and retried, replaced and unrecorded .git, interrupted, next off, changed since the check, Linux pins and sums, Watch, next, a failed edit), TestUnstrictFIFO, msg TestValue, git_protect.txtar, git_pins.txtar, fixture_v010_strict.txtar (0.1.0's app VM made strict on macOS), e2e project checks on macOS and Linux. Co-Authored-By: Claude Opus 5.5 <[email protected]>
210 lines
7.0 KiB
Plaintext
210 lines
7.0 KiB
Plaintext
# devvm git-protect: shows a folder's VM's .git protection, and turns it on
|
|
# or off while the VM is stopped; a running VM's change is saved and
|
|
# applied when it next stops. Locks need macOS: elsewhere on is refused.
|
|
# strict, which an earlier devvm took, is a usage error, and a VM it left
|
|
# strict reads as on and is on once a check finds it stopped, the
|
|
# diff.ignoreSubmodules = all that strict set taken out of .git/config,
|
|
# with one warning. The chflags stub changes no flags.
|
|
|
|
# No VM yet. strict is refused before anything runs.
|
|
project web
|
|
! exec devvm git-protect
|
|
stderr '^devvm: no_vm_git_protect dir=\S*/web$'
|
|
! exec devvm git-protect maybe
|
|
stderr '^devvm: arg_not_choice choices=on, off command=devvm git-protect given=maybe$'
|
|
! exec devvm git-protect strict
|
|
stderr '^devvm: git_protect_strict_refused$'
|
|
stderr '^usage_help command=devvm git-protect$'
|
|
! stderr no_vm
|
|
|
|
# A new VM, running: shown, but on macOS changed only when it next stops
|
|
# (it could race the locks), the last choice kept; elsewhere off, and on
|
|
# is refused.
|
|
exec git init -q
|
|
exec devvm --network open
|
|
vm_name WEB web
|
|
exec devvm git-protect
|
|
[darwin] stdout '\Aon\n\z'
|
|
[linux] stdout '\Aoff\n\z'
|
|
[linux] exec devvm git-protect off
|
|
[linux] stdout '^==> git_unprotected_quiet vm=devvm-web-[0-9a-f]{14}$'
|
|
[linux] ! exec devvm git-protect on
|
|
[linux] stderr '^devvm: git_protect_on_needs_locks$'
|
|
[linux] stop 'no locks off macOS'
|
|
stub_reset
|
|
exec devvm git-protect on
|
|
stdout '^==> git_protect_next_stop mode=on vm=devvm-web-[0-9a-f]{14}$'
|
|
exec devvm git-protect off
|
|
stdout '^==> git_protect_next_stop mode=off vm=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
! stdout chflags
|
|
exec devvm git-protect
|
|
stdout '\Aon\n\z'
|
|
vm_state $WEB_dir/vm.json
|
|
stdout '^git.next=off$'
|
|
# devvm stop applies it.
|
|
exec devvm stop
|
|
stdout '^==> git_unlocked vm=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
stdout '^chflags -R -P nouchg /\S*/web/\.git/config$'
|
|
exec devvm git-protect
|
|
stdout '\Aoff\n\z'
|
|
vm_state $WEB_dir/vm.json
|
|
! stdout '^git.next=.'
|
|
# Stopped outside devvm: the next launch applies it before the VM starts.
|
|
exec devvm
|
|
exec devvm git-protect on
|
|
stdout '^==> git_protect_next_stop mode=on vm=devvm-web-[0-9a-f]{14}$'
|
|
exec limactl stop $WEB
|
|
stub_reset
|
|
exec devvm
|
|
stdout '^==> git_locked vm=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
stdout '^chflags -R -P uchg /\S*/web/\.git/config\n(.*\n)*limactl .*start'
|
|
exec devvm git-protect
|
|
stdout '\Aon\n\z'
|
|
|
|
# A .git the VM replaced while it ran is named when it stops, before the
|
|
# mode saved meanwhile is set and takes .git as it is.
|
|
exec devvm git-protect on
|
|
stdout '^==> git_protect_next_stop mode=on vm=devvm-web-[0-9a-f]{14}$'
|
|
mv .git .git-old
|
|
exec git init -q
|
|
exec devvm stop
|
|
stderr '^devvm: git_replaced git=\S*/web/\.git$'
|
|
stdout '^==> git_locked vm=devvm-web-[0-9a-f]{14}$'
|
|
exec devvm
|
|
! stderr git_replaced
|
|
rm .git-old
|
|
|
|
# Stopped: on locks .git again, and neither on nor off touches a
|
|
# diff.ignoreSubmodules of your own.
|
|
exec limactl stop $WEB
|
|
exec git config --file .git/config diff.ignoreSubmodules dirty
|
|
exec devvm git-protect off
|
|
stub_reset
|
|
exec devvm git-protect on
|
|
stdout '^==> git_locked vm=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
stdout '^chflags -R -P uchg /\S*/web/\.git/config$'
|
|
stdout '^chflags -R -P uchg /\S*/web/\.git/hooks$'
|
|
! stdout 'nouchg|limactl (start|edit)'
|
|
exec git config --file .git/config diff.ignoreSubmodules
|
|
stdout '\Adirty\n\z'
|
|
exec devvm git-protect
|
|
stdout '\Aon\n\z'
|
|
exec devvm git-protect --json
|
|
stdout '\A{\n "version": 1,\n "mode": "on"\n}\n\z'
|
|
! exec devvm git-protect --json off
|
|
stderr '^devvm: json_shows_only command=devvm git-protect$'
|
|
vm_state $WEB_dir/vm.json
|
|
stdout '^git.mode=on$'
|
|
stdout '^git.made.git_id=[0-9]+:[0-9]+'
|
|
exec git config --file .git/config --unset diff.ignoreSubmodules
|
|
|
|
# A VM an earlier devvm left strict, running: it reads as on, and a
|
|
# launch into it changes nothing.
|
|
exec devvm
|
|
json_set $WEB_dir/vm.json git.mode=strict
|
|
exec git config --file .git/config diff.ignoreSubmodules all
|
|
exec devvm git-protect
|
|
stdout '\Aon\n\z'
|
|
exec devvm git-protect --json
|
|
stdout '"mode": "on"'
|
|
exec devvm ls
|
|
stdout '^devvm-web-[0-9a-f]{14} +Running +base +- +on '
|
|
exec devvm
|
|
! stderr git_strict
|
|
vm_state $WEB_dir/vm.json
|
|
stdout '^git.mode=strict$'
|
|
# devvm stop converts it: strict's all comes out, .git/config unlocked for
|
|
# the edit and locked again, it's on, and it says so once.
|
|
stub_reset
|
|
exec devvm stop
|
|
stderr '^devvm: git_strict_converted vm=devvm-web-[0-9a-f]{14}$'
|
|
! exec git config --file .git/config diff.ignoreSubmodules
|
|
stub_calls
|
|
stdout '^chflags -R -P nouchg /\S*/web/\.git/config\n(.*\n)*chflags -R -P uchg /\S*/web/\.git/config$'
|
|
vm_state $WEB_dir/vm.json
|
|
stdout '^git.mode=on$'
|
|
exec devvm
|
|
! stderr git_strict
|
|
exec devvm stop
|
|
! stderr git_strict
|
|
|
|
# Off on a VM left strict unlocks, and takes out only strict's all: a
|
|
# value set since stays. A launch then locks nothing.
|
|
json_set $WEB_dir/vm.json git.mode=strict
|
|
exec git config --file .git/config diff.ignoreSubmodules none
|
|
stub_reset
|
|
exec devvm git-protect off
|
|
stdout '^==> git_unlocked vm=devvm-web-[0-9a-f]{14}$'
|
|
! stderr git_strict
|
|
exec git config --file .git/config diff.ignoreSubmodules
|
|
stdout '\Anone\n\z'
|
|
stub_calls
|
|
stdout '^chflags -R -P nouchg /\S*/web/\.git/hooks$'
|
|
stdout '^chflags -R -P nouchg /\S*/web/\.git/config$'
|
|
! stdout ' uchg '
|
|
exec devvm git-protect
|
|
stdout '\Aoff\n\z'
|
|
exec git config --file .git/config --unset diff.ignoreSubmodules
|
|
stub_reset
|
|
exec devvm
|
|
stub_calls
|
|
! stdout chflags
|
|
|
|
# --no-git-protect on an existing VM names devvm git-protect off.
|
|
exec devvm --no-git-protect
|
|
stderr '^devvm: new_vm_flags_ignored_run command=devvm git-protect off flags=--no-git-protect vm=devvm-web-[0-9a-f]{14}$'
|
|
|
|
# rm unlocks a VM left strict, and takes strict's all out.
|
|
exec limactl stop $WEB
|
|
exec devvm git-protect on
|
|
json_set $WEB_dir/vm.json git.mode=strict
|
|
exec git config --file .git/config diff.ignoreSubmodules all
|
|
stub_reset
|
|
exec devvm rm --force --no-export
|
|
! stderr git_strict
|
|
stub_calls
|
|
stdout '^chflags -R -P nouchg /\S*/web/\.git/config$'
|
|
! exec git config --file .git/config diff.ignoreSubmodules
|
|
|
|
# A gitlink the VM added whose .git file names the project's own src, which
|
|
# isn't a git dir: the launch names it and locks nothing in src.
|
|
project evil git
|
|
exec devvm --network open
|
|
vm_name EVIL evil
|
|
exec limactl stop $EVIL
|
|
exec git update-index --add --cacheinfo 160000,1111111111111111111111111111111111111111,sub
|
|
stub_reset
|
|
exec devvm
|
|
stderr '^devvm: git_gitdir_not_git git=\S*/evil/src sub=\S*/evil/sub$'
|
|
! stderr git_embedded_new
|
|
stub_calls
|
|
stdout '^chflags -R -P uchg /\S*/evil/\.git/config$'
|
|
! stdout '/evil/src'
|
|
exec devvm rm --force --no-export
|
|
|
|
# Without a .git yet: locked when one appears.
|
|
project nogit
|
|
exec devvm --network open
|
|
vm_name NOGIT nogit
|
|
exec limactl stop $NOGIT
|
|
exec devvm git-protect on
|
|
stdout '^==> git_lock_later vm=devvm-nogit-[0-9a-f]{14}$'
|
|
|
|
# A --clone VM mounts no .git: shown as clone, never changed.
|
|
json_set $NOGIT_dir/vm.json clone.on:=true git.mode=clone
|
|
exec devvm git-protect
|
|
stdout '\Aclone\n\z'
|
|
! exec devvm git-protect on
|
|
stderr '^devvm: git_protect_clone vm=devvm-nogit-[0-9a-f]{14}$'
|
|
|
|
-- evil/sub/.git --
|
|
gitdir: ../src
|
|
-- evil/src/hooks/useThing.ts --
|
|
export {}
|
|
-- evil/src/config --
|
|
x
|