-
Notifications
You must be signed in to change notification settings - Fork 1
/
git.go
46 lines (39 loc) · 1.07 KB
/
git.go
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
42
43
44
45
46
package building
import (
"bytes"
"strings"
)
func (b *B) Git(args ...string) Tool {
return b.MakeTool(
"git",
"--version",
"https://git-scm.com",
`
FROM alpine:`+AlpineVersion+`
RUN apk add --no-cache git`,
args...)
}
func (b *B) GitShortCommit() string {
buf := &bytes.Buffer{}
b.Git().WithOutput(buf).WithSuccess().Run("rev-parse", "--short", "HEAD")
return strings.TrimSpace(buf.String())
}
func (b *B) GitCommit() string {
buf := &bytes.Buffer{}
b.Git().WithOutput(buf).WithSuccess().Run("rev-parse", "HEAD")
return strings.TrimSpace(buf.String())
}
func (b *B) GitTag() string {
buf := &bytes.Buffer{}
b.Git().WithOutput(buf).WithSuccess().Run("describe", "--always", "--dirty")
return strings.TrimSpace(buf.String())
}
func (b *B) GitDirty() bool {
b.Git("update-index", "-q", "--refresh")
return b.Git().WithSuccess().Run("diff-index", "--quiet", "HEAD", "--", ".") == 0
}
func (b *B) GitVersion() string {
buf := &bytes.Buffer{}
b.Git().WithOutput(buf).WithSuccess().Run("tag", "-l", "--points-at", "HEAD", `"v*"`)
return strings.TrimSpace(buf.String())
}