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

import (
	"testing"

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

// CommitTree creates a commit from a tree and message, optionally with parents.
func (repo *TestRepo) CommitTree(tb testing.TB, tree oid.ObjectID, message string, parents ...oid.ObjectID) oid.ObjectID {
	tb.Helper()
	args := []string{"commit-tree", tree.String()}
	for _, p := range parents {
		args = append(args, "-p", p.String())
	}
	args = append(args, "-m", message)
	hex := repo.Run(tb, args...)
	id, err := oid.ParseHex(repo.algo, hex)
	if err != nil {
		tb.Fatalf("parse commit-tree output %q: %v", hex, err)
	}
	return id
}