#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# Decide whether a change set is prose only.
#
#   printf '%s\n' path... | scripts/hooks/prose-only
#
# Exits 0 when the input names at least one path and every path is one that no test, script or
# source file reads: the development method's documents, its templates, and the research corpus.
# Exits 1 otherwise, including on empty input, so an unknown change set runs the full gate.
#
# The hooks use this to run `scripts/check-docs` (about two seconds) instead of the test suite.
# Paths outside the list below -- README.md, AGENTS.md, docs/tables/**, every other document,
# src/, tests/, scripts/ -- always take the full gate. Add a path here only after grepping tests/
# and src/ to show that nothing reads it.
#
# Paths come from `git diff --name-only --no-renames`, so a file renamed out of src/ into
# docs/research/ still shows the deleted source path.

set -eu

seen=0
while IFS= read -r path; do
    [ -n "$path" ] || continue
    seen=1
    # A path that climbs out of its prefix is never prose.
    case "/$path/" in
        */../*) exit 1 ;;
    esac
    case "$path" in
        docs/research/*) ;;
        docs/templates/*) ;;
        docs/method.md | docs/record.md | docs/residuals.md) ;;
        *) exit 1 ;;
    esac
done

[ "$seen" -eq 1 ]
