Files
devvm/tests/e2e/clonepartial_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

101 lines
3.6 KiB
Go

//go:build e2e
package e2e
import (
"errors"
"strings"
"github.com/devvmhq/devvm/internal/shell"
)
// partialRemote is a small public repo with more than one commit, whose
// old blobs a blob:none clone lacks.
const partialRemote = "https://github.com/octocat/Spoon-Knife.git"
// partialTitles are clonePartial's checks.
func partialTitles() []string {
return []string{
"a partial clone's VM fetches a blob it lacks from the repo's origin when it needs it",
"fetching back work that needs a blob the VM's partial clone lacks says what to do, and works once the VM has it",
}
}
// clonePartial: a blob:none clone of a public repo, on the internet tier:
// the VM's clone is a promisor clone, and its git fetches a blob the
// clone lacks from the repo's origin when a command needs it. Work in the
// VM that names another such blob doesn't come back, as the VM's
// upload-pack fetches nothing to send it, and devvm says what to do; once
// git in the VM has read the blob, it does. Skipped when github.com
// can't be reached.
func clonePartial(s *S, g cloneGit) {
d, err := s.NewProject("cloned-partial")
if err == nil {
if _, cerr := g.git(d, "clone", "-q", "--filter=blob:none", partialRemote, "."); cerr != nil {
for _, title := range partialTitles() {
s.Skip(title, "github.com can't be reached: "+cerr.Error())
}
return
}
}
var missing []string
if err == nil {
// Blobs of the history the clone hasn't fetched (?SHA).
var r Res
if r, err = g.git(d, "rev-list", "--objects", "--missing=print", "--all"); err == nil {
for line := range strings.Lines(r.Stdout) {
if sha, ok := strings.CutPrefix(strings.TrimSpace(line), "?"); ok {
missing = append(missing, sha)
}
}
}
}
var vm string
if err == nil {
_, _ = g.devvm(d, "pwd\n", "--clone", "--network", "internet")
vm = g.made(d)
}
in := "cd " + shell.Quote(d) + " && "
s.Check(partialTitles()[0], func() error {
switch {
case err != nil:
return err
case len(missing) < 2:
return errors.New("the partial clone lacks fewer than two blobs")
case vm == "":
return errors.New("no VM was made")
}
r, err := s.InVM(vm, in+"git config remote.origin.promisor && git cat-file -t "+missing[0])
if err != nil || !HasLine(r.Stdout, "true") || !HasLine(r.Stdout, "blob") {
return errors.New("the VM's clone didn't fetch the missing blob from origin:\n" + r.Out)
}
return nil
})
s.Check(partialTitles()[1], func() error {
if err != nil || len(missing) < 2 || vm == "" {
return errors.New("no partial clone in a VM")
}
// A commit whose tree names a blob neither side has.
mk := in + "t=$(printf '100644 blob %s\\tcopy\\n' " + missing[1] + " | git mktree --missing) && " +
"c=$(git -c user.name=e -c user.email=e@e commit-tree \"$t\" -p HEAD -m needs-blob) && git update-ref refs/heads/needs-blob \"$c\""
if r, err := s.InVM(vm, mk); err != nil {
return errors.New("making the commit: " + r.Out)
}
r, _ := g.devvm(d, "", "clone", "fetch")
if !g.said(r, "clone_fetch_partial", "path=.") {
return errors.New("devvm clone fetch didn't say the VM lacked an object:\n" + r.Out)
}
if r, err := s.InVM(vm, in+"git cat-file -t "+missing[1]); err != nil || !HasLine(r.Stdout, "blob") {
return errors.New("the VM's git didn't fetch the blob:\n" + r.Out)
}
if r, err := g.devvm(d, "", "clone", "fetch"); err != nil {
return errors.New("devvm clone fetch failed once the VM had the blob:\n" + r.Out)
}
if _, err := g.git(d, "rev-parse", "--verify", "devvm/needs-blob"); err != nil {
return errors.New("the VM's work didn't come back")
}
return nil
})
_, _ = g.devvm(d, "", "rm", "--force", "--no-export", "--no-clone-check")
}