2

I have been using submodules to include projects inside "super-projects".
I am running into an annoyance though where I have the same submodule included several times in one super project.

For example, say I have a project called Helpers.
Then I have a project, GeometryHelpers, that includes Helpers as a submodule.
Then I have another project called AlgebraHelpers that includes Helpers as a submodule.

So far so good, this lets me reuse my Helpers code.

However, now say I have a project called Math that has GeometryHelpers and AlgebraHelpers as submodules.
Now I have two copies of Helpers (Math/GeometryHelpers/Helpers and Math/AlgebraHelpers/Helpers).
If I have to change something in Helpers, I then have to make sure to not forget to update it in both places, or I could expect things to be out of sync.

My current update process if something in Helpers changes (which happens regularly) is:

cd Math/GeometryHelpers/Helpers; git pull
cd ..; git add -u; git commit; git push # update the pointer to Helpers in GeometryHelpers
cd ../AlgebraHelpers/Helpers; git pull; 
cd ..; git add -u; git push # update the pointer to Helpers in AlgebraHelpers
cd ..; git add -u; git push # update the pointers to AlgebraHelpers and GeometryHelpers in Math

It seems like the ideal case would be to have Math/Helpers, and have Math/AlgebraHelpers and Math/GeometryHelpers use the same Math/Helpers.
But to setup something like this, it seems like it would be hard to maintain the ability to build AlgebraHelpers in a standalone way (i.e. not inside Math).

I don't really want to build libraries and install them on the system somewhere because when I am working in GeometryHelpers and want to update something in Helpers, I'd have to go open the Helpers project, build the library, and install it to wherever GeometryHelpers is looking for it.
That is not a particularly smooth process, especially since Helpers is changing frequently.

Is there a better way to handle this?
I am using CMake as my build system and all of these projects are c++ projects.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
David Doria
  • 9,873
  • 17
  • 85
  • 147
  • Can't you solve this on the CMake-level by writing your CMakeLists, such that only a single Helpers is used in Math? – André Sep 25 '12 at 17:58
  • @Andre Yes, that is what I do now, but it just seems very dangerous. If I get one path wrong in a giant list of paths, I could be using the wrong code and not know it. – David Doria Sep 25 '12 at 18:17

1 Answers1

0

One way would be to stop recording the Helpers SHA1 at the (Algebra|Geometry)Helpers levels (ie don't initialize the submodule there) and record it at the Math level (add Helpers as a submodule there).
But that isn't practical, as the various commits of (Algebra|Geometry)Helpers won't ever know what SHA1 of Helpers there were supposed to use.

The other option would be to check if the script git new-workdir (in contrib of any git distribution since git1.7.10) could help avoiding the duplication of Helpers submodule.
See "Duplicate submodules with Git".

You would still need to commit and push each parent repos, but at least you would use only one Helpers across all parent repos.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250