aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/ref.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/testgit/ref.go')
-rw-r--r--internal/testgit/ref.go32
1 files changed, 32 insertions, 0 deletions
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
+}