2

I have three repositories: A, B, C (c++ code)

A and B are independent projects and both depends on C. The association has been made with git submodule

I create now a new project D that depends on A and B, so now C is referred two times

The project structure would be similar to the following:

D
|--A
|  |
|  C
|
|--B
   |
   C

Since different versions of D correspond to different versions of A and B I'd like to have a way to keep them synced while checking out between versions.

I was thinking about removing the submodule associations and switch to repo for all A, B and D. Does it make sense? Is there a better way to do it using only git?

Thank you

Stefano
  • 113
  • 1
  • 7
  • This is really language-independent, no need to mention a specific programming language. – Some programmer dude Jul 25 '17 at 12:58
  • 1
    Hi. Yes I know, I did it just in case :) I know there are some language dependent tool that could be helpful sometimes – Stefano Jul 25 '17 at 13:00
  • What's wrong with `git checkout --recurse-submodules`? – phd Jul 25 '17 at 13:11
  • I guess the issue might be that you might end up with multiple versions of the same submodule fetched through different intermediate dependencies. – EmDroid Jul 25 '17 at 13:29
  • exactly @axalis. Maybe I'll add some custom git hooks. not sure. There was this nice **git slave** project, but it seems quite old now – Stefano Jul 25 '17 at 13:36
  • What do you mean 'keep them synced while checking out between versions'? If you mean sync `A` with `B`, do they have the same code? – Marina Liu Jul 26 '17 at 08:52
  • Hi @Marina. No, I meant checking out the version v1.0 of A and the version v2.0 of B at the same time (of course it has to be written in some place) – Stefano Jul 26 '17 at 16:00

2 Answers2

1

One alternative to submodules that I'm using extensively within the CMake projects, is to have all the modules as independent "libraries" and use them via the find_package() CMake command (see e.g. https://cmake.org/Wiki/CMake:How_To_Find_Libraries or https://stackoverflow.com/a/20857070/1274747). Each dependency provides its own find script which is installed together with the library, and the dependent project can use it to localize the library.

That ways the project is not directly dependent on the particular "dependency" commit (but can still depend on a particular library version, as the version dependency can be also handled via the find scripts, see e.g. the FindBoost.cmake, which also handles the required version of Boost library if specified).

EmDroid
  • 5,918
  • 18
  • 18
1
  • If your project D is contribute to repo A and B, you can add them as submodules for your project D.

    But there is no way to checkout the submodules to a certain versions at the same time when you checkout a certain version for project D. The work around is use related version of D for A and B tags, and execute a script to checkout A and B to related versions.

    Such as v3.0 for D is the version related to v1.0 of A and v2.0 of B, so you can add the tags with the version v3.0.1.0 in A and v3.0.2.0 in B. When you checkout v3.0 for D, then you can run a script to checkout A and B to the version start with v3.0*.

  • If your project D is not contribute to repo A and B, you can remove the submodule associations. The code from A and B just as the subfolders for your project D and the versions of folder A and folder B can sync with the version for your project D all the time.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • Yes, I was thinking about create a custom script for that. Naming it in the right way, could allow you to use it as a git extension :) – Stefano Jul 27 '17 at 13:20
  • Whether to use git extension is depend on which tool you are operate git repo. If you use git command line to operate git repo, there is no way to use git extension, you can execute the script directly to checkout all submodules to related versions. – Marina Liu Jul 28 '17 at 07:56