Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 76f3bf3

Browse filesBrowse files
committed
fix updating submodules with relative urls
This fixes running repo.update_submodules(init=True) on repositories that are using relative for the modules. Fixes #730
1 parent 85c8155 commit 76f3bf3
Copy full SHA for 76f3bf3

2 files changed

+21Lines changed: 21 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎git/objects/submodule/base.py‎

Copy file name to clipboardExpand all lines: git/objects/submodule/base.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ def _clone_repo(
353353
os.makedirs(module_abspath_dir)
354354
module_checkout_path = osp.join(str(repo.working_tree_dir), path)
355355

356+
if url.startswith('../'):
357+
remote_name = repo.active_branch.tracking_branch().remote_name
358+
repo_remote_url = repo.remote(remote_name).url
359+
url = os.path.join(repo_remote_url, url)
360+
356361
clone = git.Repo.clone_from(
357362
url,
358363
module_checkout_path,
Collapse file

‎test/test_submodule.py‎

Copy file name to clipboardExpand all lines: test/test_submodule.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,22 @@ def test_add_empty_repo(self, rwdir):
753753
)
754754
# END for each checkout mode
755755

756+
@with_rw_directory
757+
@_patch_git_config("protocol.file.allow", "always")
758+
def test_update_submodule_with_relative_path(self, rwdir):
759+
repo_path = osp.join(rwdir, "parent")
760+
repo = git.Repo.init(repo_path)
761+
module_repo_path = osp.join(rwdir, "module")
762+
module_repo = git.Repo.init(module_repo_path)
763+
module_repo.git.commit(m="test", allow_empty=True)
764+
repo.git.submodule("add", "../module", "module")
765+
repo.index.commit("add submodule")
766+
767+
cloned_repo_path = osp.join(rwdir, "cloned_repo")
768+
cloned_repo = git.Repo.clone_from(repo_path, cloned_repo_path)
769+
770+
cloned_repo.submodule_update(init=True, recursive=True)
771+
756772
@with_rw_directory
757773
@_patch_git_config("protocol.file.allow", "always")
758774
def test_list_only_valid_submodules(self, rwdir):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.