#!/usr/bin/env bash set -euo pipefail if [[ $# -gt 1 ]]; then echo "usage: $0 [root]" >&2 exit 2 fi if [[ $# -eq 1 ]]; then root="$1" fixture_mode=true else root="$(git rev-parse --show-toplevel)" fixture_mode=false fi if [[ ! -d "$root" ]]; then echo "not a directory: $root" >&2 exit 2 fi root="$(cd "$root" && pwd)" offenders=() while IFS= read -r -d '' file; do [[ -f "$file" ]] || continue case "$file" in *.ps1) continue ;; esac if LC_ALL=C grep -Il $'\r' "$file" >/dev/null; then offenders+=("${file#"$root"/}") fi done < <( if [[ "$fixture_mode" == true ]]; then find "$root" -type f -print0 else git -C "$root" ls-files -z | while IFS= read -r -d '' path; do printf '%s\0' "$root/$path" done fi ) if (( ${#offenders[@]} )); then printf '%s\n' "CRLF line endings detected:" >&2 printf '%s\n' "${offenders[@]}" >&2 exit 1 fi