如何为 git 子模块编写更新挂钩?
我想将“vendor/assets”目录中子模块中的一些文件复制到另一个目录——“public/assets”。我听说过更新挂钩,但我不确定它们是否适用于子模块。我编写了一个简单的挂钩并从命令行运行更新,但它不起作用。
我的更新挂钩如下所示:
#.git/gooks/update.rb
#!/usr/bin/env ruby
puts "Copying files..."
那么这可能吗?
顺便说一句,我正在使用 Braid 来管理我的子模块。
I would like to copy some files in the submodules in my "vendor/assets" directory to another directory -- "public/assets." I heard about update hooks but I am not sure if they work for submodules. I wrote a simple hook and ran update from commandline, but it didn't work.
My update hook looks like this:
#.git/gooks/update.rb
#!/usr/bin/env ruby
puts "Copying files..."
So is this even possible?
btw, I'm using Braid to manage my submodules.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
update
挂钩仅在有人推送到当前存储库时运行,这听起来不像您想要的。如果您希望每次在存储库中创建提交时都将这些文件复制到位,则可以使用post-commit
挂钩。 (这应该足够了,因为当您更改子模块的提交时,您需要在主项目中提交任何子模块的新版本。这将是更新中的文件的自然点>public/assets
。)您说您的测试挂钩没有运行 - 这可能只是因为您的名称错误。更新挂钩必须是名为
.git/hooks/update
的可执行文件(注意不带.rb
后缀)。同样,提交后挂钩必须是.git/hooks/post-commit
。您不应为此任务在任何特定子模块中创建挂钩,因为挂钩将采取的操作特定于主项目。因此,您担心的更改是由于提交新版本的子模块还是只是更新任何随机文件并不重要。
对于编写钩子,您会发现官方 githooks 文档很有用,并且可能这些其他提示。
The
update
hook is only run when someone has pushed into the current repository, which doesn't sound like what you want. You could use thepost-commit
hook, if you want to copy these files into place every time you create a commit in your repository. (That should be sufficient, because you'd need to commit the new version of any submodule in the main project when you change the commit that the submodule is meant to be at. This would be a natural point to update the files inpublic/assets
.)You say that your test hook isn't being run - that may be simply because you have the name wrong. The update hook must be an executable file called
.git/hooks/update
(n.b. without a.rb
suffix). Similarly, a post-commit hook must be.git/hooks/post-commit
.You shouldn't create hooks in any particular submodule for this task, since the action the hook will be taking is specific to the main project. Because of that, it doesn't really matter whether the change you're worried about it due to committing a new version of the submodules or just updating any random file.
For writing hooks, you'll find the official githooks documentation useful, and possibly these additional tips.