0

Our compilation model consists on a super-project with 200 subprojects. My local copy tracks our development (remote) server.

I need to make a clean clone of the super-project but I'm bandwidth limited as to fetch all that info from remote server (last time I did it it took almost 7 hours to complete).

(_Note: the reason why I need a clean copy and not just a new branch on current checked out copy, is because I have to make a huge change in many projects and I want to get rid of all the binary files generated during compilation to be sure the projects are compiling correctly, at the time I don't lose current compilation for normal development).

I've read this similar answer, so I've:

git init new_copy
cd new_copy
git remote add origin file:///c/local_copy
git fetch
git checkout develop
git submodule init

So far everything is OK, but I noticed that submodules were still tracking the remote origin. So, as cited answer mentioned, I'd have to manually change the .gitmodules file to track the local copy instead. As I said, we have 200 subproject and, in addition, the URL for each submodule repository not necessarily have a pattern, as to make a simple replacement:

Sample of .gitmodules

[submodule "libs/lib1"]
    path = libs/lib1
    url = https://our-remote-server/library1.git
[submodule "istallers/installer1"]
    path = installers/installer1
    url = https://our-remote-server/the_first_installer.git
[submodule "installers/installer2"]
    path = installers/installer2
    url = https://our-remote-server/installer2.git
[submodule "apps/a_great_app"]
    path = apps/a_great_app
    url = https://our-remote-server/foobar.git

As far I've understood, I have to change the .gitmodules of the cloned repo to something like this in order to track local copies:

[submodule "libs/lib1"]
    path = libs/lib1
    url = file:///c/local_copy/libs/lib1
[submodule "istallers/installer1"]
    path = installers/installer1
    url = file:///c/local_copy/installers/installer1
[submodule "installers/installer2"]
    path = installers/installer2
    url = file:///c/local_copy/installers/installer2
[submodule "apps/a_great_app"]
    path = apps/a_great_app
    url = file:///c/local_copy/apps/a_great_app

I only need it for the initial clone, later I can restore the .gitmodules so it can track the remote origin back again.

Is there any standard / official / easy way to do it or do I have to make a script to generate the new .gitmodules files?

cbuchart
  • 10,847
  • 9
  • 53
  • 93

1 Answers1

0

Maybe with the submodule foreach statement? It applies a git command to each submodule in your gitmodules.

Check this as reference: git submodules

Andrea Nisticò
  • 466
  • 2
  • 4
  • 11
  • Thanks, I'm not very fluent with git yet, may you develop a bit your answer please? – cbuchart Jul 27 '18 at 08:16
  • The way to apply some changes to each submodule is the foreach command. Writing `git submodule foreach [any git command]` will apply the git command to each submodule. In that way you can change the URL of the modules, the only issue here that I can't really solve is how to generate the new url since there is no pattern. – Andrea Nisticò Jul 27 '18 at 08:41
  • Yes, the basic usage of `git submodule foreach` is known to me, but unfortunately it doesn't answer my question yet, that is, precisely, how to solve the URL generation problem – cbuchart Jul 27 '18 at 08:46
  • If there is no pattern about the URLs, as you said, I guess you need to write them somewhere, then you can write a simple script that reads each URL and launch the related git command with the last as parameter. In this way you don't even need to use the foreach – Andrea Nisticò Jul 27 '18 at 08:57