#!/bin/sh
# Pre-commit git hook for SWIG repository, copy to .git/hooks/pre-commit

clang_format=clang-format
files_to_format=$(git diff-index --diff-filter=d --name-only HEAD ':Source/*/*.c' ':Source/*/*.cxx' ':Source/*/*.h')
if [ -n "$files_to_format" ]; then
    printf "Running ${clang_format} in git pre-commit hook to validate modified files...\n"
    if ! ${clang_format} --dry-run --Werror ${files_to_format}; then
        printf "Error: Fix formatting before committing, see Doc/Manual/Extending.html#Extending_coding_style_guidelines.\n"
        exit 1
    fi
fi
