-
Notifications
You must be signed in to change notification settings - Fork 77
/
lib.go
48 lines (40 loc) · 1.16 KB
/
lib.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
47
48
// Copyright DataStax, Inc.
// Please see the included license file for details.
package gitutil
import (
"strings"
"github.com/datastax/cass-operator/mage/sh"
"github.com/datastax/cass-operator/mage/util"
)
func GetUnstagedChanges() string {
out := shutil.OutputPanic("git", "--no-pager", "diff")
return strings.TrimSpace(out)
}
func HasUnstagedChanges() bool {
out := shutil.OutputPanic("git", "diff")
return strings.TrimSpace(out) != ""
}
func HasStagedChanges() bool {
out := shutil.OutputPanic("git", "diff", "--staged")
return strings.TrimSpace(out) != ""
}
// First check env var for branch value
// and fall back to executing git cli
func GetBranch(env string) string {
var gitFunc = func() string {
branch := shutil.OutputPanic("git", "rev-parse", "--abbrev-ref", "HEAD")
return branch
}
val := mageutil.FromEnvOrF(env, gitFunc)
return strings.TrimSpace(val)
}
// First check env var for hash value
// and fall back to executing git cli
func GetLongHash(env string) string {
var gitFunc = func() string {
hash := shutil.OutputPanic("git", "rev-parse", "HEAD")
return hash
}
val := mageutil.FromEnvOrF(env, gitFunc)
return strings.TrimSpace(val)
}