mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
devvm git-protect shows a folder's VM's .git protection (on, strict, off, or clone for a --clone VM) and changes it while the VM is stopped. On and strict lock .git as it is now, reporting what a lock can't cover as a new VM does; strict also sets diff.ignoreSubmodules=all in the locked .git/config, which on and off take out; off unlocks. Locks need macOS. - gitprotect: Mode, Set, ignoreSubmodules; NewVM and Check share protect (new, on, check); strict counts as on for launches and rm. - Messages: no_vm_git_protect, git_protect_failed, git_protect_running, git_protect_on_needs_macos, git_protect_clone, git_config_failed, git_locked, git_locked_strict, git_lock_later, git_unlocked; git_protect_flag_ignored names devvm git-protect off. - Tests: TestSet, TestSetStrictFails, TestSetLinuxAndNoGit; testdata/script/git_protect.txtar (project.bats strict and git-protect-waits cases). e2e project: waits for stop, strict, off/on, refused off macOS. - Docs: git-protection.md (turning it on or off, strict), commands.md, CLI reference. Co-Authored-By: Claude Opus 5.5 <[email protected]>
104 lines
3.6 KiB
Plaintext
104 lines
3.6 KiB
Plaintext
# devvm git-protect: shows a folder's VM's .git protection, and turns it on,
|
|
# strict or off while the VM is stopped. 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.
|
|
env DEVVM_MESSAGES=names
|
|
env VMS=$XDG_DATA_HOME/devvm/vms
|
|
|
|
# No VM yet.
|
|
mkdir $WORK/web
|
|
cd $WORK/web
|
|
! exec devvm git-protect
|
|
stderr '^devvm: no_vm_git_protect dir=\S*/web$'
|
|
! exec devvm git-protect maybe
|
|
stderr '^devvm: usage_error '
|
|
|
|
# A new VM, running: shown, but not changed on macOS (it could race the
|
|
# locks); elsewhere off, and on is refused.
|
|
exec git init -q
|
|
exec devvm --no-network-policy base
|
|
exec devvm git-protect
|
|
[darwin] stdout '\Aon\n\z'
|
|
[linux] stdout '\Aoff\n\z'
|
|
[darwin] ! exec devvm git-protect off
|
|
[darwin] stderr '^devvm: git_protect_running vm=devvm-web-[0-9a-f]{14}$'
|
|
[linux] exec devvm git-protect off
|
|
[linux] stdout '^==> git_unlocked vm=devvm-web-[0-9a-f]{14}$'
|
|
! exec devvm git-protect strict
|
|
[darwin] stderr '^devvm: git_protect_running vm=devvm-web-[0-9a-f]{14}$'
|
|
[linux] stderr '^devvm: git_protect_on_needs_macos$'
|
|
[linux] stop 'no locks off macOS'
|
|
|
|
# Stopped: strict sets diff.ignoreSubmodules with .git/config unlocked,
|
|
# then locks .git again.
|
|
exec sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
|
|
exec sh -c ': > "$STUB_LOG"'
|
|
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 sh -c 'cat "$VMS"/devvm-web-*'
|
|
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
|
|
exec sh -c ': > "$STUB_LOG"'
|
|
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 sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
|
|
exec sh -c ': > "$STUB_LOG"'
|
|
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 sh -c 'limactl stop "$(basename "$VMS"/devvm-web-*)"'
|
|
exec devvm git-protect strict
|
|
exec sh -c ': > "$STUB_LOG"'
|
|
exec devvm
|
|
stub_calls
|
|
stdout '^chflags -R -P uchg /\S*/web/\.git/config$'
|
|
exec sh -c ': > "$STUB_LOG"'
|
|
exec devvm rm -f
|
|
stub_calls
|
|
stdout '^chflags -R -P nouchg /\S*/web/\.git/config$'
|
|
|
|
# Without a .git yet: locked when one appears.
|
|
mkdir $WORK/nogit
|
|
cd $WORK/nogit
|
|
exec devvm --no-network-policy base
|
|
exec sh -c 'limactl stop "$(basename "$VMS"/devvm-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 >> "$(ls "$VMS"/devvm-nogit-*)"'
|
|
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}$'
|