#!/usr/bin/env bash

set -e

if git diff-index --quiet HEAD --; then
    echo "No changes detected, formatting is correct!"
    exit 0
else
    echo "========================================================="
    echo "Your formatting is not correct, ESPHome uses clang-format to format"
    echo "all source files in a unified way. Please apply the changes listed below"
    echo
    echo "The following files need to be changed:"
    git diff HEAD --name-only | sed 's/^/  /'
    echo
    echo
    echo "========================================================="
    echo
    git diff HEAD
    exit 1
fi
