# devvm git-protect: shows a folder's VM's .git protection, and turns it on, # strict or off while the VM is stopped; a running VM's change is saved and # applied when it next stops. Strict also keeps host git status and diff # out of submodules (diff.ignoreSubmodules=all in .git/config). Locks need # macOS: elsewhere on and strict are refused. The chflags stub changes no # flags. # No VM yet. 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, strict, off command=devvm git-protect given=maybe$' # 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 --no-network-policy 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_unlocked vm=devvm-web-[0-9a-f]{14}$' [linux] ! exec devvm git-protect strict [linux] stderr '^devvm: git_protect_on_needs_macos$' [linux] stop 'no locks off macOS' stub_reset exec devvm git-protect strict stdout '^==> git_protect_next_stop mode=strict 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' catg $WEB_dir/state stdout '^git_protect_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' catg $WEB_dir/state ! stdout '^git_protect_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 strict stdout '^==> git_protect_next_stop mode=strict 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_strict vm=devvm-web-[0-9a-f]{14}$' exec devvm exec devvm git-protect stdout '\Astrict\n\z' rm .git-old # Stopped: strict sets diff.ignoreSubmodules with .git/config unlocked, # then locks .git again. exec limactl stop $WEB stub_reset exec devvm git-protect strict stdout '^==> git_locked_strict vm=devvm-web-[0-9a-f]{14}$' exec git config --file .git/config diff.ignoreSubmodules stdout '\Aall\n\z' stub_calls stdout '^chflags -R -P nouchg /\S*/web/\.git/config\n(.*\n)*chflags -R -P uchg /\S*/web/\.git/config$' stdout '^chflags -R -P uchg /\S*/web/\.git/hooks$' ! stdout 'limactl (start|edit)' exec devvm git-protect stdout '\Astrict\n\z' exec devvm git-protect --json stdout '\A{\n "version": 1,\n "mode": "strict"\n}\n\z' ! exec devvm git-protect --json off stderr '^devvm: json_shows_only command=devvm git-protect$' catg $WEB_dir/state stdout '^git_protect=strict$' stdout '^git_inode=[0-9]+$' # On takes diff.ignoreSubmodules back out. exec devvm git-protect on stdout '^==> git_locked vm=devvm-web-[0-9a-f]{14}$' ! exec git config --file .git/config diff.ignoreSubmodules # Off unlocks, and takes it out too; a launch then locks nothing. exec devvm git-protect strict stub_reset exec devvm git-protect off stdout '^==> git_unlocked 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/hooks$' stdout '^chflags -R -P nouchg /\S*/web/\.git/config$' ! stdout ' uchg ' exec devvm git-protect stdout '\Aoff\n\z' exec limactl stop $WEB 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: git_protect_flag_ignored$' # Strict is kept on launches, and rm unlocks it. exec limactl stop $WEB exec devvm git-protect strict stub_reset exec devvm stub_calls stdout '^chflags -R -P uchg /\S*/web/\.git/config$' stub_reset exec devvm rm --force --no-export stub_calls stdout '^chflags -R -P nouchg /\S*/web/\.git/config$' # Without a .git yet: locked when one appears. project nogit exec devvm --no-network-policy 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. exec sh -c 'echo mode=clone >> "$NOGIT_dir/state"' 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}$'