Files
devvm/testdata/script/clone.txtar
T
52bb0f467b feat(clone): a --clone VM gets the repo as it is here
A --clone VM's clone is now seeded with a snapshot, not git push, and
gets everything a working copy has. devvm clone fetch brings it all
back, and devvm rm and clone off check it before deleting.

- Refs: every branch, tag and notes ref, and a detached HEAD.
- Uncommitted changes: staged, unstaged and untracked files; files
  skip-worktree by hand get the index's version, named.
- Operations in progress (merge, rebase, cherry-pick, revert, bisect)
  and the stash; a stash's untracked part goes as its own branch.
- The repo's settings and hooks, sent as settings only where they live
  in the repo (husky); ORIG_HEAD never goes.
- Partial clones, with their promisor remote, and messages per network
  tier when it can't be reached.
- Initialised submodules, nested ones too, each with a clone of its
  own; a submodule's own folder is refused as a top-level --clone.
  vm.json gains an optional `submodules` field.
- Git LFS both ways: objects hash-checked, written under os.Root with
  no link followed, a question past 2 GiB; the filter is set only in
  the clone's repos; git-lfs 3.8.1 in base, pinned by SHA-256.
- rm and clone off keep the VM when anything the VM has didn't come
  back, and name it.
- Every shell script embedded in Go is shellchecked.
- clone.md is a guide that leads with commands; TestUserPageProse
  covers it and coding-agents.md.

After you upgrade: base and every image on it build again once, for
git-lfs.

Fixes #40, reported by @Josuesp1620. Thanks to @dhruv1220 for #42,
which found the cause (receive-pack refusing a shallow push); its
receive.shallowUpdate setting stays in the VM's repos.

Co-authored-by: Dhruv Arora <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-12 11:54:42 -07:00

199 lines
8.2 KiB
Plaintext

# --clone: the VM gets its own clone of the repo instead of the folder
# mounted. The host's branches are copied into it through the VM's own
# command, the repo gets a devvm remote, and nothing of .git is locked. rm checks
# the clone for commits the repo hasn't fetched and uncommitted changes,
# in the clone and its worktrees, keeps fetched work as local branches and removes the remote. (The stubs
# keep the VM's files in
# $STUB_DIR/vmfs.)
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
mkdir $WORK/web/sub
cd $WORK/web
# Not a repo, not its top folder, no commits: refused before anything is
# built. (A detached HEAD is copied as it is: clone_refs.)
! exec devvm --clone --network open
stderr '^devvm: clone_not_top dir=/\S*/web$'
exec git init -q -b main
cd sub
! exec devvm --clone --network open
stderr '^devvm: clone_not_top dir=/\S*/web/sub$'
cd ..
! exec devvm --clone --network open
stderr '^devvm: clone_no_commits$'
exec git commit -q --allow-empty -m one
# Objects borrowed from another repo (alternates), or a .git file that
# points into one: refused.
exec sh -c 'echo /elsewhere/objects > .git/objects/info/alternates'
! exec devvm --clone --network open
stderr '^devvm: clone_alternates path=/\S*/web/\.git/objects/info/alternates$'
rm .git/objects/info/alternates
mkdir $WORK/pointed
exec sh -c 'echo "gitdir: $(pwd -P)/.git" > ../pointed/.git'
cd $WORK/pointed
! exec devvm --clone --network open
stderr '^devvm: clone_git_elsewhere path=/\S*/pointed/\.git$'
cd $WORK/web
exec git branch other
stub_calls
! stdout 'limactl (create|clone)'
! exists $VMS
# A new VM: nothing mounted but the shared tools; its clone made at the
# folder's path, every branch copied into it through the VM's own command,
# never git push, main checked out; the remote added. The repo's
# url.*.insteadOf, which rewrites the VM's URL to another host, doesn't
# change where devvm clone fetch goes: devvm's ssh connects to the VM
# alone. Not a terminal: the Include line isn't added, and devvm says how
# to fetch until it is. The uncommitted change is copied too
# (clone_uncommitted has the rest).
exec sh -c 'echo x > tracked && git add tracked && git commit -qm two && echo y > tracked'
exec git config url.elsewhere.example:/x.insteadOf devvm-web-
stub_reset
exec devvm --clone --network open
stdout '^==> copying_branches$'
stdout '^==> clone_ready branch=main remote=devvm$'
stdout '^ssh_include_needed line=Include /\S*/data/devvm/ssh_config$'
stderr '^devvm: ssh_include_yourself$'
stderr '^devvm: fetch_until file=/\S*/data/devvm/ssh_config remote=devvm$'
! stderr 'git_protect|ssh_remote_hint|uncommitted'
stub_calls
stdout '^limactl clone --tty=false devvm-img-[0-9a-f]{12} devvm-web-[0-9a-f]{14} --mount-none --set \.mounts = \[\{"location":"[^"]*/data/devvm/tools","mountPoint":"/mnt/devvm-tools","writable":false\}\] '
! stdout 'git-receive-pack'
! stdout elsewhere
stdout '^limactl shell --workdir /\S*/web devvm-web-[0-9a-f]{14}\n\z'
! stdout chflags
stub_reset
exec devvm clone fetch
stderr '^devvm: clone_remote_elsewhere path=\. remote=devvm$'
stub_calls
! stdout '^ssh '
vm_name WEB web
vm_state $WEB_dir/vm.json
stdout '^clone.on=true$'
stdout '^clone.made.remote=devvm$'
stdout '^clone.made.seeded=true$'
stdout '^git.mode=clone$'
exec git config --unset url.elsewhere.example:/x.insteadOf
exec git remote get-url devvm
stdout '^devvm-web-[0-9a-f]{14}:/\S*/web$'
exec sh -c 'c="$STUB_DIR/vmfs$(pwd -P)"; git -C "$c" branch --show-current && git -C "$c" branch --format="%(refname:short)" && cat "$c/tracked"'
cmp stdout $WORK/vm-branches
! exists $HOME/.ssh/config
stub_reset
exec devvm clone fetch
stub_calls
stdout '^ssh -F none -T -o BatchMode=yes .* -o UserKnownHostsFile=/\S*/data/devvm/vms/[0-9a-f]{14}/run/known_hosts -o GlobalKnownHostsFile=/dev/null -o HostKeyAlias=devvm-web-[0-9a-f]{14} -o StrictHostKeyChecking=yes .* -o ForwardAgent=no .* -o ClearAllForwardings=yes .* -p 60022 -l stub 127\.0\.0\.1 git -c uploadpack\.allowAnySHA1InWant=true upload-pack ''/\S*/web''$'
# Opened again: not copied again. --clone on it is fine.
stub_reset
exec devvm --clone
! stdout 'copying_branches|clone_ready'
stub_calls
! stdout '^ssh '
# rm: nothing unfetched, and the one uncommitted change is the copied
# one, still as it came, though it's undone here since: deleted, and the
# remote removed.
exec git checkout -q -- tracked
exec devvm rm --force
stdout '^==> deleted vm=devvm-web-[0-9a-f]{14}$'
stdout '^==> removed_remote remote=devvm$'
! exec git remote get-url devvm
# devvm is another repo's: the next free name is devvm-<folder>. The VM's
# own commit isn't fetched: without a terminal rm refuses and keeps it.
rm $STUB_DIR/vmfs
exec git remote add devvm https://example.com/other.git
exec devvm --clone --network open
stdout '^==> clone_ready branch=main remote=devvm-web$'
exec git remote get-url devvm
stdout '^https://example.com/other.git$'
exec sh -c 'git -C "$STUB_DIR/vmfs$(pwd -P)" commit -q --allow-empty -m from-vm'
! exec devvm rm --force
stdout '^unfetched_commits refs="main"$'
stderr '^devvm: no_terminal_fetch command=devvm rm$'
vm_name WEB web
exec git remote get-url devvm-web
# Fetched: rm then finds uncommitted changes in the clone, shows them,
# and without a terminal keeps the VM.
exec git fetch -q devvm-web
exec git log --format=%s -1 devvm-web/main
stdout '^from-vm$'
exec sh -c 'echo z > "$STUB_DIR/vmfs$(pwd -P)/new"'
! exec devvm rm --force
! stdout unfetched_commits
stdout '^clone_dirty$'
stdout '^\?\? new$'
stderr '^devvm: no_terminal_delete command=devvm rm$'
exec git remote get-url devvm-web
# A clean clone with a worktree in it that has uncommitted changes: rm
# shows them under the worktree's path, and without a terminal keeps the
# VM.
exec sh -c 'c="$STUB_DIR/vmfs$(pwd -P)"; rm "$c/new" && git -C "$c" worktree add -q .worktrees/a && echo .worktrees/ >> "$c/.git/info/exclude" && echo w > "$c/.worktrees/a/w"'
! exec devvm rm --force
! stdout 'unfetched_commits|clone_dirty$'
stdout '^clone_worktree_dirty path=/\S*/web/\.worktrees/a$'
stdout '^\?\? w$'
stderr '^devvm: no_terminal_delete command=devvm rm$'
# --force never skips the checks: with the worktree's change still there,
# rm keeps the VM. A check that can't read the clone keeps it too, naming
# --no-clone-check, which deletes it unchecked after a warning, the
# worktree's change with it; a remote the user pointed elsewhere stays.
! exec devvm rm --force --no-export
stderr '^devvm: no_terminal_delete command=devvm rm$'
exec sh -c 'mv "$STUB_DIR/vmfs" "$STUB_DIR/vmfs.away"'
! exec devvm rm --force
stderr '^devvm: clone_check_failed command=devvm rm vm=devvm-web-[0-9a-f]{14}$'
exec sh -c 'mv "$STUB_DIR/vmfs.away" "$STUB_DIR/vmfs"'
exec git remote set-url devvm-web https://example.com/mine.git
exec devvm rm --force --no-clone-check
stderr '^devvm: clone_check_skipped command=devvm rm vm=devvm-web-[0-9a-f]{14}$'
! stdout 'unfetched_commits|clone_dirty|clone_worktree_dirty'
stdout '^==> deleted vm=devvm-web-[0-9a-f]{14}$'
! stdout removed_remote
exec git remote get-url devvm-web
stdout '^https://example.com/mine.git$'
exec git remote remove devvm-web
exec git remote remove devvm
# Copying fails (the VM's command applying it fails): the VM stays
# unseeded, and the next launch copies again.
rm $STUB_DIR/vmfs
exec sh -c 'echo index-pack > "$STUB_DIR/shell-fails-on"'
! exec devvm --clone --network open
stderr '^devvm: clone_seed_failed vm=devvm-web-[0-9a-f]{14}$'
! exec git remote get-url devvm
rm $STUB_DIR/shell-fails-on
exec devvm
stdout '^==> clone_ready branch=main remote=devvm$'
# rm --force: the VM's work fetched only into devvm/* is kept as new local
# branches under saved/devvm, then the remote goes with its
# remote-tracking branches.
exec sh -c 'git -C "$STUB_DIR/vmfs$(pwd -P)" commit -q --allow-empty -m from-vm-2'
exec git fetch -q devvm
exec devvm rm --force --no-export
stdout '^==> saved_branches branches="saved/devvm/main"$'
stdout '^==> removed_remote remote=devvm$'
exec git log --format=%s -1 saved/devvm/main
stdout '^from-vm-2$'
exec git for-each-ref refs/remotes
! stdout .
exec git branch -D saved/devvm/main
# A VM that mounts the folder: --clone on it is refused.
exec devvm --network open --no-git-protect
! exec devvm --clone
stderr '^devvm: clone_needs_new_vm vm=devvm-web-[0-9a-f]{14}$'
exec devvm rm --force --no-export
-- vm-branches --
main
main
other
y