Any way to put my hook to github repo?

后端 未结 1 453
星月不相逢
星月不相逢 2021-01-06 23:56

Can I achieve it so that after pulling a repo from github the hooks has existed in .git/hooks directory?

1条回答
  •  孤城傲影
    2021-01-07 00:29

    Not directly, as that would represent a security risk (you don't know what those hook scripts are doing)

    You can try and:

    • version a file (or files) representing your hooks in your git repo
    • version a .gitattribute declaring a content filter driver (smudge script), which will trigger on git checkout.
    • in that smudge script, copy those files into your .git/hooks

    (image from "Customizing Git - Git Attributes", from "Pro Git book")

    But even in that case, you would need to activate that smudge filter with a git config command first (which can be a global config, so done before cloning the repo)

    git config --global filter.hooks.smudge 'script_to_copy_hooks'
    

    0 讨论(0)
提交回复
热议问题