//go:build integration package buildstep import ( "context" "os" "path/filepath" "strings" "testing" "git.novox.be/novox/mesh-sdk/go/forgekey" ) // Issue 890 C1 (AC3): a mirror brought to two commits in turn; a fetch through it checks out each commit, the // alternates name the mirror, and no symlink is in the workspace. func TestMirrorServesTwoCommitsWithoutSymlinks(t *testing.T) { root := t.TempDir() src := filepath.Join(root, "src.git") work := filepath.Join(root, "work") for _, d := range []string{src, work} { if err := os.MkdirAll(d, 0o755); err != nil { t.Fatal(err) } } gitIn(t, src, "init", "-q", "--bare") gitIn(t, work, "init", "-q") var commits []string for _, c := range []string{"one", "two"} { if err := os.WriteFile(filepath.Join(work, "f"), []byte(c), 0o644); err != nil { t.Fatal(err) } gitIn(t, work, "add", "f") gitIn(t, work, "commit", "-q", "-m", c) commits = append(commits, gitIn(t, work, "rev-parse", "HEAD")) gitIn(t, work, "push", "-q", src, "HEAD:refs/heads/main") } remote := "file://" + src mirror := filepath.Join(root, "mirror.git") for i, commit := range commits { if err := UpdateMirror(context.Background(), forgekey.ExecRunner, mirror, remote, commit, "", AllowFileRemote()); err != nil { t.Fatal(err) } ws := filepath.Join(root, "ws"+string(rune('0'+i))) if err := os.MkdirAll(ws, 0o755); err != nil { t.Fatal(err) } if err := FetchCommit(context.Background(), forgekey.ExecRunner, ws, remote, commit, "", AllowFileRemote(), WithMirror(mirror)); err != nil { t.Fatal(err) } if head := gitIn(t, ws, "rev-parse", "HEAD"); head != commit { t.Errorf("HEAD = %s, want %s", head, commit) } b, _ := os.ReadFile(filepath.Join(ws, ".git", "objects", "info", "alternates")) if !strings.Contains(string(b), filepath.Join(mirror, "objects")) { t.Errorf("alternates %q", b) } _ = filepath.Walk(ws, func(p string, fi os.FileInfo, err error) error { if err == nil && fi.Mode()&os.ModeSymlink != 0 { t.Errorf("symlink %s", p) } return nil }) } }