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) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user