#!/bin/bash

# derived from here
# https://github.com/andrewseidl/githook-clang-format/blob/master/clang-format.hook

format_file() {
  file="${1}"

  if [ -f $file ]; then
    clang-format -style=file -i ${file}
    git add ${file}
  fi
}

# find staged files only
for file in `git diff-index --cached --name-only HEAD | grep -iE '\.(c|cpp|h|hpp|)$' ` ; do
  format_file "${file}"
done
