aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/repo_hash_object.go
blob: 75f1a7ab636798e2b8fa6350150a29b8c71327ed (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package testgit

import (
	"testing"

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

// HashObject hashes and writes an object and returns its object ID.
func (testRepo *TestRepo) HashObject(tb testing.TB, objType string, body []byte) objectid.ObjectID {
	tb.Helper()
	hex := testRepo.RunInput(tb, body, "hash-object", "-t", objType, "-w", "--stdin")

	id, err := objectid.ParseHex(testRepo.algo, hex)
	if err != nil {
		tb.Fatalf("parse git hash-object output %q: %v", hex, err)
	}

	return id
}