From 3e3c06118c9ddd8941f9b88dd6bd544a9df490e2 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Sat, 6 Mar 2021 07:39:48 +0100 Subject: [PATCH] chore(build): Ensure git hooks from Makefile --- Makefile | 1 + scripts/git-hook-pre-push.sh | 12 ++++++++++++ scripts/git-hooks-init.sh | 13 +++++++++++++ 3 files changed, 26 insertions(+) create mode 100755 scripts/git-hook-pre-push.sh create mode 100755 scripts/git-hooks-init.sh diff --git a/Makefile b/Makefile index f74296361..f4cc5dc89 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +$(shell scripts/git-hooks-init.sh) REBAR_VERSION = 3.14.3-emqx-4 REBAR = $(CURDIR)/rebar3 BUILD = $(CURDIR)/build diff --git a/scripts/git-hook-pre-push.sh b/scripts/git-hook-pre-push.sh new file mode 100755 index 000000000..2f5a9abcd --- /dev/null +++ b/scripts/git-hook-pre-push.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -euo pipefail + +url="$2" + +if [ -f 'EMQX_ENTERPRISE' ]; then + if [[ "$url" != *emqx-enterprise* ]]; then + echo "$(tput setaf 1)error: enterprise_code_to_non_enterprise_repo" + exit 1 + fi +fi diff --git a/scripts/git-hooks-init.sh b/scripts/git-hooks-init.sh new file mode 100755 index 000000000..a9f02ab3a --- /dev/null +++ b/scripts/git-hooks-init.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -euo pipefail + +if [ ! -d .git ]; then + exit 0 +fi + +mkdir -p ".git/hooks" + +if [ ! -L '.git/hooks/pre-push' ]; then + ln -sf '../../scripts/git-hook-pre-push.sh' '.git/hooks/pre-push' +fi