shithub: furgit

ref: b3b2d5057a55baf88cbaaa31234edd3fe5d30e7f
dir: /internal/testgit/repo_hash_object.go/

View raw version
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
}