aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-07 11:45:43 +0000
committerGravatar Runxi Yu2026-06-07 11:45:43 +0000
commitfcc8ca4353e9ec38ad74a912216b96b958291950 (patch)
tree8162b63eeef79ee1feb460a5a27b7b5eddc27b1b /internal/testgit
parentobject/tree/mode: Other tests (diff)
signatureNo signature
internal/testgit: Add UpdateRef and ForEachRefFormat
Diffstat (limited to 'internal/testgit')
-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
+}