From 811868f06b8fb881d5d8e7be835716ce09caf91f Mon Sep 17 00:00:00 2001 From: makeworld Date: Wed, 2 Sep 2020 13:51:48 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Detect=20if=20Git=20repo=20exist?= =?UTF-8?q?s=20in=20Makefile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index fb3810a..463c226 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,16 @@ -ifeq ($(shell git tag --points-at HEAD),) - # Not currently on a tag - VERSION := $(shell git describe --tags | sed 's/-.*/-next/') # v1.2.3-next -else - # On a tag - VERSION := $(shell git tag --points-at HEAD) -endif +GIT_EXISTS := $(shell git status > /dev/null 2>&1 ; echo $$?) -COMMIT := $(shell git rev-parse --verify HEAD) +ifeq ($(GIT_EXISTS), 0) + ifeq ($(shell git tag --points-at HEAD),) + # Not currently on a tag + VERSION := $(shell git describe --tags | sed 's/-.*/-next/') # v1.2.3-next + else + # On a tag + VERSION := $(shell git tag --points-at HEAD) + endif + + COMMIT := $(shell git rev-parse --verify HEAD) +endif INSTALL := install -o root -g root INSTALL_DIR := /usr/local/bin @@ -17,6 +21,10 @@ DESKTOP_DIR := /usr/share/applications all: build build: +ifneq ($(GIT_EXISTS), 0) + # No Git repo + $(error No Git repo was found, which is needed to compile the commit and version) +endif @echo "Downloading dependencies" @go env -w GO111MODULE=on ; go mod download @echo "Building binary"