Commit git hook to repo

為{幸葍}努か 提交于 2020-06-16 04:58:11

问题


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?


回答1:


"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.

  • 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


来源:https://stackoverflow.com/questions/50836112/commit-git-hook-to-repo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!