Files
devvm/testdata/script/clone_inprogress.txtar
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

97 lines
4.4 KiB
Plaintext

# --clone of a repo in the middle of a rebase stopped on a conflict,
# started with --autostash, with a stash of two entries, one of them git
# stash --all's: the VM's clone is in the same rebase, git rebase
# --continue there finishes it and brings the autostashed change back, and
# its stash is this repo's but for the --all entry, which holds ignored
# files and is named. Then rm names the VM's own stash entry, never the
# ones copied in, and once devvm clone fetch has saved it as
# saved/devvm/stash-0, rm without a terminal deletes the VM. (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
cd $WORK/web
exec git init -q -b main
exec git add .
exec git commit -q -m base
exec git checkout -q -b topic
exec sh -c 'echo topic > f && git commit -q -am topic'
exec git checkout -q main
exec sh -c 'echo main > f && git commit -q -am main'
exec git checkout -q topic
exec sh -c 'echo one > g && git stash push -q -m one'
exec sh -c 'echo secret > x.log && echo all > g && git stash push -q --all -m all'
exec sh -c 'echo wip > g'
! exec git rebase --autostash main
exec git status --short
stdout '^UU f$'
exec devvm --clone --network open
stderr '^devvm: clone_stash_all_kept count=1 dir=/\S*/web entries="stash@\{0\}"$'
stdout '^==> clone_ready_detached remote=devvm$'
exec sh -c 'cd "$STUB_DIR/vmfs$(pwd -P)" && git status --short && git stash list --format=%gs && test ! -e x.log && echo no-log'
stdout '^UU f$'
stdout '^On topic: one$'
! stdout 'On topic: all'
stdout '^no-log$'
exec sh -c 'cd "$STUB_DIR/vmfs$(pwd -P)" && echo resolved > f && git add f && git -c core.editor=true rebase --continue >/dev/null 2>&1 && git log --format=%s -2 && cat g'
stdout '^topic\nmain\nwip$'
# rm and clone off: the stash entry the VM made is its work, as is the
# rebased topic; the entry copied in isn't. (internal/vm's
# TestRmFetchesStash fetches one, which needs a yes.)
exec sh -c 'cd "$STUB_DIR/vmfs$(pwd -P)" && git checkout -q -- . && echo vm > g && echo planted > site.pth && git stash push -q -u -m mine'
! exec devvm rm --force --no-export
stdout '^unfetched_commits refs="topic" "stash-0"$'
stderr '^devvm: no_terminal_fetch command=devvm rm$'
! stdout 'stash-1'
! exec devvm clone off --force --no-input
stderr 'no_terminal_fetch'
# devvm clone fetch, as the refusal says: the rebased topic as devvm/topic,
# the VM's stash entry as saved/devvm/stash-0, not the one copied in; the
# JSON names it. Its untracked file, which git ignores here, goes apart, to
# saved/devvm/stash-0-untracked, named, so git stash apply doesn't write
# it. Then rm finds nothing to lose.
exec sh -c 'echo "*.pth" >> .git/info/exclude'
exec devvm clone fetch --json
stdout '"saved": \[\n\s+"saved/devvm/stash-0"\n\s+\]'
! stdout 'stash-1'
stderr '^devvm: clone_stash_untracked branch=saved/devvm/stash-0 count=1 files="site.pth" untracked=saved/devvm/stash-0-untracked$'
stderr '^devvm: clone_stash_untracked_ignored count=1 files="site.pth" untracked=saved/devvm/stash-0-untracked$'
exec git stash list --format=%gs
stdout '^On topic: one$'
exec sh -c 'git log --format=%s -1 saved/devvm/stash-0 && git rev-parse saved/devvm/stash-0^2 >/dev/null && ! git rev-parse -q --verify saved/devvm/stash-0^3 && git show --name-only --format= saved/devvm/stash-0-untracked'
stdout '^On topic: mine$'
stdout '^site\.pth$'
exec git stash show --include-untracked --name-only saved/devvm/stash-0
stdout '^g$'
! stdout site.pth
exec devvm rm --force --no-export
stdout '^==> deleted vm=devvm-web-[0-9a-f]{14}$'
# A cherry-pick of two commits stopped on the first, whose second only
# its todo list names, which no ref reaches: the VM's clone lacks it, and
# devvm names it, as that step will fail there.
cd $WORK/pick
exec git init -q -b main
exec git add .
exec git commit -q -m base
exec git checkout -q -b gone
exec sh -c 'echo gone > f && git commit -q -am gone && echo later > h && git add h && git commit -q -m later'
exec sh -c 'git rev-parse --short HEAD > $WORK/later && git rev-parse HEAD~ > $WORK/first'
exec git checkout -q main
exec git branch -q -D gone
exec sh -c 'echo main > f && git commit -q -am main'
! exec sh -c 'git cherry-pick $(cat $WORK/first) $(cat $WORK/later)'
exec devvm --clone --network open
stderr '^devvm: clone_todo_missing commits="[0-9a-f]+" count=1 dir=/\S*/pick$'
exec devvm rm --force --no-export --no-clone-check
-- pick/f --
base
-- web/f --
base
-- web/g --
g
-- web/.gitignore --
*.log