views:

55

answers:

2

Suppose Project X is the base project and Project Y depends on X. Project Y might be a plugin for Project X, or perhaps it is a standalone app that requires Project X in some other fashion.

I have thought all this time that Project Y should be the superproject, and Project X should be a submodule of Project Y.

However, upon reading this, it appears as though my thinking may be inverted. In the article, the dependency is the superproject and dependent code (in this case, plugins) are submodules. Is this the correct way to use submodules, then?

+3  A: 

It depends, but in the general case, I'd say submodules are (or can be) for both.

Clearly, if Project Y is a dependency (e.g., an external library) of Project X, it should be a submodule.

But a submodule isn't only for dependencies, it's for items that are components of a project that are developed semi-independently. A plugin is such a component: it's developed independently, but you may want to package it with the project's source.

mipadi
Hi @mipadi, thank you for your input. I wonder: is there were a way to separate dependency submodules from plugin submodules? Then a repository could enforce checkout of its dependencies (for why would one ever not wish to check them out?) while plugin submodule checkouts could remain optional.
Sam Pearson
+1  A: 

If ProjectY can live without knowing anything about ProjectX (which can be the case it it is a plugin for X), it cannot be a superproject.

If it it needs X to somehow be complete, then yes, it could be a superproject, in order to reference X within its tree (as explained in true nature of submodules).

In a component-based approach, a true superproject would be a third project which references the right version of ProjectY and ProjectX in order to record the exact configuration (i.e. list of revisions) needed for the overall project to work.


The OP add the right question: where do one stores the dependency (of Y on X)?

If one takes the component-based approach and has a ProjectZ superproject, and ProjectY has a dependency on ProjectX to build, do we not include ProjectX as a submodule in ProjectY's repository, but only in ProjectZ?
This would mean that ProjectY could not be built on its own, making it (for lack of eloquence) a sort of "implied submodule."

If you have only 2 components, one depending on the other, sure: you can directly declare ProjectX as a submodule of ProjectY.

But if ProjectY cannot been built on its own, it is not a "complete" (as in "autonomous") project anyway.
Hence a global parent "ProjectZ", where storing that dependency information outside ProjectY has its advantages:

  1. keep each module paths more visible, directly from ProjectZ root (instead of burying ProjectX potentially deep within ProjectY, making that dependency less visible to ProjectY clients)
  2. unifying ProjectX versions (if several modules need ProjectX, referencing it once in ProjectZ clearly advertise the "one official version" of ProjectX that all the other modules should use)
VonC
Thank you for your insightful answer, @VonC. If one takes the component-based approach and has a ProjectZ superproject, and ProjectY has a dependency on ProjectX to build, do we not include ProjectX as a submodule in ProjectY's repository, but only in ProjectZ? This would mean that ProjectY could not be built on its own, making it (for lack of eloquence) a sort of "implied submodule." Is this ok?
Sam Pearson
@Sam: it is better to keep separate -- if possible -- a project and its dependencies in order to: 1/ keep each module paths more visible, directly from ProjectZ root (instead of burying ProjectX potentially deep within ProjectY, making that dependency less visible to ProjectY clients) 2/ unifying ProjectX versions (if several modules need ProjectX, referencing it once in ProjectZ clearly advertise the "one official version" of ProjectX that all the other modules should use). All that being said, for just 2 modules, you can directly record ProjectX within ProjectY.
VonC
@VonC excellent. Thank you for your help!
Sam Pearson
@Sam: glad to have helped. I just updated the answer with a new take on the dependency recording discussed in the previous comments.
VonC