25 lines
676 B
Bash
Executable File
25 lines
676 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
repo_root="$(git rev-parse --show-toplevel)"
|
|
hook="$repo_root/.git/hooks/pre-push"
|
|
|
|
if [[ -e "$hook" && ! -f "$hook" ]]; then
|
|
printf 'Cannot install guard: %s is not a regular file.\n' "$hook" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -f "$hook" ]] && ! grep -Fq 'scripts/check_public_content.sh' "$hook"; then
|
|
printf 'Cannot install guard: existing pre-push hook is not managed by this repository.\n' >&2
|
|
exit 1
|
|
fi
|
|
|
|
cat > "$hook" <<'EOF'
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
repo_root="$(git rev-parse --show-toplevel)"
|
|
exec bash "$repo_root/scripts/check_public_content.sh"
|
|
EOF
|
|
chmod +x "$hook"
|
|
printf 'Installed public-content pre-push guard.\n'
|