ref: ab174c473618dd3743881cf44e02c2db4d1ecd5f
dir: /internal/testgit/repo_from_fixture.go/
package testgit
import (
"io/fs"
"os"
"testing"
objectid "codeberg.org/lindenii/furgit/object/id"
)
// NewRepoFromFixture copies one existing repository fixture into a temp dir.
func NewRepoFromFixture(tb testing.TB, algo objectid.Algorithm, fixtureDir string) *TestRepo {
tb.Helper()
if algo.Size() == 0 {
tb.Fatalf("invalid algorithm: %v", algo)
}
dst := tb.TempDir()
srcFS := os.DirFS(fixtureDir)
err := copyFS(dst, srcFS)
if err != nil {
tb.Fatalf("copy fixture %q: %v", fixtureDir, err)
}
return &TestRepo{
dir: dst,
algo: algo,
env: defaultEnv(),
}
}
func copyFS(dst string, src fs.FS) error {
return os.CopyFS(dst, src)
}