blob: 0c3989cdacf7a6ecb7b6e0886967ef12f9bc451d [file] [log] [blame]
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2026 Krzysztof Kozlowski <krzk@kernel.org>
#
set -eE
die() {
echo "Fail: $1"
exit 1
}
SELF_DIR="$(dirname "${BASH_SOURCE[0]}")"
test -f .git/hooks/post-commit && die "rm -f .git/hooks/post-commit"
test -f .git/hooks/post-applypatch && die "rm -f .git/hooks/post-applypatch"
test -f .git/hooks/post-merge && die "rm -f .git/hooks/post-merge"
# Sanity check:
LINUS_URL="$(git remote get-url linus)"
test -n "$LINUS_URL" || die "No 'linus' remote? Or not running in soc Linux kernel repo?"
if [[ "$LINUS_URL" != *"kernel.org/pub/scm/linux/kernel/git/torvalds"* ]]; then
die "'linus' remote points somewhere else or not running in soc Linux kernel repo?"
fi
sed -e "s+__REPLACE__TOOLS__+${SELF_DIR}/+" "${SELF_DIR}/git-hooks-post-commit" > .git/hooks/post-commit
sed -e "s+__REPLACE__TOOLS__+${SELF_DIR}/+" "${SELF_DIR}/git-hooks-post-commit" > .git/hooks/post-applypatch
sed -e "s+__REPLACE__TOOLS__+${SELF_DIR}/+" "${SELF_DIR}/git-hooks-post-merge" > .git/hooks/post-merge
chmod a+x .git/hooks/post-commit .git/hooks/post-applypatch .git/hooks/post-merge
echo "Hooks installed from ${SELF_DIR}"