Skip to content

Commit bbb3d00

Browse files
authored
Merge pull request #2062 from t-webber/relative_path_submodules
Allow relative path url in submodules for submodule_update
2 parents 4d529b7 + 1ee1e78 commit bbb3d00

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

git/objects/submodule/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import stat
1212
import sys
1313
import uuid
14+
import urllib
1415

1516
import git
1617
from git.cmd import Git
@@ -799,9 +800,13 @@ def update(
799800
+ "Cloning url '%s' to '%s' in submodule %r" % (self.url, checkout_module_abspath, self.name),
800801
)
801802
if not dry_run:
803+
if self.url.startswith("."):
804+
url = urllib.parse.urljoin(self.repo.remotes.origin.url + "/", self.url)
805+
else:
806+
url = self.url
802807
mrepo = self._clone_repo(
803808
self.repo,
804-
self.url,
809+
url,
805810
self.path,
806811
self.name,
807812
n=True,

test/test_submodule.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,3 +1350,23 @@ def test_submodule_update_unsafe_options_allowed(self, rw_repo):
13501350
for unsafe_option in unsafe_options:
13511351
with self.assertRaises(GitCommandError):
13521352
submodule.update(clone_multi_options=[unsafe_option], allow_unsafe_options=True)
1353+
1354+
@with_rw_directory
1355+
@_patch_git_config("protocol.file.allow", "always")
1356+
def test_submodule_update_relative_url(self, rwdir):
1357+
parent_path = osp.join(rwdir, "parent")
1358+
parent_repo = git.Repo.init(parent_path)
1359+
submodule_path = osp.join(rwdir, "module")
1360+
submodule_repo = git.Repo.init(submodule_path)
1361+
submodule_repo.git.commit(m="initial commit", allow_empty=True)
1362+
1363+
parent_repo.git.submodule("add", "../module", "module")
1364+
parent_repo.index.commit("add submodule with relative URL")
1365+
1366+
cloned_path = osp.join(rwdir, "cloned_repo")
1367+
cloned_repo = git.Repo.clone_from(parent_path, cloned_path)
1368+
1369+
cloned_repo.submodule_update(init=True, recursive=True)
1370+
1371+
has_module = any(sm.name == "module" for sm in cloned_repo.submodules)
1372+
assert has_module, "Relative submodule was not updated properly"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy