我是提交钩子和 Clang 格式的新手,我正在尝试将两者结合起来。我设置了预提交挂钩,并且知道如何在命令行上运行 Clang 格式,但不确定如何将其添加到文件中。
这是我在命令行中运行的用于格式化的代码:
clang-format -i -style=llvm fileName
我也试图在所有提交提交的文件上运行它。 git diff --cached --name-only
这是我的pre-commit
文件:
hook_enabled=true
# Redirect output to stderr.
exec 1>&2
# If the hook is enabled and there are one or more files added to the commit run
# code formatting.
if [ "$hook_enabled" != "false" ] &&
test $(git diff --cached --name-only $against | wc -c) != 0
then
cat <<\EOF
Code formatting changed some files, please review and re-add files with git …
Run Code Online (Sandbox Code Playgroud)