aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/object.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-06-06 17:45:29 +0000
committerGravatar Runxi Yu2026-06-06 17:45:29 +0000
commit2c79eaae593f5669f5f596337f5ac98492cc1127 (patch)
tree7b6dccf1689110a7d865b8a46f9d72b3ac058f6d /internal/testgit/object.go
parentinternal/testgit: hash-object and command (diff)
signatureNo signature
testgit: Add config support
Diffstat (limited to 'internal/testgit/object.go')
-rw-r--r--internal/testgit/object.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/internal/testgit/object.go b/internal/testgit/object.go
index 6f1a2dd8..a5f7163b 100644
--- a/internal/testgit/object.go
+++ b/internal/testgit/object.go
@@ -1,7 +1,9 @@
package testgit
import (
+ "fmt"
"io"
+ "strings"
"testing"
"lindenii.org/go/furgit/object/id"
@@ -10,18 +12,18 @@ import (
// HashObject hashes and writes an object,
// and returns its object ID.
-func (repo *Repo) HashObject(tb testing.TB, ty typ.Type, body io.Reader) id.ObjectID {
+func (repo *Repo) HashObject(tb testing.TB, ty typ.Type, body io.Reader) (id.ObjectID, error) {
tb.Helper()
stdout, err := repo.Run(tb, body, "git", "hash-object", "-t", ty.Name(), "-w", "--stdin", "--literally")
if err != nil {
- tb.Fatalf("hash-object: %v", err)
+ return id.ObjectID{}, fmt.Errorf("hash-object: %w", err)
}
- id, err := repo.objectFormat.FromString(string(stdout))
+ objectID, err := repo.objectFormat.FromString(strings.TrimSuffix(string(stdout), "\n"))
if err != nil {
- tb.Fatalf("parse git hash-object output %q: %v", string(stdout), err)
+ return id.ObjectID{}, fmt.Errorf("parse git hash-object output %q: %w", string(stdout), err)
}
- return id
+ return objectID, nil
}