#!/bin/sh

format_file() {
  file="${1}"
  if [ -f $file ]; then
    clang-format -i -style=file ${1} || clang-format-epita
    git add ${1}
  fi
}

case "${1}" in
  --about )
    echo "Runs clang-format on source files"
    ;;
  * )
    for file in `git diff-index --cached --name-only HEAD | grep -iE '\.(c|h)$' ` ; do
      format_file "${file}"
    done
    ;;
esac
