[Cargo] Dependency with git-submodule can not be fetched

I'm having some trouble with cargo and my private repository containing git-submodules.
Consider my example:
I have a crate A, B and C.
In my private repo they are relative to each other like this:



They are used like this:

Crate A
  '-----> has git submodule: crate B
Crate C
  '-----> has cargo dependency: crate A 

The git submodule is specified with a relative url.
So inside the .gitmodules file inside crate A it is specified like this:

[submodule "crate-b"]
	path = crate-b
	url = ../crate-b.git

Now when I run cargo check for crate C the following error occurs:

error: failed to get `crate-a` as a dependency of package `crate-c v0.1.0 (local/file/path)`

Caused by:
  failed to load source for dependency `crate-a`

Caused by:
  Unable to update ssh://git@my-repository.com/group_0/crate-a.git

Caused by:
  failed to update submodule `crate-b`

Caused by:
  failed to fetch submodule `crate-b` from ../crate-b.git

Caused by:
  process didn't exit successfully: `git fetch --tags --force --update-head-ok ../crate-b.git 'refs/heads/*:refs/remotes/origin/*'` (exit code: 128)
  --- stderr
  fatal: '../crate-b.git' does not appear to be a git repository
  fatal: Could not read from remote repository.

I understand why this error occurs.
Cargo tries to resolve the relative URL as is, not building the actual URL from the repository URL of crate A.
In the Cargo.toml of crate C, the dependency is:

crate-a = {git="ssh://git@my-repository.com:/group_0/crate-a.git", tag="0.1.0"}

So for checking out the submodule crate-b, cargo would just need to apply the relative URL ../crate-b.git and the result would be correct, but it doesn't.
I tried with

git-fetch-with-cli = true

and without.

I'm using relative submodule URLs to be protocol agnostic.
I read this is advisable and so far it worked fine for me.

Does anybody know how to resolve this?

Thanks in advance for any help!

I ran into a similar issue with GitLab CI where it couldn't find a remote repository when checking out sugmodules. I needed to change the URL to something like this:

[submodule "crate-b"]
	path = crate-b
	url = ../../my-organisation/crate-b.git

I also use path instead of git when specifying a dependency in Cargo.toml. So instead of crate-a = {git="ssh://git@my-repository.com:/group_0/crate-a.git", tag="0.1.0"} I would write crate-a = { path = "../vendor/crate-a" }, where vendor/ is where I keep git submodules.

Okay, but as far as I understand this makes the repository dependent on the file structure it is in.
I would like to have it working wherever it is checked out though without having to check out the other dependencies before.

Your said your private repository already has git submodules, so won't you need to check them out anyway?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.