From fcc8ca4353e9ec38ad74a912216b96b958291950 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 7 Jun 2026 11:45:43 +0000 Subject: internal/testgit: Add UpdateRef and ForEachRefFormat --- internal/testgit/ref.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 internal/testgit/ref.go (limited to 'internal/testgit/ref.go') diff --git a/internal/testgit/ref.go b/internal/testgit/ref.go new file mode 100644 index 00000000..ae564acc --- /dev/null +++ b/internal/testgit/ref.go @@ -0,0 +1,32 @@ +package testgit + +import ( + "fmt" + "testing" + + "lindenii.org/go/furgit/object/id" +) + +// UpdateRef points a ref at an object so that ref-aware tooling can see it. +func (repo *Repo) UpdateRef(tb testing.TB, name string, oid id.ObjectID) error { + tb.Helper() + + _, err := repo.run(tb, nil, "git", "update-ref", "--end-of-options", name, oid.String()) + if err != nil { + return fmt.Errorf("update-ref %s %s: %w", name, oid, err) + } + + return nil +} + +// ForEachRefFormat returns git-for-each-ref output for one ref and one format. +func (repo *Repo) ForEachRefFormat(tb testing.TB, pattern string, format string) ([]byte, error) { + tb.Helper() + + stdout, err := repo.run(tb, nil, "git", "for-each-ref", "--format="+format, "--end-of-options", pattern) + if err != nil { + return nil, fmt.Errorf("for-each-ref --format=%q %s: %w", format, pattern, err) + } + + return stdout, nil +} -- cgit v1.3.1-10-gc9f91