shithub: furgit

ref: 5d84c4a2716c9dec5f9fcfcce4ca7f8a65cad3ff
dir: /internal/testgit/repo_hash_object.go/

View raw version
package testgit

import (
	"testing"

	"codeberg.org/lindenii/furgit/objectid"
)

// HashObject hashes and writes an object and returns its object ID.
func (repo *TestRepo) HashObject(tb testing.TB, objType string, body []byte) objectid.ObjectID {
	tb.Helper()
	hex := repo.RunInput(tb, body, "hash-object", "-t", objType, "-w", "--stdin")
	id, err := objectid.ParseHex(repo.algo, hex)
	if err != nil {
		tb.Fatalf("parse git hash-object output %q: %v", hex, err)
	}
	return id
}