Skip to content

Commit

Permalink
git: clang format C/C++ files if format file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
foxtrot committed Aug 31, 2021
1 parent 61ff50c commit 7818f36
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .git-templates/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#!/bin/bash

TOP_LEVEL=$(git rev-parse --show-toplevel)

for file in $(git diff --cached --name-only --diff-filter=ACMRTUXB | grep "\.go")
do
echo "(gofmt) $file"
gofmt -w $file
git add "$file"
done

if [ -f "$TOP_LEVEL/.clang-format" ]; then
for file in $(git diff --cached --name-only --diff-filter=ACMRTUXB | grep "\.c\|\.h\|\.hxx\|\.cpp\|\.cxx")
do
echo "(clang-format) $file"
clang-format -i -style=file "$file"
git add "$file"
done
fi

0 comments on commit 7818f36

Please sign in to comment.