1#!/bin/bash 2 3# The latest version of this hook is available on GitHub; 4# https://github.com/sheredom/git-hooks 5# 6# This is free and unencumbered software released into the public domain. 7# 8# Anyone is free to copy, modify, publish, use, compile, sell, or 9# distribute this software, either in source code form or as a compiled 10# binary, for any purpose, commercial or non-commercial, and by any 11# means. 12# 13# In jurisdictions that recognize copyright laws, the author or authors 14# of this software dedicate any and all copyright interest in the 15# software to the public domain. We make this dedication for the benefit 16# of the public at large and to the detriment of our heirs and 17# successors. We intend this dedication to be an overt act of 18# relinquishment in perpetuity of all present and future rights to this 19# software under copyright law. 20# 21# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 22# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 24# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 25# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27# OTHER DEALINGS IN THE SOFTWARE. 28# 29# For more information, please refer to <http://unlicense.org/> 30 31# find out where clang-format is 32exe=$(which clang-format) 33 34if [ -n "$exe" ] 35then 36 # set the field separator to new line 37 IFS=$'\n' 38 39 echo "Files formatted:" 40 files=$(git diff --cached --diff-filter=AM --name-only | grep -E ".hpp$|.cpp$" | grep -v "^lib/") 41 42 # format the files 43 echo $files | xargs -n20 -P6 clang-format -i 44 45 echo $files | xargs git diff --name-only 46 47 # and then add the file (so that any formatting changes get committed) 48 echo $files | xargs git add 49else 50 echo "WARNING: clang-format was not found, cannot format files!" 51fi 52