Add support for self referencing submodules

When working with relative submodule paths, The "./" needs special
handling similar to "../".

See information on:
https://git-scm.com/docs/git-submodule
Which currently states:
"<repository> is the URL of the new submodule’s origin repository.
This may be either an absolute URL, or (if it begins with ./ or ../),
the location relative to the superproject’s default remote
repository (Please note that to specify a repository foo.git which is
located right next to a superproject bar.git, you’ll have to use
../foo.git instead of ./foo.git - as one might expect when following
the rules for relative URLs - because the evaluation of relative URLs
in Git is identical to that of relative directories)."

The implementation also was not handling file/directory names
starting with "." or "..". Explicitly look for "./" and "../"
instead.

Change-Id: I8ae68d61fb0cbb1624183b175236e98a36e4afdb
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/579182
Reviewed-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Josef Malmstrom <Josef.Malmstrom@arm.com>
Tested-by: Josef Malmstrom <Josef.Malmstrom@arm.com>
This commit is contained in:
Josef Malmström
2026-05-04 14:16:40 +02:00
committed by gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent c97a306fe7
commit 1db50e49fb
2 changed files with 83 additions and 1 deletions
+1 -1
View File
@@ -2448,7 +2448,7 @@ class Project:
result.extend(project.GetDerivedSubprojects())
continue
if url.startswith(".."):
if url.startswith(("./", "../")):
url = urllib.parse.urljoin("%s/" % self.remote.url, url)
remote = RemoteSpec(
self.remote.name,