diff options
| author | 2026-05-24 09:29:34 +0000 | |
|---|---|---|
| committer | 2026-05-24 09:29:34 +0000 | |
| commit | 748b4e5c3b6e11e10b6a302df8a140bacb7d4eef (patch) | |
| tree | 4609fd9ac7fe484768cc4f85f34e90f72fffe836 /internal/testgit/object.go | |
| parent | README, CONTRIBUTING: Simplify (diff) | |
| signature | No signature | |
internal/testgit: Init
Diffstat (limited to 'internal/testgit/object.go')
| -rw-r--r-- | internal/testgit/object.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/internal/testgit/object.go b/internal/testgit/object.go new file mode 100644 index 00000000..0ea4d4d8 --- /dev/null +++ b/internal/testgit/object.go @@ -0,0 +1,27 @@ +package testgit + +import ( + "io" + "testing" + + "codeberg.org/lindenii/furgit/object/id" + "codeberg.org/lindenii/furgit/object/typ" +) + +// 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 { + tb.Helper() + cmd := repo.Command(tb, "git", "hash-object", "-t", ty.Name(), "-w", "--stdin", "--literally") + + hex, err := cmd.CombinedOutput() + if err != nil { + tb.Fatalf("hash-object: %v", hex) + } + + id, err := id.FromHex(repo.algo, string(hex)) + if err != nil { + tb.Fatalf("parse git hash-object output %q: %v", hex, err) + } + + return id +} |
