From fda71b541d09689c6f5a8ae7807321186d5f722f Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Wed, 22 Jun 2022 11:03:24 +0200 Subject: Make setup-repo work with submodules --- bin/setup-repo | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/setup-repo b/bin/setup-repo index ef7cf2c95b..1651534e14 100755 --- a/bin/setup-repo +++ b/bin/setup-repo @@ -4,8 +4,19 @@ set -e -SRC=../../conf/pre-commit -HOOK=.git/hooks/pre-commit +## variables +if [ -d .git ]; then + GIT_HOOKS_DIR=".git/hooks" +elif [ -e .git ]; then + GIT_DIR=$(awk '/gitdir:/ { print $2 }' .git) + GIT_HOOKS_DIR="$GIT_DIR/hooks" +else + echo "ERROR: Not in the top-level directory of the git repository." >&2 + exit 1 +fi + +SRC=$(realpath --relative-to "$GIT_HOOKS_DIR" conf/pre-commit) +HOOK="$GIT_HOOKS_DIR"/pre-commit install_pre_commit_hook() { if [ -L "${HOOK}" ] && [ "$(readlink ${HOOK})" = "${SRC}" ]; then -- cgit v1.2.3