Skip to content

Commit 861dbd3

Browse files
committed
fix: honor Git effective hook path
1 parent 988e857 commit 861dbd3

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

‎.ores-lint/install-git-hooks.sh‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
#!/bin/sh
22
# Optional: install a pre-push hook that runs ores-lint.
3-
# Not installed automatically by the rollout - run this yourself per repo.
4-
set -u
5-
ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || { echo "not a git repo"; exit 1; }
6-
HOOK="$ROOT/.git/hooks/pre-push"
7-
if [ -e "$HOOK" ] && ! grep -q 'ores-lint' "$HOOK"; then
8-
echo "refusing to clobber an existing pre-push hook: $HOOK"
3+
set -eu
4+
ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || { echo "not a git repo" >&2; exit 1; }
5+
HOOKS_PATH=$(git -C "$ROOT" config --get core.hooksPath 2>/dev/null || true)
6+
case "$HOOKS_PATH" in
7+
"") GIT_DIR=$(git -C "$ROOT" rev-parse --absolute-git-dir); HOOK_DIR="$GIT_DIR/hooks" ;;
8+
/*) HOOK_DIR="$HOOKS_PATH" ;;
9+
'~/'*) HOOK_DIR="$HOME/${HOOKS_PATH#??}" ;;
10+
*) HOOK_DIR="$ROOT/$HOOKS_PATH" ;;
11+
esac
12+
mkdir -p "$HOOK_DIR"
13+
HOOK="$HOOK_DIR/pre-push"
14+
if [ -e "$HOOK" ] && ! grep -Fq 'installed by .ores-lint/install-git-hooks.sh' "$HOOK"; then
15+
echo "refusing to clobber an existing pre-push hook: $HOOK" >&2
916
exit 1
1017
fi
1118
cat > "$HOOK" <<'INNER'
1219
#!/bin/sh
1320
# installed by .ores-lint/install-git-hooks.sh
14-
[ -x "$(git rev-parse --show-toplevel)/.ores-lint/lint.sh" ] && \
15-
sh "$(git rev-parse --show-toplevel)/.ores-lint/lint.sh"
16-
exit 0
21+
set -eu
22+
ROOT=$(git rev-parse --show-toplevel 2>/dev/null) || exit 1
23+
LINT="$ROOT/.ores-lint/lint.sh"
24+
if [ ! -x "$LINT" ]; then
25+
echo "ores-lint pre-push: missing executable $LINT" >&2
26+
exit 1
27+
fi
28+
exec sh "$LINT"
1729
INNER
1830
chmod +x "$HOOK"
1931
echo "installed $HOOK"

0 commit comments

Comments
 (0)