tags:

views:

36

answers:

1

I'm trying to setup my (Zend Framework) development environment (or more importantly my directory structure) with git. However, my underlying question really has nothing to do with the specific libraries involved but more importantly how to get git to accomplish what I am wanting.

I'm going to have my project root be /home/jsuggs/project.
I'm also going to be working with/on Zend Framework (ZF), Doctrine, and other libraries, but I'll only focus on ZF since the solution for one will likely be the same for the others.

I will clone the ZF2 repository in /home/jsuggs/zf2.
I would like to have /home/jsuggs/project/application/library/Zend reference /home/jsuggs/zf2/library/Zend.

I want the ability to work locally on both repositories (project and zf2), where switching branches in zf2 directly affects project.

My question is how do I setup Git so that the deeply nested libraries can reference my local versions during development but can also be set to (other/arbitrary) locations when deployed into production?

I would also like to avoid having the paths be absolute, so that if someone else worked on the project then the library path wouldn't referencing to my home directory.

I'm looking into using symbolic links and git submodules, but wondered if there were "best practices" for this type of setup. Also, it is completely possible that I am just doing it wrong so feel free to say "just do X instead."

+1  A: 

Whenever you need to have a specific configuration (specific revisions) for different set of files, the component-based approach is best.

With symbolic link, you have no idea what exact version of zf2 your project (through the path /home/jsuggs/project/application/library/Zend) is referencing.

But with submodules, you will have:

  • the exact version of that sub component zf2 stored within your project (including a different one for production deployment, if you want to manage a "prod" branch),
  • the ability to change/modify zf2 directly from /home/jsuggs/project/application/library/Zend (provided you commit those changes within zf2, then commit the zf2 new revision within /home/jsuggs/project/application/library, i.e. your parent project).
VonC
Thanks, will likely mark this as solution. But first wanted some clarification on how to actually accomplish this with Git and submodules.When I add the reference to the zf2 submodule where should I add the reference to:a) the upstream zf2 master branch?b) my personal github clone of zf2?c) my local branch of zf2?I'd prefer to have changes to my local zf2 branch effect project instantly, but realize I may have to do "git submodule update" for them to be pulled in. Any suggestions/advice is welcomed.Thanks again for the response!
jsuggs
Also, I found the following link very helpful as submodules are somewhat confusing (or rather tricky) to get setup.http://chrisjean.com/2009/04/20/git-submodules-adding-using-removing-and-updating/
jsuggs
@jsuggs: read also http://stackoverflow.com/questions/1979167/git-submodule-update/1979194#1979194 on submodules. I like referencing local clone in order to keep every dependencies local. But once you are referencing a submodule repo, you can select in that repo whatever branch you need (provided you go back in the parent repo and commit again, in order to register that new submodule reference)
VonC
Thanks. I've been looking into submodules more and I think I'll like the setup once I get it all figured out.
jsuggs
@VonC - Slightly different issue that may need to be made a separate question. In project, I don't want the entire zf2 repository, only the library/Zend subdirectory (meaning, I don't want/need the unit tests, documentation, etc). Is there a way to "map" project:/application/library/Zend => zf2:/library/Zend
jsuggs
@jsuggs: no a git-way unless you consider zf2 repo as a parent repo with submodules in it (but that would be bad: the all content is highly inter-dependent). And a symlink wouldn't work either, since the .gitsubmodules in zf2 directory wouldn't then be seen from the parent repo. That leaves you with the sparse checkout option of the submodule (http://stackoverflow.com/questions/2586824/partial-clone-with-git-and-mercurial): I am not sure you can do a sparse checkout of a submodule though...
VonC
@VonC - Thanks again for the response. A little disappointing, but nothing that can't be worked around. It seems as though that would be a somewhat requested use case since many web projects only need a few components of larger libraries. Anyway, thanks for all the feedback!
jsuggs