views:

57

answers:

2

I have a few Rails 3 apps deployed to Heroku that need to share some business logic. Apparently, although Heroku's Bundler support is pretty solid, it can't yet pull from a private Github repo. So instead I'm building a couple of gems, vendoring them into each app, checking them into git, and pushing them up with the rest of my code.

This has worked alright, but every time I want to change something in these shared gems I have to go to each app, gem unpack to the right directory, git add/git remove all the files that have changed, and so on, and it's becoming a bit of a pain. I may also want to set up different branches of my business logic, and having different applications follow different branches, but I don't know how I'd accomplish that by vendoring.

It looks like git submodules were invented for this kind of situation, but the last time I tried submodules I just found them horribly confusing, plus they apparently don't work with Heroku unless you actually check them into your repo. I suppose that's what I'd need to do, but the code snippet that Heroku gives as an example at that link is also pretty confusing.

So, my questions:

  1. Are submodules what I want to use here?
  2. What's the simplest possible git workflow I'd need in order to do what I'm describing?

I'm not a beginner with git, but I'm not quite intermediate either, and I want to start with a simple set of steps I can use to learn from. I'd need to track a local git repository from within my vendor/gems directory, pull in updates from that repository regularly, and do so in such a way that Heroku/Bundler doesn't throw a fit when I try to push the entire app to production.

Thank you!

A: 

You can use the git-subtree technique

http://progit.org/book/ch6-7.html

shingara
+1  A: 

You might find apenwarr’s git subtree command helpful. It provides a nice wrapper around Git’s subtree merge functionality.

Add a new subtree:

git subtree add --prefix=vendor/gems/shiny remote-or-url-to-shiny-gem branch

Pull new commits into the subtree:

git subtree pull --prefix=vendor/gems/shiny remote-or-url-to-shiny-gem branch

You might also like the --squash option if you do not want to incorporate the history.

You can also use git subtree to extract local commits that change the subtree so that they can be pushed to the subtree’s source repository (the split and push sub-commands).

Chris Johnsen