From 3339c9c5d2128f419aaf45352be43becf30e5e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 26 Sep 2018 19:16:33 +0200 Subject: [PATCH] add repository-local fallback checks for all hooks --- config/hooks/applypatch-msg | 1 + config/hooks/commit-msg | 1 + config/hooks/execute_hook.sh | 17 +++++++++++++++++ config/hooks/fsmonitor-watchman | 1 + config/hooks/p4-pre-submit | 1 + config/hooks/post-applypatch | 1 + config/hooks/post-checkout | 1 + config/hooks/post-commit | 1 + config/hooks/post-merge | 1 + config/hooks/post-receive | 1 + config/hooks/post-rewrite | 1 + config/hooks/post-update | 1 + config/hooks/pre-applypatch | 1 + config/hooks/pre-auto-gc | 1 + config/hooks/pre-commit | 21 +-------------------- config/hooks/pre-commit.local | 4 +++- config/hooks/pre-push | 1 + config/hooks/pre-rebase | 1 + config/hooks/pre-receive | 1 + config/hooks/prepare-commit-msg | 1 + config/hooks/push-to-checkout | 1 + config/hooks/rebase | 1 + config/hooks/sendemail-validate | 1 + config/hooks/update | 1 + 24 files changed, 42 insertions(+), 21 deletions(-) create mode 120000 config/hooks/applypatch-msg create mode 120000 config/hooks/commit-msg create mode 100755 config/hooks/execute_hook.sh create mode 120000 config/hooks/fsmonitor-watchman create mode 120000 config/hooks/p4-pre-submit create mode 120000 config/hooks/post-applypatch create mode 120000 config/hooks/post-checkout create mode 120000 config/hooks/post-commit create mode 120000 config/hooks/post-merge create mode 120000 config/hooks/post-receive create mode 120000 config/hooks/post-rewrite create mode 120000 config/hooks/post-update create mode 120000 config/hooks/pre-applypatch create mode 120000 config/hooks/pre-auto-gc mode change 100755 => 120000 config/hooks/pre-commit create mode 120000 config/hooks/pre-push create mode 120000 config/hooks/pre-rebase create mode 120000 config/hooks/pre-receive create mode 120000 config/hooks/prepare-commit-msg create mode 120000 config/hooks/push-to-checkout create mode 120000 config/hooks/rebase create mode 120000 config/hooks/sendemail-validate create mode 120000 config/hooks/update diff --git a/config/hooks/applypatch-msg b/config/hooks/applypatch-msg new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/applypatch-msg @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/commit-msg b/config/hooks/commit-msg new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/commit-msg @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/execute_hook.sh b/config/hooks/execute_hook.sh new file mode 100755 index 0000000..373cc25 --- /dev/null +++ b/config/hooks/execute_hook.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +HOOK=$(basename $0) + +# Execute a repository-local hook first. +LOCAL_HOOK=$(git rev-parse --show-toplevel 2>/dev/null | sed -e "s/\$/\/.git\/hooks\/$HOOK/") +if [ ! -z "$LOCAL_HOOK" ] && [ -x "$LOCAL_HOOK" ]; then + exec "$LOCAL_HOOK" "$@" + exit 1 +fi + +# If there's no repository-local hook, try executing a secret-shield hook if it exists. +SHIELD_HOOK=$(dirname $0)/$HOOK.local +if [ -x "$SHIELD_HOOK" ]; then + exec "$SHIELD_HOOK" "$@" + exit 1 +fi diff --git a/config/hooks/fsmonitor-watchman b/config/hooks/fsmonitor-watchman new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/fsmonitor-watchman @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/p4-pre-submit b/config/hooks/p4-pre-submit new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/p4-pre-submit @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/post-applypatch b/config/hooks/post-applypatch new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/post-applypatch @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/post-checkout b/config/hooks/post-checkout new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/post-checkout @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/post-commit b/config/hooks/post-commit new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/post-commit @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/post-merge b/config/hooks/post-merge new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/post-merge @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/post-receive b/config/hooks/post-receive new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/post-receive @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/post-rewrite b/config/hooks/post-rewrite new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/post-rewrite @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/post-update b/config/hooks/post-update new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/post-update @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/pre-applypatch b/config/hooks/pre-applypatch new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/pre-applypatch @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/pre-auto-gc b/config/hooks/pre-auto-gc new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/pre-auto-gc @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/pre-commit b/config/hooks/pre-commit deleted file mode 100755 index b8018ac..0000000 --- a/config/hooks/pre-commit +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -LOCALHOOKS=$(git rev-parse --show-toplevel 2>/dev/null | sed -e "s/\$/\/.git\/hooks\/pre-commit/") - -if [ -z "$NVM_DIR" ]; then - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" -fi - -if [ ! -z "$LOCALHOOKS" ] && [ -x "$LOCALHOOKS" ]; then - exec "$LOCALHOOKS" - exit -fi - -command -v secret-shield >/dev/null 2>&1 || { - echo >&2 "WARNING! Could not check for secrets because the secret-shield package is either not installed or misconfigured (command not found)." - exit 0 -} - -secret-shield --pre-commit diff --git a/config/hooks/pre-commit b/config/hooks/pre-commit new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/pre-commit @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/pre-commit.local b/config/hooks/pre-commit.local index 6ee2970..6b4389e 100755 --- a/config/hooks/pre-commit.local +++ b/config/hooks/pre-commit.local @@ -1,10 +1,12 @@ #!/bin/sh -if [ -z "$NVM_DIR" ]; then +# Try enabling NVM if we can't find secret-shield. +if [ ! command -v secret-shield >/dev/null 2>&1 ] && [ -z "$NVM_DIR" ]; then export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" fi +# Fail gracefully even if we couldn't find secret-shield in the NVM installation. command -v secret-shield >/dev/null 2>&1 || { echo >&2 "WARNING! Could not check for secrets because the secret-shield package is either not installed or misconfigured (command not found)." exit 0 diff --git a/config/hooks/pre-push b/config/hooks/pre-push new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/pre-push @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/pre-rebase b/config/hooks/pre-rebase new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/pre-rebase @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/pre-receive b/config/hooks/pre-receive new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/pre-receive @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/prepare-commit-msg b/config/hooks/prepare-commit-msg new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/prepare-commit-msg @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/push-to-checkout b/config/hooks/push-to-checkout new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/push-to-checkout @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/rebase b/config/hooks/rebase new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/rebase @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/sendemail-validate b/config/hooks/sendemail-validate new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/sendemail-validate @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file diff --git a/config/hooks/update b/config/hooks/update new file mode 120000 index 0000000..70fa0d1 --- /dev/null +++ b/config/hooks/update @@ -0,0 +1 @@ +execute_hook.sh \ No newline at end of file