Files
kvitt/tools/install-git-hooks.sh

25 lines
937 B
Bash
Executable File

#!/usr/bin/env bash
# Installs the Kvitt pre-commit hook into this repository's hooks folder (shared by all worktrees).
# The hook guards itself: on branches without android/ or server/ it only runs the secrets check.
# An earlier version of the Kvitt hook (recognised by its first comment line) is replaced; any other hook is kept.
set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"
src="$here/git-hooks/pre-commit"
hooks="$(git -C "$here" rev-parse --path-format=absolute --git-common-dir)/hooks"
target="$hooks/pre-commit"
marker="# Kvitt pre-commit hook:"
if [[ -e "$target" ]]; then
if cmp -s "$src" "$target"; then
echo "Up to date: $target"
exit 0
fi
if ! sed -n 2p "$target" | grep -qF "$marker"; then
echo "A different pre-commit hook already exists at $target; not overwriting. Merge them by hand." >&2
exit 1
fi
fi
mkdir -p "$hooks"
cp "$src" "$target"
chmod +x "$target"
echo "Installed $target"