| Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 |  | 
|  | 3 | # This script reformats source files using the clang-format utility. | 
|  | 4 | # | 
|  | 5 | # Files are changed in-place, so make sure you don't have anything open in an | 
|  | 6 | # editor, and you may want to commit before formatting in case of awryness. | 
|  | 7 | # | 
|  | 8 | # This must be run on a clean repository to succeed | 
|  | 9 | # | 
|  | 10 | # Input parmameter must be full path to git repo to scan | 
|  | 11 |  | 
|  | 12 | DIR=$1 | 
|  | 13 | cd ${DIR} | 
|  | 14 |  | 
|  | 15 | echo "Formatting code under $DIR/" | 
| Andrew Geissler | 9b0105c | 2018-01-10 10:58:35 -0800 | [diff] [blame] | 16 |  | 
| Adriana Kobylak | bcee22b | 2018-01-10 16:58:27 -0600 | [diff] [blame^] | 17 | if [ -f "setup.cfg" ]; then | 
|  | 18 | pycodestyle --show-source . | 
|  | 19 | rc=$? | 
|  | 20 | if [ ${rc} -ne 0 ]; then | 
|  | 21 | exit ${rc} | 
|  | 22 | fi | 
|  | 23 | fi | 
|  | 24 |  | 
|  | 25 | if [ -f ".clang-format" ]; then | 
|  | 26 | find . -regextype sed -regex ".*\.[hc]\(pp\)\?" -not -name "*mako*" -print0 |\ | 
|  | 27 | xargs -0 "clang-format-5.0" -i | 
|  | 28 | git --no-pager diff --exit-code | 
|  | 29 | fi |