From e423f9594e2eda7a5425a6da8767fff9052c3de8 Mon Sep 17 00:00:00 2001 From: Andrew Kesterson Date: Thu, 30 Jul 2026 18:22:47 -0400 Subject: [PATCH] Accept absolute paths in reindent.sh --check `--check` prefixed every path with the repository root unconditionally, so passing an absolute path produced a bogus `$root//abs/path`, cp failed, and the subsequent cmp reported the file as non-conforming. The exit status happened to be 1, which looked correct while being reached for the wrong reason. In-place mode was unaffected -- it cds to the root and hands the list straight to Emacs, where absolute paths resolve normally, which is why the pre-commit hook worked. Normalize both the copy and the compare through an abspath helper so relative and absolute paths behave identically in either mode. Co-Authored-By: Claude Opus 5 (1M context) --- scripts/reindent.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/reindent.sh b/scripts/reindent.sh index 12e34ea..2dc67af 100755 --- a/scripts/reindent.sh +++ b/scripts/reindent.sh @@ -68,10 +68,19 @@ fi tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT INT TERM +# Accept both repo-relative and absolute paths: the default file list is +# relative, but callers (including the pre-commit hook) pass absolute ones. +abspath() { + case "$1" in + /*) printf '%s' "$1" ;; + *) printf '%s/%s' "$root" "$1" ;; + esac +} + copies='' for f in $files; do dest="$tmp/$(printf '%s' "$f" | tr '/' '_')" - cp "$root/$f" "$dest" + cp "$(abspath "$f")" "$dest" copies="$copies $dest" done @@ -84,7 +93,7 @@ emacs --batch -Q -l "$elisp" -- $copies >/dev/null || { status=0 for f in $files; do dest="$tmp/$(printf '%s' "$f" | tr '/' '_')" - if ! cmp -s "$root/$f" "$dest"; then + if ! cmp -s "$(abspath "$f")" "$dest"; then echo "$f" status=1 fi