#!/bin/sh # Copy this file to .git/hooks # Run clang-format before commiting files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(cpp|hpp)$') [ -z "$files" ] && exit 0 clang-format -i $files git add $files