开发者

How to write an update hook for git submodules?

I would like to copy some files in the submodules in my "vendor/assets" directory to another 开发者_StackOverflow中文版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.


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 the post-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 in public/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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜