aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/repo_hash_object.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-02-20 21:19:47 +0800
committerGravatar Runxi Yu2026-02-20 21:34:42 +0800
commit05e07f6c6aca1662c33359f41c66e6f9b6eb935a (patch)
tree6928a76783b2230a010c36d53b8da48ff24d611f /internal/testgit/repo_hash_object.go
parentoid: Add ObjectID (diff)
testgit: Add test harnesses
Diffstat (limited to 'internal/testgit/repo_hash_object.go')
-rw-r--r--internal/testgit/repo_hash_object.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/testgit/repo_hash_object.go b/internal/testgit/repo_hash_object.go
new file mode 100644
index 00000000..97a86be5
--- /dev/null
+++ b/internal/testgit/repo_hash_object.go
@@ -0,0 +1,18 @@
+package testgit
+
+import (
+ "testing"
+
+ "codeberg.org/lindenii/furgit/oid"
+)
+
+// HashObject hashes and writes an object and returns its object ID.
+func (repo *TestRepo) HashObject(tb testing.TB, objType string, body []byte) oid.ObjectID {
+ tb.Helper()
+ hex := repo.RunInput(tb, body, "hash-object", "-t", objType, "-w", "--stdin")
+ id, err := oid.ParseHex(repo.algo, hex)
+ if err != nil {
+ tb.Fatalf("parse git hash-object output %q: %v", hex, err)
+ }
+ return id
+}