小编Mar*_*ina的帖子

如何将 clang 格式添加到预提交挂钩?

我是提交钩子和 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)

git clang pre-commit-hook githooks

8
推荐指数
3
解决办法
1万
查看次数

标签 统计

clang ×1

git ×1

githooks ×1

pre-commit-hook ×1