# 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