Skip to content

Commit 1d80891

Browse 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 1d80891

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

git/objects/submodule/base.py

Lines 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,

test/test_submodule.py

Lines 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)
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