|
|
|
@@ -2,7 +2,9 @@ package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/buildstep"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
"sync"
|
|
|
|
@@ -50,10 +52,15 @@ func TestTwoFetchesOfARepositoryUseOneMirrorAndReferenceIt(t *testing.T) {
|
|
|
|
|
if updates != 2 {
|
|
|
|
|
t.Errorf("the mirror %s was updated %d times, want 2:\n%s", mirror, updates, strings.Join(f.lines(), "\n"))
|
|
|
|
|
}
|
|
|
|
|
// The fake git writes nothing, so the alternates file the SDK wrote stands until the fetch dissociates: it is gone
|
|
|
|
|
// at the end and git repack -a -d ran in each tree.
|
|
|
|
|
for _, ws := range workspaces {
|
|
|
|
|
raw, err := os.ReadFile(filepath.Join(m.Work, ws, "tree", ".git", "objects", "info", "alternates"))
|
|
|
|
|
if err != nil || strings.TrimSpace(string(raw)) != filepath.Join(mirror, "objects") {
|
|
|
|
|
t.Errorf("the alternates of %s are %q (%v)", ws, raw, err)
|
|
|
|
|
tree := filepath.Join(m.Work, ws, "tree")
|
|
|
|
|
if _, err := os.Stat(filepath.Join(tree, ".git", "objects", "info", "alternates")); err == nil {
|
|
|
|
|
t.Errorf("the workspace %s still borrows from the mirror", ws)
|
|
|
|
|
}
|
|
|
|
|
if !strings.Contains(strings.Join(f.lines(), "\n"), "-C "+tree+" repack -a -d") {
|
|
|
|
|
t.Errorf("git repack -a -d did not run in %s", tree)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -71,9 +78,8 @@ func TestASiblingIsPlacedThroughItsOwnMirror(t *testing.T) {
|
|
|
|
|
t.Errorf("the mirror of %s was not updated", repo)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
raw, _ := os.ReadFile(filepath.Join(m.Work, ws, "beside", "mesh-sdk", ".git", "objects", "info", "alternates"))
|
|
|
|
|
if strings.TrimSpace(string(raw)) != filepath.Join(m.Cache, "mirror", "novox", "mesh-sdk.git", "objects") {
|
|
|
|
|
t.Errorf("the sibling's alternates are %q", raw)
|
|
|
|
|
if _, err := os.Stat(filepath.Join(m.Work, ws, "beside", "mesh-sdk", ".git", "objects", "info", "alternates")); err == nil {
|
|
|
|
|
t.Errorf("the sibling still borrows from the mirror")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -132,3 +138,53 @@ func TestAMirrorThatCannotBeUpdatedLetsTheFetchGoOnWithoutIt(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sleepABit() { time.Sleep(30 * time.Millisecond) }
|
|
|
|
|
|
|
|
|
|
// The workspace is self-contained after the fetch: no alternates file, and git finds the commit with the mirror gone,
|
|
|
|
|
// as a step shut off with the workspace alone needs. Real git, a local repository as the forge.
|
|
|
|
|
func TestTheWorkspaceIsSelfContainedAfterAFetchThroughTheMirror(t *testing.T) {
|
|
|
|
|
if _, err := exec.LookPath("git"); err != nil {
|
|
|
|
|
t.Skip("no git")
|
|
|
|
|
}
|
|
|
|
|
forge := t.TempDir()
|
|
|
|
|
src := filepath.Join(forge, "novox", "mesh-sdk.git")
|
|
|
|
|
if err := os.MkdirAll(src, 0o755); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
git := func(dir string, args ...string) string {
|
|
|
|
|
cmd := exec.Command("git", append([]string{"-C", dir, "-c", "user.name=t", "-c", "user.email=t@example.org", "-c", "commit.gpgsign=false"}, args...)...)
|
|
|
|
|
cmd.Env = append(os.Environ(), "GIT_CONFIG_GLOBAL=/dev/null")
|
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("git %v: %v %s", args, err, out)
|
|
|
|
|
}
|
|
|
|
|
return strings.TrimSpace(string(out))
|
|
|
|
|
}
|
|
|
|
|
git(src, "init", "-q")
|
|
|
|
|
if err := os.WriteFile(filepath.Join(src, "f.txt"), []byte("one\n"), 0o644); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
git(src, "add", ".")
|
|
|
|
|
git(src, "commit", "-q", "-m", "one")
|
|
|
|
|
commit := git(src, "rev-parse", "HEAD")
|
|
|
|
|
|
|
|
|
|
states := newStates()
|
|
|
|
|
m := moduleWith(states, "go1.27.1")
|
|
|
|
|
m.Home, m.Work, m.Cache = t.TempDir(), t.TempDir(), t.TempDir()
|
|
|
|
|
m.Run = StepRunner(m.Home)
|
|
|
|
|
m.RemoteBase = "file://" + forge + "/"
|
|
|
|
|
m.FetchOptions = []buildstep.Option{buildstep.AllowFileRemote()}
|
|
|
|
|
ws := fetchOnce(t, m, states, map[string]any{"repository": "novox/mesh-sdk", "commit": commit}).Workspace
|
|
|
|
|
tree := filepath.Join(m.Work, ws, "tree")
|
|
|
|
|
if _, err := os.Stat(filepath.Join(tree, ".git", "objects", "info", "alternates")); err == nil {
|
|
|
|
|
t.Errorf("the workspace still has an alternates file")
|
|
|
|
|
}
|
|
|
|
|
if err := os.RemoveAll(filepath.Join(m.Cache, "mirror")); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if out, err := exec.Command("git", "-C", tree, "cat-file", "-e", commit+"^{commit}").CombinedOutput(); err != nil {
|
|
|
|
|
t.Errorf("git does not find the commit with the mirror gone: %v %s", err, out)
|
|
|
|
|
}
|
|
|
|
|
if out, err := exec.Command("git", "-C", tree, "fsck", "--connectivity-only").CombinedOutput(); err != nil {
|
|
|
|
|
t.Errorf("the workspace is not whole: %v %s", err, out)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|