> ## Documentation Index
> Fetch the complete documentation index at: https://calendar-effects.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# scripts/install_git_hooks.sh

> Install this repository's git hooks on your machine (decision 0011). Optional, per person.

`scripts/install_git_hooks.sh` · chapter [Tests and team tooling](https://calendar-effects.mintlify.site/tour/10-tests-and-tooling.md), file 27 · 62 lines · [open in the repository](https://github.sfu.ca/aba395/Calendar-Effects/blob/main/scripts/install_git_hooks.sh)

## What it does

Install this repository's git hooks on your machine (decision 0011). Optional, per person.

pre-commit   rebuilds docs-site/ (scripts/build\_docs.py) and stages it, so a commit you make
by hand never leaves the docs behind. (Claude Code commits are also checked by
.claude/hooks/pre-commit-tests.sh, which runs tests/test\_docs\_site.py.)
post-commit  in the background, on main: pushes docs-site/ to the docs repository Mintlify deploys,
the dashboard to the repository Streamlit Community Cloud deploys, and the project copy
the cloud streamer runs (scripts/sync\_docs\_site.sh, scripts/sync\_dashboard\_app.sh,
scripts/sync\_live\_stream.sh; decisions 0011, 0013, 0015).

It also points those three at the team's github.com repositories (git config calendar-effects.\*;
an address already set is kept). Pushing needs the GitHub CLI signed in (gh auth login) with write
access to the Calendar-Effects organisation; without it the pushes fail quietly and commits still work.

Each hook's lines sit between markers, so running this again replaces them, and other hooks
already in the file (for example graphify's) are kept.
Remove:   scripts/install\_git\_hooks.sh --remove

## Source

```bash title="scripts/install_git_hooks.sh" lines expandable theme={null}
#!/usr/bin/env bash
# Install this repository's git hooks on your machine (decision 0011). Optional, per person.
#
#   pre-commit   rebuilds docs-site/ (scripts/build_docs.py) and stages it, so a commit you make
#                by hand never leaves the docs behind. (Claude Code commits are also checked by
#                .claude/hooks/pre-commit-tests.sh, which runs tests/test_docs_site.py.)
#   post-commit  in the background, on main: pushes docs-site/ to the docs repository Mintlify deploys,
#                the dashboard to the repository Streamlit Community Cloud deploys, and the project copy
#                the cloud streamer runs (scripts/sync_docs_site.sh, scripts/sync_dashboard_app.sh,
#                scripts/sync_live_stream.sh; decisions 0011, 0013, 0015).
#
# It also points those three at the team's github.com repositories (git config calendar-effects.*;
# an address already set is kept). Pushing needs the GitHub CLI signed in (gh auth login) with write
# access to the Calendar-Effects organisation; without it the pushes fail quietly and commits still work.
#
# Each hook's lines sit between markers, so running this again replaces them, and other hooks
# already in the file (for example graphify's) are kept.
# Remove:   scripts/install_git_hooks.sh --remove
set -euo pipefail

root=$(git rev-parse --show-toplevel)
hooks=$(git -C "$root" rev-parse --git-path hooks)
case "$hooks" in /*) ;; *) hooks="$root/$hooks" ;; esac
mkdir -p "$hooks"
begin="# >>> calendar-effects docs (scripts/install_git_hooks.sh)"
end="# <<< calendar-effects docs"

strip() {  # remove our block from a hook file
  [ -f "$1" ] || return 0
  awk -v b="$begin" -v e="$end" '$0==b{skip=1;next} $0==e{skip=0;next} !skip' "$1" > "$1.tmp" && mv "$1.tmp" "$1"
}

add() {  # put our block right after the hook's first line, so it runs before any `exec` below it
  local file="$hooks/$1" body="$2"
  strip "$file"
  [ -s "$file" ] || printf '#!/bin/sh\n' > "$file"
  { head -n 1 "$file"; printf '%s\n%s\n%s\n' "$begin" "$body" "$end"; tail -n +2 "$file"; } > "$file.tmp"
  mv "$file.tmp" "$file"
  chmod +x "$file"
}

if [ "${1:-}" = "--remove" ]; then
  strip "$hooks/pre-commit"
  strip "$hooks/post-commit"
  echo "Removed the docs hooks."
  exit 0
fi

python='python3'
[ -x "$root/.venv/bin/python" ] && python="$root/.venv/bin/python"

# The team's github.com repositories, from common.settings (an address already set is kept).
org=$(cd "$root/src" && "$python" -c "from common.settings import GITHUB_ORG; print(GITHUB_ORG)")
for pair in docsRemote:docs dashboardRemote:dashboard streamerRemote:live-stream; do
  key="calendar-effects.${pair%%:*}"
  git -C "$root" config --get "$key" >/dev/null || git -C "$root" config "$key" "https://github.com/$org/${pair#*:}.git"
done

add pre-commit "cd \"\$(git rev-parse --show-toplevel)\" && \"$python\" scripts/build_docs.py && git add docs-site"
add post-commit "( cd \"\$(git rev-parse --show-toplevel)\" && { scripts/sync_docs_site.sh; scripts/sync_dashboard_app.sh; scripts/sync_live_stream.sh; } >/dev/null 2>&1 & )"
echo "Installed: pre-commit rebuilds and stages docs-site/; post-commit pushes the docs site, the hosted dashboard"
echo "and the cloud streamer's project copy to github.com/$org (needs: gh auth login)."
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.