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:
group_0/crate_a
/crate_b
group_1/subfolder/crate_c
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
[net]
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!