git clang-format
是一个很方便的工具,它可以只在git补丁所涉及的行上运行clang-format
。我想阻止自己意外提交和推送我忘记运行git-clang-format的补丁。例如,通过向.git/hooks/pre-commit
添加一个检查,以确保git clang-format HEAD~1
没有任何事情要做。然而,它看起来并没有改变返回代码。clang-format
本身有--dry-run -Werror
:Can clang-format tell me if formatting changes are necessary?
不幸的是,git-clang-format似乎不支持它,或者有一种方法可以转发参数。有没有一种编程方法可以知道是否有更改?
$ git clang-format -Werror --diff HEAD~1 -q
usage: git clang-format [OPTIONS] [<commit>] [<commit>] [--] [<file>...]
git-clang-format: error: unrecognized arguments: -Werror
2条答案
按热度按时间brccelvz1#
作为一种解决方法,我检查stdout以查看
--diff
中是否没有更改:因为两者都使用管道,所以diff中的颜色被删除了。为了在
.git/hooks/pre-commit
钩子中保持输出中的颜色,我运行了两次...:(webghufk2#
git-clang-format
now返回错误代码% 1您应该更新LLVM安装。