我在配置 tslint 和预提交挂钩时遇到问题。 重点是我创建了 tsconfig 文件,它工作得很好。并添加了 bash 脚本,如果 tslint 返回任何错误,则不允许我提交。问题是我需要为团队中的其他人提交这个挂钩文件。这应该会自动替换 .git 文件夹中的预提交挂钩。我刚刚找到了一个 bash 脚本,它检查“hooks”文件夹中的钩子并将其替换到 .git 文件夹中。我如何提交并为我的团队“自动”完成此操作?
出于安全原因,“提交挂钩”是不可能的。如果可以的话,那么某人只需克隆您的存储库并运行基本操作就可以在他们的计算机上执行任意代码。
处理此问题的两种常见方法是:
记录人们必须做什么才能让钩子在他们的存储库中运行。
自动化人们必须做什么才能获得它。例如,在使用 Makefile 的项目中,我在 Makefile 中包含此内容,人们只需运行
make setup-pre-push-hook
即可让钩子在每次推送时运行“make check”:
setup-pre-push-hook: setup-pre-push-hook-file
grep -q 'make check' .git/hooks/pre-push || \
printf '\n%s\n\n' 'make check' >> .git/hooks/pre-push
setup-pre-push-hook-file:
test -f .git/hooks/pre-push || echo '#!/bin/sh' >.git/hooks/pre-push
test -x .git/hooks/pre-push || chmod +x .git/hooks/pre-push