From 0fad4fe5e59a7d908ce62b80b7a14a7c74149ec5 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 11 Jun 2026 13:03:56 +0000 Subject: internal/testgit: packobjects, verifypack --- internal/testgit/packobjects.go | 47 +++++++++++++++++++++++++++++++++++++++++ internal/testgit/verifypack.go | 13 ++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 internal/testgit/packobjects.go create mode 100644 internal/testgit/verifypack.go (limited to 'internal/testgit') diff --git a/internal/testgit/packobjects.go b/internal/testgit/packobjects.go new file mode 100644 index 00000000..9f56eef0 --- /dev/null +++ b/internal/testgit/packobjects.go @@ -0,0 +1,47 @@ +package testgit + +import ( + "bytes" + "iter" + "path/filepath" + "strings" + "testing" + + "lindenii.org/go/furgit/object/id" +) + +// PackObjectsOptions controls one pack-objects invocation. +type PackObjectsOptions struct { + // RevIndex requests writing a .rev reverse index alongside the pack. + RevIndex bool +} + +// PackObjects packs the supplied objects with git pack-objects +// into a temporary directory, +// and returns the artifact path prefix "/pack-", +// to which ".pack", ".idx", and ".rev" suffixes apply. +func (repo *Repo) PackObjects(tb testing.TB, oids iter.Seq[id.ObjectID], opts PackObjectsOptions) (string, error) { + tb.Helper() + + dir := tb.TempDir() + + var stdin bytes.Buffer + for oid := range oids { + stdin.WriteString(oid.String()) + stdin.WriteByte('\n') + } + + revIndex := "false" + if opts.RevIndex { + revIndex = "true" + } + + out, err := repo.run(tb, &stdin, + "git", "-c", "pack.writeReverseIndex="+revIndex, + "pack-objects", "--end-of-options", filepath.Join(dir, "pack")) + if err != nil { + return "", err + } + + return filepath.Join(dir, "pack-"+strings.TrimSpace(string(out))), nil +} diff --git a/internal/testgit/verifypack.go b/internal/testgit/verifypack.go new file mode 100644 index 00000000..ec59572a --- /dev/null +++ b/internal/testgit/verifypack.go @@ -0,0 +1,13 @@ +package testgit + +import ( + "testing" +) + +// VerifyPack runs git verify-pack -v on one pack index path +// and returns its raw verbose output. +func (repo *Repo) VerifyPack(tb testing.TB, idxPath string) ([]byte, error) { + tb.Helper() + + return repo.run(tb, nil, "git", "verify-pack", "-v", "--end-of-options", idxPath) +} -- cgit v1.3.1-10-gc9f91