aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/repo_hash_object.go
blob: b21e12313b55372bbaa78dba16c4f3a948a03a1e (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
}