-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·28 lines (23 loc) · 946 Bytes
/
Copy pathpre-commit
File metadata and controls
executable file
·28 lines (23 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
# Pre-commit hook for Git repos.
# Andrew Benson (14-May-2026)
# Directory containing individual pre-commit scripts. Use the common Git
# directory so that this resolves correctly in linked worktrees (where
# `.git` is a file, and `.git/hooks` does not exist).
HOOKS_DIR="$(git rev-parse --git-common-dir)/hooks/pre-commit.d"
# Exit immediately if any script fails
set -e
# Avoid running a literal glob pattern if nothing matches.
shopt -s nullglob
# Run every executable script whose name begins with the two-digit numerical
# prefix convention (e.g. `00-galacticus`). This deliberately ignores artifacts
# such as `__pycache__` directories or editor backup files.
for hook in "$HOOKS_DIR"/[0-9][0-9]*; do
# Skip editor backup files (e.g. `00-galacticus~`).
[[ "$hook" == *~ ]] && continue
if [ -x "$hook" ]; then
echo "Running hook: $(basename "$hook")"
"$hook" || exit 1
fi
done
exit 0