3

We have a very large ancient flat CVS repo with an example format as below. I have imported each subdir as its own git repo with full history.

.
├── liba
├── libb
├── libc
├── prog1
├── prog2
└── prog3

Lets say that the 3 programs use libraries in the following way:

.
├── prog1
│   ├── liba
│   └── libb
├── prog2
│   ├── libb
│   └── libc
└── prog3
    ├── liba
    └── libc

Because CVS allows tagging part of the tree - we tag each library and program release with a version tag. eg liba_4x23, prog3_2x22.

We also tag the program with every version of library it uses at release (ie liba_3x19 libc_7x88)

If we release a new version of the program without a library tag - the tag stays the earliest version of the program it was used.
Now due to the way the git import works - it actually ends up at the latest version of the program (not to worried about that though)

Git submodules seem to be a very good solution for this - a version of a program can be checked out and it pulls in all the right version of libraries as submodules.

Now since all current programs are at different releases of libraries - I would need to retrofit a submodule at a particular version.

  • prog1 is linked with libb_4x50
  • prog2 is linked with libb_4x70

Assuming libb_4x70 is latest version then the example of prog2 is easy

git checkout prog2
cd prog2
git submodule add libb
.... done

So how to add libb tagged with version (not branched) 4x50 to prog1?

Other advice appreciated if you have a better idea :-)

What we may also want to do is go back 3 version of the program and set the appropriate submodules for each version. For either backwards compatibility and also as an example to management on how it will work.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Adrian Cornish
  • 23,227
  • 13
  • 61
  • 77

1 Answers1

4

The idea of submodules (as explained here) is to record a specific commit within a parent repo.

So all you need to do is, after adding libb, to checkout the right tag, and then to record that new state within the parent repo:

git checkout prog1
cd prog1
git submodule add libb
cd lib
git checkout libb_4x50 # make sure to make a branch 
                       # if you want to do any modification
                       # based on libb_4x50,
cd ..
git add -A .
git commit -m "fix correct libb version"

(For the "detached HEAD" comment, see "git submodule update * deletes uncommitted files")

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks. "The idea of submodules is to record a specific commit within a parent repo." - this is exactly the result I want. That was simpler than I thought. – Adrian Cornish Feb 16 '12 at 16:07