From f7d51f6a76fbb7593f7bec6ff7dea716eaa3385c Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Fri, 4 May 2018 11:21:35 +0200 Subject: [PATCH] Adding nicer format script example --- scripts/clang-format-pre-commit | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/clang-format-pre-commit b/scripts/clang-format-pre-commit index 812eee48..96e178fd 100755 --- a/scripts/clang-format-pre-commit +++ b/scripts/clang-format-pre-commit @@ -9,13 +9,15 @@ format_file() { file="${1}" case "$file" in *.hpp | *.cpp | .c | *.cc | *.cu | *.h ) - clang-format -i -style=file -sort-includes "${1}" - if git diff-files --quiet -- "${1}" ; then - echo "Already formatted: ${1}" - else - git add "${1}" - echo "Reformatting file: ${1}" - fi; + if [ -f "${1}" ] ; then + clang-format -i -style=file -sort-includes "${1}" + if git diff-files --quiet -- "${1}" ; then + echo "Already nicely formatted: ${1}" + else + git add "${1}" + echo "Reformatting file: ${1}" + fi + fi ;; *) ;;