git-clone和post-checkout钩子 [英] git-clone and post-checkout hook
问题描述
根据手册,在 git checkout
之后运行后结账
钩子(就像预期的那样)也可以在 git clone
之后(除非你传递了 - no-checkout
)。
很好,现在,考虑以下几点:$ b
$ b
- 在没有本地存储库之前, code> git clone
- 钩子不会在远程之间同步
- 与
- template
一起使用的模板目录被复制为非可执行文件,因此在git clone $ c $之后执行
(这实际上并非如Jefromi在他的回答中所陈述的那样,但钩子仍未执行) >在 git clone
之后执行后结账
钩子似乎是不可能的。不过, http:// git中的 githooks
手册页-scm.com/docs/githooks 明确规定了一种避免被执行的方法,并且在执行时还要传递参数,这将表明可以在 git-clone
。
那么,它怎么可能?
结果
我假设您可以进行自定义安装 - 重命名 ... / share / git-core / templates / hooks
中的钩子以删除 .sample
后缀。
您也可以创建一个模板目录,其中包含符号链接到存储库中的钩子目录(例如 post-checkout - > ../ ../钩/结帐后
)。然后,如果克隆的回购包含特定的钩子,它会得到执行。
然而,在大多数情况下,它是不会发生的。
编辑:我刚刚测试过,并且 - template
选项确实会保留权限,向前发展的方式。
对版本的最后一点说明:您正在网上查看文档,以获取更新版本的git,重新使用。此功能已添加到dfa7a6c(克隆:签出时运行post-checkout挂钩); git describe说这个版本直到v1.6.2-rc2才被收录。
According to the manual, the post-checkout
hook is run after a git checkout
(just as expected) but also after a git clone
(unless you pass --no-checkout
).
Very well, now, considering the following:
- you don't have a local repository before a
git clone
- hooks are not synced between remotes
hooks stored in a custom template directory used with(that is actually not true as stated by Jefromi in his answer, but the hook is still not executed)--template
are copied non-executable and therefore not executed aftergit clone
It seems impossible that a post-checkout
hook ever gets executed after a git clone
. Still, the githooks
man page at http://git-scm.com/docs/githooks explicitely states a way to avoid it being executed, and also parameters passed in case it is executed, which would indicate it is possible to execute a custom hook after a git-clone
.
So, how is it possible? I am obviously missing something here.
Turns out
I suppose you could make a custom installation - rename the hooks in .../share/git-core/templates/hooks
to remove the .sample
suffix.
You could also make a template directory full of symlinks to a hooks directory inside the repository, (e.g. post-checkout -> ../../hooks/post-checkout
). Then if the cloned repo contained that particular hook, it'd get executed.
You're right, though, in most cases it will not happen.
Edit: I just tested it, and the --template
option does appear to preserve permissions, so that's a much more straight-forward way to make it happen. What'd you see to indicate that it stripped that bit?
The final say on versions: You're looking at documentation online for a newer version of git than you're using. This feature was added in dfa7a6c (clone: run post-checkout hook when checking out); git describe says this wasn't included until v1.6.2-rc2.
这篇关于git-clone和post-checkout钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!