From f0e76b814b854bd0b60b472a26309a65894cf82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Sat, 12 Feb 2022 20:30:01 +0100 Subject: [PATCH] Add more checks to makefile We're trying to prevent clobbering other's changes or forgetting to push ours. --- Makefile | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 0ab587a..529f745 100644 --- a/Makefile +++ b/Makefile @@ -10,12 +10,27 @@ sign: $(patsubst %,%.sig,$(wildcard *.zone)) .PHONY: check-clean check-clean: - [ ! -e .git ] || git diff-index --exit-code HEAD - [ ! -e .git ] || \ - git ls-files --other --directory --exclude-standard | \ - sed -n '/.*\.zone/{p;q1}' + @git diff-index --exit-code HEAD >/dev/null && \ + git ls-files --other --directory --exclude-standard | \ + sed -n '/.*\.zone/{p;q1}' || { \ + printf 'Commit your changes before uploading!\n' >&2; \ + git status -s; exit 1; } -upload: +GIT_BRANCH=$(shell git name-rev --name-only HEAD) +GIT_BRANCH_REMOTE=$(shell git config branch.$(GIT_BRANCH).remote) +GIT_BRANCH_MERGE=$(shell git config branch.$(GIT_BRANCH).merge) # remote branch +.PHONY: fetch +check-uptodate: FORCE + git fetch $(GIT_BRANCH_REMOTE) $(GIT_BRANCH_MERGE) + @[ -z "`git rev-list -n1 HEAD@{upstream} --not HEAD`" ] || { \ + printf 'Unpulled changes, refusing to upload zones!\n' >&2; \ + git log --decorate --oneline --graph -n3 \ + HEAD@{upstream} --not HEAD; \ + } + +.PHONY: upload +upload: check-clean check-uptodate +upload: sign printf 'put %s\n' *.zone *.sig | \ sftp $(SFTP_FLAGS) zones@ns0.it-syndikat.org:zones/