From b6728a85e94b8de73d7e566bacf5efa4e38cc8cb Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Wed, 28 Jun 2017 11:56:09 +0100 Subject: [PATCH] pkg: Simplify dirty handling By setting `DIRTY` to either "-dirty" or "" directly we can simply use `$(HASH)$(DIRTY)` and avoid make adding a space as it does with `+=`. For the push check we now block pushing if `$(DIRTY)` is non-empty. Signed-off-by: Ian Campbell --- pkg/package.mk | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/pkg/package.mk b/pkg/package.mk index 96297159a..1e2971d5c 100644 --- a/pkg/package.mk +++ b/pkg/package.mk @@ -5,18 +5,8 @@ ORG?=linuxkit HASH?=$(shell git ls-tree HEAD -- ../$(notdir $(CURDIR)) | awk '{print $$3}') BASE_DEPS=Dockerfile Makefile -# Add '-dirty' to hash if the repository is not clean. make does not -# concatenate strings without spaces, so we use the documented trick -# of replacing the space with nothing. -DIRTY=$(shell git diff-index --quiet HEAD --; echo $$?) -ifneq ($(DIRTY),0) -HASH+=-dirty -nullstring := -space := $(nullstring) $(nullstring) -TAG=$(subst $(space),,$(HASH)) -else -TAG=$(HASH) -endif +DIRTY=$(shell git diff-index --quiet HEAD -- ) || echo "-dirty") +TAG=$(HASH)$(DIRTY) # Get a release tag, if present RELEASE=$(shell git tag -l --points-at HEAD) @@ -35,7 +25,7 @@ tag: $(BASE_DEPS) $(DEPS) docker build $(NET_OPT) -t $(ORG)/$(IMAGE):$(TAG) . push: tag -ifneq ($(DIRTY),0) +ifneq ($(DIRTY),) $(error Your repository is not clean. Will not push package image.) endif DOCKER_CONTENT_TRUST=1 docker pull $(ORG)/$(IMAGE):$(TAG) || \