8

I have two code libraries A and B and have started developing an application M. All three of these are stored in their own repository.

My problem is that I have a dependency such that A uses submodule B, but M uses both submodules A and B.

As far as I can tell I'll have two copies of the same submodule B for the same main project. But it would never make sense (in this setup) for them to be different, as they represent the same library in the same application.

Is there a way to work around this, so that when I work on M I have only one copy of A and B?

Philip Pittle
  • 11,821
  • 8
  • 59
  • 123
DeadDog
  • 241
  • 2
  • 6
  • 1
    It could make sense. Say you make some change to **B** that are specific to **M** in a separate branch. It could break **A** if the changes made for **M** in **B** were not well tested etc and **A** was made to use them. If there are there are two separate copies you can be confident that **A** is using the right one (provided the `path` is fine tuned) – Bleeding Fingers Oct 17 '13 at 11:23
  • I agree that it _could_ make sense, but in the context of my current setup it won't ;) – DeadDog Oct 17 '13 at 11:46
  • Since **A** and **B** are separate libraries I build them to each their .dll file. Having two versions of B, how would I go about _choosing_ which to compile to B.dll? – DeadDog Oct 17 '13 at 11:54
  • If M's A is at sub/A and its B at sub/B, why not just tell A that B is at ../B? – jthill Oct 17 '13 at 12:57

3 Answers3

2
M--/
   |-- A
   |   |-- B
   |
   |-- B

Just remove M/B submodule from M, and keep/use M/A/B.

The reasons:

  1. For A submodule(a independent repository), it must needs B for something.
  2. For M repository, you can teach it to use M/A/B.
Yue Lin Ho
  • 2,945
  • 26
  • 36
0

As i understand in your app M hierarсhy is something like this:

M /
  |- A /
       |- B

So to add submodule B to A you should do (in folder A)

git submodule add git@github.com:username/B.git

For the app M you should do the same but with path to existing B (in folder M)

git submodule add git@github.com:username/B.git A/B
cooperok
  • 4,249
  • 3
  • 30
  • 48
  • Setting up temp repo's and testing ;) – DeadDog Oct 17 '13 at 11:28
  • Unfortunately this will not solve my problem. This solution requires me to make changes to submodule B that are specific to this application, which results in other issues. – DeadDog Oct 17 '13 at 11:52
  • I'm edited my answer. Check it. You don't need to make changes in your submodule B – cooperok Oct 17 '13 at 12:06
0

See Guenther Bunthaler's very detailed answer here

The approach would be to flatten the directories to work independently by moving the .git working directories outside of each other's project directory hierarchies.

M/
A/
B/

Where M/ has backlink submodules to both A/ and B/.
And A/ has a backlink submodule to B/.

In sort, after you have made sure that all of your submodule changes have been committed and pushed,

cd M/A
git submodule deinit -- B
rm -rf .git/modules/B
git mv -- B ../../
cd ..
git submodule deinit -- A
rm -rf .git/modules/A
git mv -- A ../
git submodule deinit -- B
rm -rf .git/modules/B
git mv -- B ../
echo "gitdir: A/.git" > "A/.git"
echo "gitdir: B/.git" > "B/.git"
cd ../A
echo "gitdir: B/.git" > "B/.git"
ergohack
  • 1,268
  • 15
  • 27