aboutsummaryrefslogtreecommitdiff
path: root/internal/testgit/ref.go
blob: ae564acc1333cba6a582df84e2bdef9e1a467104 (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
25
26
27
28
29
30
31
32
package testgit

import (
	"fmt"
	"testing"

	"lindenii.org/go/furgit/object/id"
)

// UpdateRef points a ref at an object so that ref-aware tooling can see it.
func (repo *Repo) UpdateRef(tb testing.TB, name string, oid id.ObjectID) error {
	tb.Helper()

	_, err := repo.run(tb, nil, "git", "update-ref", "--end-of-options", name, oid.String())
	if err != nil {
		return fmt.Errorf("update-ref %s %s: %w", name, oid, err)
	}

	return nil
}

// ForEachRefFormat returns git-for-each-ref output for one ref and one format.
func (repo *Repo) ForEachRefFormat(tb testing.TB, pattern string, format string) ([]byte, error) {
	tb.Helper()

	stdout, err := repo.run(tb, nil, "git", "for-each-ref", "--format="+format, "--end-of-options", pattern)
	if err != nil {
		return nil, fmt.Errorf("for-each-ref --format=%q %s: %w", format, pattern, err)
	}

	return stdout, nil
}