aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/repo_commit_tree.go
blob: 763474c29ece2bfb593e8ae0c33b561e053510a4 (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
24
package testgit

import (
	"testing"

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

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