https://stackoverflow.com/questions/55965712/how-do-i-add-clang-formatting-to-pre-commit-hook
system
cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.4 LTS"
clang-format --version
clang-format version 10.0.0-4ubuntu1
hook (dont use)
I'm adding the following to the top of my REPO_ROOT/.git/hooks/pre-commit
file:
for FILE in $(git diff --cached --name-only)
do
clang-format -i $FILE
done
The .clang-format
file is placed in the REPO_ROOT
.
chmod a+x pre-commit
hook (use)
#!/usr/bin/env bash
for FILE in *
do
if [[ "$FILE" =~ \.(c|h|cpp|cc)$ ]]
then
echo "processing $FILE"
clang-format -i $FILE
else
echo "skip $FILE"
fi
done
沒有留言:
張貼留言