Skip to content

Commit f67029c

Browse files
authored
Merge pull request #2205 from gitpython-developers/fixup-2202
Handle invalid submodule names during recursive updates
2 parents 2212c63 + 4299c99 commit f67029c

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

.basedpyright/baseline.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,14 +491,6 @@
491491
"lineCount": 1
492492
}
493493
},
494-
{
495-
"code": "reportPossiblyUnboundVariable",
496-
"range": {
497-
"startColumn": 15,
498-
"endColumn": 20,
499-
"lineCount": 1
500-
}
501-
},
502494
{
503495
"code": "reportArgumentType",
504496
"range": {

git/objects/submodule/base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,9 @@ def _validated_name(cls, name: str) -> str:
316316

317317
@classmethod
318318
def _module_abspath(cls, parent_repo: "Repo", path: PathLike, name: str) -> PathLike:
319+
name = cls._validated_name(name)
319320
if cls._need_gitfile_submodules(parent_repo.git):
320-
return osp.join(parent_repo.git_dir, "modules", cls._validated_name(name))
321+
return osp.join(parent_repo.git_dir, "modules", name)
321322
if parent_repo.working_tree_dir:
322323
return osp.join(parent_repo.working_tree_dir, path)
323324
raise NotADirectoryError()
@@ -747,9 +748,7 @@ def update(
747748
prefix = "DRY-RUN: "
748749
# END handle prefix
749750

750-
# To keep things plausible in dry-run mode.
751-
if dry_run:
752-
mrepo = None
751+
mrepo = None
753752
# END init mrepo
754753

755754
def fetch_remotes(module_repo: "Repo") -> None:

test/test_submodule.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,10 @@ def test_update_rejects_parent_component_in_name(self, rwdir):
971971
with pytest.raises(ValueError, match="submodule name"):
972972
Submodule._module_abspath(clone, "module", name)
973973

974+
with mock.patch.object(Submodule, "_need_gitfile_submodules", return_value=False):
975+
with pytest.raises(ValueError, match="submodule name"):
976+
Submodule._module_abspath(clone, "module", "../module")
977+
974978
@with_rw_directory
975979
@_patch_git_config("protocol.file.allow", "always")
976980
def test_root_update_keeps_going_after_invalid_submodule_name(self, rwdir):
@@ -994,6 +998,8 @@ def test_root_update_keeps_going_after_invalid_submodule_name(self, rwdir):
994998
assert not clone.submodule("../invalid").module_exists()
995999
assert clone.submodule("valid").module_exists()
9961000

1001+
clone.submodule("../invalid").update(recursive=True, keep_going=True)
1002+
9971003
@with_rw_directory
9981004
@_patch_git_config("protocol.file.allow", "always")
9991005
def test_list_only_valid_submodules(self, rwdir):

0 commit comments

Comments
 (0)