check-expected-filenames.sh 810 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Vendored upstream paths follow vendor/README.md instead of repository naming policy.
  4. root=$(git rev-parse --show-toplevel)
  5. candidate_file=$(mktemp)
  6. trap 'unlink "$candidate_file"' EXIT
  7. git -C "$root" ls-files -z -- \
  8. ':(icase,glob)*golden*' \
  9. ':(icase,glob)**/*golden*' \
  10. ':(exclude,glob)vendor/**' > "$candidate_file"
  11. violations=()
  12. while IFS= read -r -d '' path; do
  13. violations+=("$path")
  14. done < "$candidate_file"
  15. if (( ${#violations[@]} == 0 )); then
  16. echo 'check-expected-filenames: no tracked non-vendor filename contains "golden".'
  17. exit 0
  18. fi
  19. echo 'check-expected-filenames: tracked non-vendor filenames must not contain "golden":' >&2
  20. printf ' %s\n' "${violations[@]}" >&2
  21. echo 'Rename each file with an accurate term such as "expected".' >&2
  22. exit 1