diff --git a/scripts/check-doc-links.sh b/scripts/check-doc-links.sh index a8a4a12b..0813f952 100755 --- a/scripts/check-doc-links.sh +++ b/scripts/check-doc-links.sh @@ -48,6 +48,9 @@ cd "$(dirname "$0")/.." # Generated, vendored or build-output trees. Their markdown is not authored here # and their link targets are not ours to fix. +# +# Only consulted when this is NOT a git checkout — inside one, the tracked-file +# list does this job and does not need maintaining. Kept for the tarball case. EXCLUDES=( "./node_modules/*" "./.svelte-kit/*" @@ -81,14 +84,33 @@ is_generated() { echo "🔎 Checking relative markdown links resolve to files on disk…" -# Build the find(1) prune expression from EXCLUDES. -find_args=(. ) -for pattern in "${EXCLUDES[@]}"; do - find_args+=(-path "$pattern" -prune -o) -done -find_args+=(-name "*.md" -type f -print) - -mapfile -t md_files < <(find "${find_args[@]}" | sort) +# Ask git which markdown files are ours, rather than walking the filesystem. +# +# This started as a find(1) with a hand-maintained prune list, and that list was +# wrong three times in a row: it walked the scratch worktrees under .claude/, +# then makepkg's vendored cargo registry under packaging/arch/src/ — each time +# reporting a dependency's broken README as if it were ours. Every one of those +# directories is already git-ignored, so the tracked-file list is the exclusion +# rule, and it cannot drift out of date the way EXCLUDES did. It also matches +# what this script always claimed to do. +# +# Untracked-but-not-ignored files are deliberately included: a new doc added in +# a working tree should be checked before it is committed, not after. +if git rev-parse --git-dir >/dev/null 2>&1; then + mapfile -t md_files < <( + { git ls-files -z --cached --others --exclude-standard -- '*.md' | tr '\0' '\n'; } \ + | sed 's|^|./|' | sort -u + ) +else + # Not a git checkout (an exported tarball, say): fall back to walking, with + # the prune list below as the only defence. + find_args=(. ) + for pattern in "${EXCLUDES[@]}"; do + find_args+=(-path "$pattern" -prune -o) + done + find_args+=(-name "*.md" -type f -print) + mapfile -t md_files < <(find "${find_args[@]}" | sort) +fi echo " ${#md_files[@]} markdown files"