#!/bin/bash # ============================================================================ # Refuse to commit anything that identifies a real person. # # The logic is check_personal_data.py; this half exists to list what git # tracks, which keeps the Python free of a subprocess call it would otherwise # need a lint suppression for. # # scripts/check_personal_data.sh --all every tracked file # scripts/check_personal_data.sh a.py b.md named files # scripts/check_personal_data.sh --message .git/COMMIT_EDITMSG # ============================================================================ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" readonly SCRIPT_DIR REPO_ROOT="$(dirname "$SCRIPT_DIR")" readonly REPO_ROOT readonly CHECKER="${SCRIPT_DIR}/check_personal_data.py" # The repo's own interpreter when there is one, so the check runs the same # way under pre-commit, in CI and by hand. PYTHON="${PYTHON:-${REPO_ROOT}/.venv/bin/python}" if [[ ! -x "$PYTHON" ]]; then PYTHON="$(command -v python3)" fi readonly PYTHON usage() { echo "Usage: $(basename "$0") [--all | --message FILE | FILE...]" exit 0 } main() { if [[ $# -eq 0 ]]; then usage fi case "$1" in -h | --help) usage ;; --message) if [[ $# -lt 2 ]]; then echo "Error: --message needs a file" >&2 exit 1 fi "$PYTHON" "$CHECKER" --message "$2" ;; --all) local files=() mapfile -t files < <(git -C "$REPO_ROOT" ls-files) if [[ ${#files[@]} -eq 0 ]]; then echo "Error: git tracks no files here" >&2 exit 1 fi # Prefixed with the repo root so this works from any directory. local paths=() local file for file in "${files[@]}"; do paths+=("${REPO_ROOT}/${file}") done "$PYTHON" "$CHECKER" --files "${paths[@]}" ;; *) "$PYTHON" "$CHECKER" --files "$@" ;; esac } main "$@"