Error while checking out git repository with submodules
Asked Answered
P

3

9

While deploying my tests on a Jenkins instance, I noticed that some submodules could not be initialized.

In Jenkins, I checked the checkbox for Use credentials from default remote of parent repository which made it possible to initialize the first submodule. Unfortunately, no matter what I do, the rest doesn't work.

 > git remote # timeout=10
 > git submodule init # timeout=10
 > git submodule sync # timeout=10
 > git config --get remote.origin.url # timeout=10
 > git submodule init # timeout=10
 > git config -f .gitmodules --get-regexp ^submodule\.(.+)\.url # timeout=10
 > git config --get submodule.sub1.url # timeout=10
 > git remote # timeout=10
 > git config --get remote.origin.url # timeout=10
 > git config -f .gitmodules --get submodule.sub1.path # timeout=10
using GIT_SSH to set credentials 
 > git submodule update --init --recursive sub1
 > git config --get submodule.sub2.url # timeout=10
 > git remote # timeout=10
 > git config --get remote.origin.url # timeout=10
 > git config -f .gitmodules --get submodule.sub2.path # timeout=10
using GIT_SSH to set credentials 
 > git submodule update --init --recursive sub2
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[Bitbucket] Notifying commit build result
[Bitbucket] Build result notified
hudson.plugins.git.GitException: Command "git submodule update --init --recursive sub2" returned status code 1:
stdout: 
stderr: Cloning into '/var/jenkins_home/workspace/develop/sub2'...
repository does not exist.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:xxxx/xxx.git/sub2' into submodule path '/var/jenkins_home/workspace/develop/sub2' failed
Failed to clone 'sub2'. Retry scheduled
Cloning into '/var/jenkins_home/workspace/develop/sub2'...
repository does not exist.
fatal: Could not read from remote repository.

I also checked that in .git/config, I have the proper paths to the other repositories in bitbucket.

Patriapatriarch answered 27/1, 2019 at 11:43 Comment(0)
P
1

The error has nothing to do with jenkins or bitbucket but a git misconfiguration. .git/config is not tracked, but .gitmodules is.

The path [email protected]:xxxx/xxx.git/sub2 should have made me notice the actual error, which was in .gitmodules:

[submodule "sub1"]
    path = sub1
    url = [email protected]:xxxx/sub1.git
[submodule "sub2"]
    path = sub2
    url = ./sub2

It worked locally because of the different local configuration that is not tracked by git. Basically in .gitmodules, it should be only addresses.

I made the mistake when assembling the repository and using git submodule add sub2 on a local clone instead of checking it out entirely.

Patriapatriarch answered 27/1, 2019 at 11:43 Comment(0)
N
15

I faced the same issue. Delete all submodules from their physical locations and try again:

git submodule update --init
Natalianatalie answered 4/3, 2020 at 13:15 Comment(2)
what does this mean in code: Delete all submodules from their physical locations and try again:?Maxine
That you should open the .git folder and delete the modules from there.Natalianatalie
S
4

I wanted to modify my git submodule's path and faced multiple issues with git submodule update To fix,

  1. removed the submodule related folder under ".git/modules"
  2. modify my .gitmodules file with correct path
  3. did a "git submodule deinit -f <submodule folder>" on commandline
  4. did a git "Submodule update" using my TortoiseGit
Sitarski answered 10/3, 2022 at 21:19 Comment(1)
Removing the folder from .git/modules was the key step for me that was missing. Also was able to replace step 4 with git submodule update --init.Grewitz
P
1

The error has nothing to do with jenkins or bitbucket but a git misconfiguration. .git/config is not tracked, but .gitmodules is.

The path [email protected]:xxxx/xxx.git/sub2 should have made me notice the actual error, which was in .gitmodules:

[submodule "sub1"]
    path = sub1
    url = [email protected]:xxxx/sub1.git
[submodule "sub2"]
    path = sub2
    url = ./sub2

It worked locally because of the different local configuration that is not tracked by git. Basically in .gitmodules, it should be only addresses.

I made the mistake when assembling the repository and using git submodule add sub2 on a local clone instead of checking it out entirely.

Patriapatriarch answered 27/1, 2019 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.