From becb5f56c51e5a12e79aadec26ecfac15bdd0b09 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Mon, 9 Apr 2018 13:19:57 +0200 Subject: [PATCH] Adding git hook example script for clang format --- scripts/clang-format-pre-commit | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 scripts/clang-format-pre-commit diff --git a/scripts/clang-format-pre-commit b/scripts/clang-format-pre-commit new file mode 100755 index 000000000..822becb06 --- /dev/null +++ b/scripts/clang-format-pre-commit @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# To use: +# ln -s scripts/clang-format.hook .git/hooks/pre-commit + +# Based loosely on https://github.com/andrewseidl/githook-clang-format + +format_file() { + file="${1}" + case "$file" in + *.hpp | *.cpp | .c | *.cc | *.cu | *.h ) + echo "Fixing: $file" + clang-format -i -style=file "${1}" + git add "${1}" + ;; + *) + ;; + esac +} + +case "${1}" in + --about ) + echo "Runs clang-format on source files" + ;; + * ) + for file in `git diff-index --cached --name-only HEAD` ; do + format_file "${file}" + done + ;; +esac