【发布时间】:2019-09-21 18:12:19
【问题描述】:
我是提交钩子和 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 add
EOF
exit 1
我还将clang格式添加到package.json:
"pre-commit": "check-clang-format",
"format": "git-clang-format",
请帮我整合 clang 格式。
【问题讨论】:
-
在这里查看stackoverflow.com/questions/427207/… 了解钩子的全部内容。在使用之前了解 githooks 的工作原理。
标签: git clang githooks pre-commit-hook