Files
devvm/tests/e2e/clonesubmodules_test.go
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

111 lines
3.4 KiB
Go

//go:build e2e
package e2e
import (
"errors"
"path/filepath"
"strings"
"github.com/devvmhq/devvm/internal/shell"
)
// cloneSubmodules: a repo with a submodule that has one of its own, both
// initialised: in the VM, git submodule status --recursive is as here; a
// VM commit in the submodule comes back into the submodule's repo here
// with devvm clone fetch; and rm without a terminal names a commit in the
// nested submodule that wasn't fetched, and keeps the VM.
func cloneSubmodules(s *S, g cloneGit) {
deep, err := s.NewProject("cloned-sub-deep")
if err == nil {
err = g.repo(deep)
}
lib, lerr := s.NewProject("cloned-sub-lib")
if err == nil {
err = lerr
}
if err == nil {
err = g.repo(lib)
}
app, aerr := s.NewProject("cloned-sub-app")
if err == nil {
err = aerr
}
if err == nil {
err = g.repo(app)
}
file := []string{"-c", "protocol.file.allow=always"}
steps := []struct {
dir string
args []string
}{
{lib, append(file, "submodule", "add", "-q", "file://"+deep, "deep")},
{lib, []string{"commit", "-q", "-m", "deep"}},
{app, append(file, "submodule", "add", "-q", "file://"+lib, "lib")},
{app, []string{"commit", "-q", "-m", "lib"}},
{app, append(file, "submodule", "update", "-q", "--init", "--recursive")},
}
for _, st := range steps {
if err == nil {
_, err = g.git(st.dir, st.args...)
}
}
var vm, host string
if err == nil {
var r Res
if r, err = g.git(app, "submodule", "status", "--recursive"); err == nil {
host = r.Stdout
}
}
if err == nil {
_, _ = g.devvm(app, "pwd\n", "--clone", "--network", "open")
vm = g.made(app)
}
in := "cd " + shell.Quote(app) + " && "
s.Check("a repo's submodules, nested ones too, get clones of their own in the VM, as here", func() error {
switch {
case err != nil:
return err
case vm == "":
return errors.New("no VM was made")
}
r, err := s.InVM(vm, in+"git submodule status --recursive")
if err != nil || strings.TrimSpace(r.Stdout) != strings.TrimSpace(host) {
return errors.New("the VM's submodule status isn't this machine's:\n" + r.Out + "\nhere:\n" + host)
}
return nil
})
s.Check("a VM commit in a submodule comes back with devvm clone fetch, and rm names one in a nested submodule not fetched", func() error {
if vm == "" {
return errors.New("no VM was made")
}
commit := func(path, branch string) error {
_, err := s.InVM(vm, "cd "+shell.Quote(filepath.Join(app, path))+" && git checkout -q -b "+branch+" && git -c user.email=e@e -c user.name=e commit -q --allow-empty -m "+branch)
return err
}
if err := commit("lib", "vm-lib"); err != nil {
return err
}
if _, err := g.devvm(app, "", "clone", "fetch"); err != nil {
return err
}
if r, err := g.git(filepath.Join(app, "lib"), "log", "--format=%s", "-1", "devvm/vm-lib"); err != nil || strings.TrimSpace(r.Stdout) != "vm-lib" {
return errors.New("lib's VM commit didn't come back")
}
if err := commit(filepath.Join("lib", "deep"), "vm-deep"); err != nil {
return err
}
r, err := g.devvm(app, "", "rm", "--force")
switch {
case err == nil:
return errors.New("rm succeeded")
case !g.said(r, "unfetched_commits_in", `refs="vm-deep"`, "repo=lib/deep"):
return errors.New("rm didn't name the nested submodule's commit:\n" + r.Out)
case !g.listed(vm):
return errors.New(vm + " is gone")
}
return nil
})
_, _ = g.devvm(app, "", "rm", "--force", "--no-export", "--no-clone-check")
}