#! /usr/bin/env bash

LAST_DIR="$PWD"
cd "$(dirname "$0")/.."

if $(\
  git diff-index HEAD --name-only -C devel/include \
    | grep -qo 'watcher/.*')
then
  tool/hone --header-content-amalgam \
    > include/watcher/watcher.hpp
fi

while read CPP_FILE
do
  if test -n "$CPP_FILE" \
    && test -f "$CPP_FILE"
  then
    clang-format -i "$CPP_FILE"
  fi
done <<< "$(\
  git diff-index HEAD --name-only \
    | grep -oE '.*\.(cpp|cc|hpp|h)$')"

cd "$LAST_DIR"
