diff options
Diffstat (limited to 'internal/testgit/object.go')
| -rw-r--r-- | internal/testgit/object.go | 12 |
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 } |
