Skip to content

Commit

Permalink
Merge pull request sysprog21#11 from mlouielu/patch-1
Browse files Browse the repository at this point in the history
Fix clang-format hook failed when using <filename>.h
  • Loading branch information
jserv authored Sep 26, 2019
2 parents 8292af4 + d797035 commit 0f146d6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions scripts/pre-commit.hook
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ fi
FILES=`git diff --cached --name-only --diff-filter=ACMR | grep -E "\.(c|cpp|h)$"`
for FILE in $FILES; do
nf=`git checkout-index --temp $FILE | cut -f 1`
newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1
$CLANG_FORMAT $nf > $newfile 2>> /dev/null
$DIFF -u -p -B "${nf}" "${newfile}"
tempdir=`mktemp -d` || exit 1
newfile=`mktemp ${tempdir}/${nf}.XXXXXX` || exit 1
basename=`basename $FILE`

source="${tempdir}/${basename}"
mv $nf $source
cp .clang-format $tempdir
$CLANG_FORMAT $source > $newfile 2>> /dev/null
$DIFF -u -p -B "${source}" "${newfile}"
r=$?
rm "${newfile}"
rm "${nf}"
rm -rf "${tempdir}"
if [ $r != 0 ] ; then
echo "[!] $FILE does not follow the consistent coding style." >&2
RETURN=1
Expand Down

0 comments on commit 0f146d6

Please sign in to comment.