2

I have four Rails applications (with more coming). They share:

  • stylesheets
  • javascripts
  • 3rd party gems
  • some of the same ActiveRecord models
  • our own ruby libraries
  • configuration / environment variables

I also have a bunch of rabbitmq services that interact with the above Rails applications.

I'm trying to figure out how to sanely version control all this stuff. Right now, I have everything in one giant git repository, structured like:

/sites/rails1
/sites/rails2
/sites/rails3
/services/service1
/services/service2
/services/service2
/lib/our_code
/lib/common_js
/lib/common_css
/config/common_configuration_files

Is this a sane way to do it?

If I were to break everything into their own git project, then it seems like it would suck to individually update each project each time a shared gem/library/css file was updated (with gems/bundler or whatever).

The unfortunate thing about having everything in one project is that I can't put one app or service on Heroku (easily).

Could git subtree merging help here? Maybe each site/service is its own branch?

Joe Van Dyk
  • 6,828
  • 8
  • 57
  • 73

1 Answers1

2

One repo per project. The shared stuff can go in its own repo. Assuming a constant file structure, you can use soft file links to include those directories. Git will respect those soft file links and check them in, but will not include the referenced directories in the project's repo.

Having one big repo makes your repos log hard to follow, since you will have branches that don't relate to the semantic divisions of the project (i.e., into Rails apps). Of course, all the information is there if you want to figure out what happened to a particular file or directory, but your general git log --name-status is going to include information on all projects, which is less-than desirable and also kind of hard to filter out (without creating an ad-hoc system on top of git).

Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
  • I can't count on a constant file structure. Developers develop on their own machines. I deploy to a different file structure. The CI machines run on something different (with Jenkins). Heroku uses their own. Because of all those differences, I don't think I could checkin symlinks into git. – Joe Van Dyk Jul 19 '11 at 20:05
  • Also, how does one big project make merging impossible? – Joe Van Dyk Jul 19 '11 at 20:15
  • @Joe Van Dyk, it doesn't... I'm going to edit that portion of the answer. – Dan Rosenstark Jul 19 '11 at 21:31
  • If symlinks don't work for you, that could be part of the ignored files (individual machine/server configuration). A new machine does require setup, then, but you get to do what you want otherwise. – Dan Rosenstark Jul 19 '11 at 21:35
  • Would it be a pain to do branches with multiple projects? Say I need to branch off two services, a shared library, and a Rails site. Whenever I want to change between branches, I'd need to switch branches in four different projects. We also use Github for pull requests. In this case, if another developer wants me to merge something into the 'master' branch, he'd need to submit 4 pull requests -- (and if I'm not using Github, I'd still have to do four merges). – Joe Van Dyk Jul 19 '11 at 22:49
  • @Joe Van Dyk, not to be too conservative, but that's not what branches are intended for, and using them that way will preclude you from using branches where they would otherwise be convenient. While it's true that you can branch from a branch, etc., the thing gets confusing fast. Anyway, you can try all of this out with a tiny repository (no remote repo needed) with 4 files and see how it (doesn't) work. Check out submodules (http://stackoverflow.com/questions/1540879) and http://stackoverflow.com/questions/3233562). Non-rails answers are helpful too. – Dan Rosenstark Jul 19 '11 at 23:10
  • I'm not sure why you said "branch from a branch". In case it wasn't clear, I was asking about the the case where a new feature would affect four different projects (in this case: two services, a rails site, and the shared code). When developing a new feature, I usually do it on a new branch, do the work, then merge it back into master when it's complete. I'd need to create a new branch for each of the different projects (right?). I could use git-submodules, but Heroku unfortunately doesn't support it. :( – Joe Van Dyk Jul 19 '11 at 23:27