根据手册,post-checkout
挂钩在 git checkout
之后运行(正如预期的那样),但也在 git clone
之后运行(除非您通过了--no-checkout
)。
很好,现在,考虑以下因素:在
- 之间同步之前,您没有本地存储库
git clone
钩子未在远程
存储在与 一起使用的自定义模板目录中存储的钩子 - -template
被复制为不可执行的,因此不会在 git clone
之后执行(这实际上并不正确,正如 Jefromi 在他的回答中所述,但钩子仍然没有执行)
在 git clone
之后似乎不可能执行 post-checkout
钩子。尽管如此,http://git-scm.com/docs 上的 githooks
手册页/githooks 明确说明了避免执行它的方法,以及执行时传递的参数,这表明可以在 git-clone 后执行自定义挂钩。
那么,怎么可能呢?我显然在这里遗漏了一些东西。
事实证明
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 --template
are copied non-executable and therefore not executed after git clone
(that is actually not true as stated by Jefromi in his answer, but the hook is still not executed)
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
发布评论
评论(2)
我想您可以进行自定义安装 - 重命名
.../share/git-core/templates/hooks
中的挂钩以删除.sample
后缀。您还可以创建一个模板目录,其中充满指向存储库内的 hooks 目录的符号链接(例如
post-checkout -> ../../hooks/post-checkout
)。然后,如果克隆的存储库包含该特定钩子,它将被执行。不过,你是对的,在大多数情况下这不会发生。
编辑:我刚刚测试了它,并且
--template
选项似乎确实保留了权限,因此这是实现这一目标的更直接的方法。你看到什么表明它剥夺了那一点?关于版本的最终决定权:您正在在线查看比您正在使用的版本更新的 git 文档。此功能已在
dfa7a6c
中添加(克隆:运行 post - 结帐时的结帐钩子);git describe
表示直到 之前才包含此内容v1.6.2-rc2
。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 untilv1.6.2-rc2
.来自 githooks 文档:
此初始化作为创建克隆的一部分进行 - 请注意
builtin-clone.c
。例如:
From the githooks documentation:
This initialization takes place as part of creating a clone—note the call to
init_db
inbuiltin-clone.c
.For example: