#!/bin/sh
# Check the format of staged C source files.

tmp=$(mktemp -d) || exit 1
trap 'rm -rf "$tmp"' EXIT

git diff --cached --name-only --diff-filter=ACMRT -z -- '*.c' '*.h' > "$tmp/files" || exit 1
[ -s "$tmp/files" ] || exit 0

git checkout-index --prefix="$tmp/" -z --stdin < "$tmp/files" || exit 1
git show :.clang-format > "$tmp/.clang-format" || exit 1
cd "$tmp" || exit 1

xargs -0 clang-format --dry-run --Werror -- < files
