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

110 lines
3.8 KiB
Plaintext

# --clone copies the repo's uncommitted changes: what's staged, as the
# index has it, and what isn't, deletions and intent-to-add files
# included, so git status in the VM's clone matches this one's. Untracked
# and ignored files stay on this machine, and so does anything below a
# tracked file that became a folder, or in an embedded repo, whose .git
# never goes. A file a filter (git-crypt, say) changes goes as git stores
# it, and devvm says it may differ. (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 config filter.rot.clean 'tr a-z n-za-m'
exec git config filter.rot.smudge 'tr a-z n-za-m'
exec ln -s a link
exec git add .
exec git commit -q -m one
exec git init -q -b main emb
exec git -C emb commit -q --allow-empty -m e
exec git -C emb remote add origin https://u:[email protected]/x/emb.git
# The changes: staged a, unstaged b, deleted c, intent-to-add n, a link
# changed, a filtered file changed, foo turned into a folder, an embedded
# repo staged with an untracked file in it; .env untracked.
exec sh -c 'echo staged > a && git add a && echo unstaged > b && rm c && echo new > n && git add -N n'
exec sh -c 'rm link && ln -s b link && echo changed > secret'
exec sh -c 'rm foo && mkdir foo && echo AWS=topsecret > foo/.env'
exec sh -c 'echo LIBSECRET=x > emb/.env && git add emb 2>/dev/null; echo SECRET=1 > .env'
exec sh -c 'git update-index --skip-worktree local.yml && echo password=hidden > local.yml'
exec git status --porcelain --untracked-files=no
cmp stdout $WORK/host-status
exec devvm --clone --network open
stderr '^devvm: clone_filtered_kept count=1 dir=/\S*/web files="secret"$'
stderr '^devvm: clone_typechange_kept count=1 dir=/\S*/web files="foo"$'
stderr '^devvm: clone_skip_worktree_kept count=1 dir=/\S*/web files="local.yml"$'
! stderr 'uncommitted_not_copied|clone_kept_files'
stdout '^==> clone_ready branch=main remote=devvm$'
# In the VM: the same status but foo, which is gone there; a, b, n as
# here; secret as git stores it; link the new link; none of .env,
# foo/.env, emb/.env or emb/.git.
exec sh -c 'cd "$STUB_DIR/vmfs$(pwd -P)" && git status --porcelain --untracked-files=no'
cmp stdout $WORK/vm-status
exec sh -c 'c="$STUB_DIR/vmfs$(pwd -P)"; cat "$c/a" "$c/b" "$c/n" "$c/secret"; readlink "$c/link"; git -C "$c" diff --cached --name-only'
cmp stdout $WORK/vm-files
exec sh -c 'c="$STUB_DIR/vmfs$(pwd -P)"; ls -a "$c" "$c/emb"'
! stdout '\.env'
exec sh -c 'c="$STUB_DIR/vmfs$(pwd -P)"; test ! -e "$c/foo" && test ! -e "$c/emb/.git" && test ! -e "$c/.env" && echo clean'
stdout '^clean$'
exec sh -c 'grep -r EMBTOKEN "$STUB_DIR/vmfs" || echo none'
stdout '^none$'
# local.yml, skip-worktree here, is in the VM as the index has it.
exec sh -c 'cat "$STUB_DIR/vmfs$(pwd -P)/local.yml"'
stdout '^committed$'
# rm: the copied changes aren't the VM's work while the VM leaves them as
# they came, even once they change here; b changed in the VM is, and rm
# without a terminal refuses, naming b alone.
exec sh -c 'echo again > b && echo more > a'
exec sh -c 'echo vm > "$STUB_DIR/vmfs$(pwd -P)/b"'
! exec devvm rm --force --no-export
stdout '^clone_dirty$'
stderr '^devvm: no_terminal_delete command=devvm rm$'
stdout '^ M b$'
! stdout '^(M a| D c|A emb| D foo| M link| A n)$'
exec sh -c 'git -C "$STUB_DIR/vmfs$(pwd -P)" checkout -q -- b'
exec devvm rm --force --no-export
stdout '^==> deleted vm='
-- web/a --
a
-- web/b --
b
-- web/c --
c
-- web/local.yml --
committed
-- web/foo --
foo
-- web/secret --
plaintext
-- web/.gitattributes --
secret filter=rot
-- host-status --
M a
M b
D c
A emb
D foo
M link
A n
M secret
-- vm-status --
M a
M b
D c
A emb
D foo
M link
A n
-- vm-files --
staged
unstaged
new
cynvagrkg
b
a
emb