aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Ward <kate.ward@forestent.com>2020-04-10 14:29:35 +0200
committerKate Ward <kate.ward@forestent.com>2020-04-10 14:29:35 +0200
commit16e941e937cbcbd7cfc9cd06eb43e9e4fd579238 (patch)
treea0ff26f003c4ab3676250d40a4337608a74bbb33
parentfb1f0537ec1fdb592c133327969f73334aabbeb0 (diff)
downloadshflags-16e941e937cbcbd7cfc9cd06eb43e9e4fd579238.tar.gz
Setup repo hooks.
-rwxr-xr-x.githooks/pre-commit13
-rwxr-xr-x.githooks/pre-commit.shellcheck20
-rwxr-xr-xinit_githooks.sh46
3 files changed, 79 insertions, 0 deletions
diff --git a/.githooks/pre-commit b/.githooks/pre-commit
new file mode 100755
index 0000000..5ee533a
--- /dev/null
+++ b/.githooks/pre-commit
@@ -0,0 +1,13 @@
+#!/bin/sh
+#
+# A hook script to verify what is about to be committed.
+# Called by "git commit" with no arguments.
+
+# Redirect output to stderr.
+exec 1>&2
+
+for f in .githooks/pre-commit.*; do
+ n=$(echo "${f}" |sed 's/^.*pre-commit\.//')
+ echo "running ${n} pre-commit"
+ $(${f})
+done
diff --git a/.githooks/pre-commit.shellcheck b/.githooks/pre-commit.shellcheck
new file mode 100755
index 0000000..d8f364e
--- /dev/null
+++ b/.githooks/pre-commit.shellcheck
@@ -0,0 +1,20 @@
+#!/bin/sh
+#
+# Git hook to run ShellCheck.
+#
+# ShellCheck <https://www.shellcheck.net/>
+
+# Treat unset variables as an error when performing parameter expansion.
+set -u
+
+if ! command -v shellcheck >/dev/null; then
+ echo 'unable to locate shellcheck' >&2
+ return 0
+fi
+
+for f in $(git diff --name-only); do
+ case "${f}" in
+ shflags|shflags_test_helpers) shellcheck -s sh "${f}" ;;
+ *.sh) shellcheck "${f}" ;;
+ esac
+done
diff --git a/init_githooks.sh b/init_githooks.sh
new file mode 100755
index 0000000..d5a7f50
--- /dev/null
+++ b/init_githooks.sh
@@ -0,0 +1,46 @@
+#! /bin/sh
+#
+# Initialize the local git hooks this repository.
+# https://git-scm.com/docs/githooks
+
+topLevel=$(git rev-parse --show-toplevel) && cd "${topLevel}"
+hooksDir="${topLevel}/.githooks"
+hooksPath=$(git config core.hooksPath)
+if [ $? -ne 0 ]; then
+ hooksPath="${topLevel}/.git/hooks"
+fi
+
+echo "linking hooks..."
+for hook in \
+ applypatch-msg \
+ pre-applypatch \
+ post-applypatch \
+ pre-commit \
+ pre-merge-commit \
+ prepare-commit-msg \
+ commit-msg \
+ post-commit \
+ pre-rebase \
+ post-checkout \
+ post-merge \
+ pre-push \
+ pre-receive \
+ update \
+ post-receive \
+ post-update \
+ push-to-checkout \
+ pre-auto-gc \
+ post-rewrite \
+ sendemail-validate \
+ fsmonitor-watchman \
+ p4-pre-submit \
+ post-index-change
+do
+ src="${hooksDir}/${hook}"
+ dest="${hooksPath}/${hook}"
+
+ [ -x "${src}" ] || continue
+
+ echo "- ${hook}"
+ ln -sf "${src}" "${dest}"
+done