Search code examples
gitgitlabrepositorygit-submodules

Why does my submodule fail to init on a fresh clone?


I have a git repo repoA that is the parent repo. Within, I have a submodule repoB stored at the directory repoB within the cloned repoA's directory.

Years ago, when I first started this project, I have been operating in the directory devDir where repoA is cloned to. To this day, I can push/fetch just fine within devDir.

Recently, I wanted to clone another version of repoA into demoDir. The clone of repoA into demoDir works just fine, and I can see all of the correct files. Great!

Now when I do a git submodule update --init I am hit with this error message:

user@devBox:~/repos/demoDir> git submodule update --init
Cloning into '/home/user/repos/demoDir/repoB'...
remote: 
remote: ========================================================================
remote: 
remote: ERROR: The namespace you were looking for could not be found.

remote: 
remote: ========================================================================
remote: 
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]:groupname/repoA.git/repoB' into submodule path '/home/user/repos/demoDir/repoB' failed

When I cat demoDir/.gitmodules I see

[submodule "repoB"]
        path = repoB
        url = ./repoB/

which is fine.

Then, when I cat demoDir/.git/config I see

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = [email protected]:groupname/repoA.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[submodule "repoB"]
        active = true
        url = [email protected]:groupname/repoA.git/repoB

Now that last url line is worrisome to me, as that is not the correct path to clone repoB from ( when I go to gitlab's website and click the clone button, the url it gives me is [email protected]:groupname/repoB.git).

When I edit demoDir/.git/config and change that last line to url = [email protected]:groupname/repoB.git, I can then run git submodule update --init and it is able to check everything out just fine.

The real kicker here, is when I cat devDir/.git/config I get basically the exact same output (for the submodule) as demoDir, except it's flipped

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = [email protected]:groupname/repoA.git
        fetch = +refs/heads/*:refs/remotes/origin/*
        pushurl = [email protected]:groupname/repoA.git
[branch "master"]
        remote = origin
        merge = refs/heads/master
[submodule "repoB"]
        url = [email protected]:groupname/repoA.git/repoB
        active = true

[... a bunch of branches that I don't think matter]

So how in the HECK can one clone work fine, and the other not?

I've tried running a git submodule sync but no dice.

Things I've ruled out:

  • Public key is not an issue, as I can clone repoA just fine.
  • I have verified that the paths stated in demoDir/.gitmodules and demoDir/.git/config actually exist from within the browser on gitlab's site.
  • I am the maintainter of all of these repos, so it is not an individual permissions issue,
  • I am operating on a opensuse tumbleweed, so it is not an issue of Windoze path resolution (a lot of the google answer suggest this).

Any and all help is appreciated!


Solution

  • De-initializing my submodules, and then re-initializing them worked. How did I do that?

    De-init: https://www.educative.io/answers/how-to-delete-a-git-submodule

    Add: git submodule add [email protected]:groupname/repoB.git repoB

    I then committed these changes and verified that I was able to clone fresh.