mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
build: makes git dirty check opt-in
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
a3286a0ab1
commit
b1440b07f2
@ -67,7 +67,13 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
|
|||||||
if sha, err := gitc.FullCommit(); err != nil && !gitutil.IsUnknownRevision(err) {
|
if sha, err := gitc.FullCommit(); err != nil && !gitutil.IsUnknownRevision(err) {
|
||||||
return res, errors.Wrapf(err, "buildx: failed to get git commit")
|
return res, errors.Wrapf(err, "buildx: failed to get git commit")
|
||||||
} else if sha != "" {
|
} else if sha != "" {
|
||||||
if gitc.IsDirty() {
|
checkDirty := false
|
||||||
|
if v, ok := os.LookupEnv("BUILDX_GIT_CHECK_DIRTY"); ok {
|
||||||
|
if v, err := strconv.ParseBool(v); err == nil {
|
||||||
|
checkDirty = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if checkDirty && gitc.IsDirty() {
|
||||||
sha += "-dirty"
|
sha += "-dirty"
|
||||||
}
|
}
|
||||||
if setGitLabels {
|
if setGitLabels {
|
||||||
|
@ -131,6 +131,7 @@ func TestGetGitAttributes(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetGitAttributesDirty(t *testing.T) {
|
func TestGetGitAttributesDirty(t *testing.T) {
|
||||||
setupTest(t)
|
setupTest(t)
|
||||||
|
t.Setenv("BUILDX_GIT_CHECK_DIRTY", "true")
|
||||||
|
|
||||||
// make a change to test dirty flag
|
// make a change to test dirty flag
|
||||||
df := []byte("FROM alpine:edge\n")
|
df := []byte("FROM alpine:edge\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user