0
votes

I have 2repos. Repo1 is dependent on repo2.

I tried the following steps:

  1. Git clone repo1
  2. git submodule add repo2
  3. uploaded the .gitmodules file in VSTS of repo1 branch
  4. In Get-sources step of VSTS build, clicked on check-out submodules
  5. Added one extra step git submodule update --init.

Still the submodules files are not getting into agent. below is my .gitmodules [submodule "sm"] path = sm url = https://xxx.visualstudio.com/DefaultCollection/project/_git/sm

1

1 Answers

2
votes

It’s caused by you didn’t commit and push the sm (repo2 name) in repo1.

After you add repo2 (sm) as submodule for repo1 (git submodule add <URL for repo2>), there will create two files need to be committed:

  • .gitmodules: record the path and source to get the submodule repo (repo2).
  • sm (repo2 name): record the commit which you added the submodule repo (repo2) in repo1

These two files are both necessary for submodule. While you only uploaded .gitmodules in VSTS repo1, so even you cloned the repo1 with submodule (in Get sources step), git can’t find the commit which you add the submodule.

The correct way is commit and push the two files.

If you haven’t made other changes on the local repo after add submodule and no other change on repo1, you can use way to commit and push:

git status #make sure both the .gitmodules and sm (repo2 name) are staged (changes to be committed)
git commit -m 'commit for .gitmodules and sm (repo2 name)'
git push -f #force push