Commit f7d51f6a76fbb7593f7bec6ff7dea716eaa3385c
1 parent
f785046d
Adding nicer format script example
Showing
1 changed file
with
9 additions
and
7 deletions
scripts/clang-format-pre-commit
| @@ -9,13 +9,15 @@ format_file() { | @@ -9,13 +9,15 @@ format_file() { | ||
| 9 | file="${1}" | 9 | file="${1}" |
| 10 | case "$file" in | 10 | case "$file" in |
| 11 | *.hpp | *.cpp | .c | *.cc | *.cu | *.h ) | 11 | *.hpp | *.cpp | .c | *.cc | *.cu | *.h ) |
| 12 | - clang-format -i -style=file -sort-includes "${1}" | ||
| 13 | - if git diff-files --quiet -- "${1}" ; then | ||
| 14 | - echo "Already formatted: ${1}" | ||
| 15 | - else | ||
| 16 | - git add "${1}" | ||
| 17 | - echo "Reformatting file: ${1}" | ||
| 18 | - fi; | 12 | + if [ -f "${1}" ] ; then |
| 13 | + clang-format -i -style=file -sort-includes "${1}" | ||
| 14 | + if git diff-files --quiet -- "${1}" ; then | ||
| 15 | + echo "Already nicely formatted: ${1}" | ||
| 16 | + else | ||
| 17 | + git add "${1}" | ||
| 18 | + echo "Reformatting file: ${1}" | ||
| 19 | + fi | ||
| 20 | + fi | ||
| 19 | ;; | 21 | ;; |
| 20 | *) | 22 | *) |
| 21 | ;; | 23 | ;; |