aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/rosa/git.go
blob: 0954477f2467cc7734ef3bf9ced9fd091d7e05e0 (plain)
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
33
34
35
36
37
38
39
40
41
package rosa

import (
	"path"
	"strings"

	"hakurei.app/internal/pkg"
)

// Git is the package used by [Toolchain.NewViaGit].
var Git = H("git")

// NewViaGit returns a [pkg.Artifact] for cloning a git repository.
func (t Toolchain) NewViaGit(
	url, rev string,
	checksum pkg.Checksum,
) pkg.Artifact {
	return t.New(strings.TrimSuffix(
		path.Base(url),
		".git",
	)+"-src-"+path.Base(rev), THostNet, t.Append(nil,
		nssCACert,
		Git,
	), &checksum, nil, `
git \
	-c advice.detachedHead=false \
	clone \
	--depth=1 \
	--revision=`+rev+` \
	--shallow-submodules \
	--recurse-submodules \
	`+url+` \
	/work
rm -rf /work/.git
`, resolvconf())
}

// newTagRemote is a helper around NewViaGit for a tag on a git remote.
func (t Toolchain) newTagRemote(url, tag, checksum string) pkg.Artifact {
	return t.NewViaGit(url, "refs/tags/"+tag, mustDecode(checksum))
}