问题描述
我在配置tslint和预提交钩子时遇到问题.关键是我创建了工作良好的tsconfig文件.并添加了bash脚本,如果tslint返回任何错误,该脚本将不允许我提交.问题是我需要为团队中的其他人提交此挂钩文件.这应该自动替换.git文件夹中的预提交钩子.我刚刚找到了一个bash脚本,该脚本检查我的钩子在"hooks"文件夹中,并将其替换为.git文件夹.我怎样才能做到这一点,并为我的团队自动"做到这一点?
I have a problem with configuration tslint and pre-commit hook.The point is that i created tsconfig file which work's well. And added bash script which not allow me to commit if tslint return any bugs. Problme is that i need commit this hook file for other people in my team. This should automatly replace pre-commit hook from .git folder. I just found a bash script which check my hooks in 'hooks' folder and replace them in .git folder. How can I commit this and make this 'automatically' for my team?
推荐答案
出于安全原因,挂勾"是不可能的.如果可以,那么只是克隆您的存储库并运行基本操作的人可能会在他们的计算机上执行任意代码.
"Committing a hook" is not possible for security reasons. If you could, then someone just cloning your repo and running basic operations could get arbitrary code executed on their machines.
两种常见的处理方法是:
Two common ways to deal with this are:
-
记录人们为使挂钩在其存储库中可操作而必须做的事情.
Document what people have to do to get the hook operational in their repository.
自动化人们必须做些什么才能获得它.例如,在一个使用Makefile的项目中,我在Makefile中有此文件,人们只要按下make setup-pre-push-hook
就可以使钩子在运行"make check"时运行:
Automate what people have to do to get it. For example, in a project using a Makefile, I have this in the Makefile and people can just run make setup-pre-push-hook
to get the hook to run "make check" whenever they push:
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
这篇关于提交git hook到仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!