summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/objects/submodule/base.py19
-rw-r--r--git/objects/submodule/util.py23
2 files changed, 20 insertions, 22 deletions
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index 960ff045..c95b66f2 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -335,7 +335,7 @@ class Submodule(IndexObject, TraversableIterableObj):
@classmethod
def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = None,
- branch=None, no_checkout: bool = False, depth=None, env=None
+ branch=None, no_checkout: bool = False, depth=None, env=None, clone_multi_options=None
) -> 'Submodule':
"""Add a new submodule to the given repository. This will alter the index
as well as the .gitmodules file, but will not create a new commit.
@@ -369,6 +369,8 @@ class Submodule(IndexObject, TraversableIterableObj):
and is defined in `os.environ`, value from `os.environ` will be used.
If you want to unset some variable, consider providing empty string
as its value.
+ :param clone_multi_options: A list of Clone options. Please see ``git.repo.base.Repo.clone``
+ for details.
:return: The newly created submodule instance
:note: works atomically, such that no change will be done if the repository
update fails for instance"""
@@ -381,7 +383,7 @@ class Submodule(IndexObject, TraversableIterableObj):
# assure we never put backslashes into the url, as some operating systems
# like it ...
if url is not None:
- url = to_native_path_linux(url) # to_native_path_linux does nothing??
+ url = to_native_path_linux(url)
# END assure url correctness
# INSTANTIATE INTERMEDIATE SM
@@ -389,7 +391,7 @@ class Submodule(IndexObject, TraversableIterableObj):
if sm.exists():
# reretrieve submodule from tree
try:
- sm = repo.head.commit.tree[path] # type: ignore
+ sm = repo.head.commit.tree[path]
sm._name = name
return sm
except KeyError:
@@ -435,6 +437,8 @@ class Submodule(IndexObject, TraversableIterableObj):
kwargs['depth'] = depth
else:
raise ValueError("depth should be an integer")
+ if clone_multi_options:
+ kwargs['multi_options'] = clone_multi_options
# _clone_repo(cls, repo, url, path, name, **kwargs):
mrepo = cls._clone_repo(repo, url, path, name, env=env, **kwargs)
@@ -469,7 +473,7 @@ class Submodule(IndexObject, TraversableIterableObj):
return sm
def update(self, recursive=False, init=True, to_latest_revision=False, progress=None, dry_run=False,
- force=False, keep_going=False, env=None):
+ force=False, keep_going=False, env=None, clone_multi_options=None):
"""Update the repository of this submodule to point to the checkout
we point at with the binsha of this instance.
@@ -500,6 +504,8 @@ class Submodule(IndexObject, TraversableIterableObj):
and is defined in `os.environ`, value from `os.environ` will be used.
If you want to unset some variable, consider providing empty string
as its value.
+ :param clone_multi_options: list of Clone options. Please see ``git.repo.base.Repo.clone``
+ for details. Only take effect with `init` option.
:note: does nothing in bare repositories
:note: method is definitely not atomic if recurisve is True
:return: self"""
@@ -566,7 +572,8 @@ class Submodule(IndexObject, TraversableIterableObj):
progress.update(BEGIN | CLONE, 0, 1, prefix + "Cloning url '%s' to '%s' in submodule %r" %
(self.url, checkout_module_abspath, self.name))
if not dry_run:
- mrepo = self._clone_repo(self.repo, self.url, self.path, self.name, n=True, env=env)
+ mrepo = self._clone_repo(self.repo, self.url, self.path, self.name, n=True, env=env,
+ multi_options=clone_multi_options)
# END handle dry-run
progress.update(END | CLONE, 0, 1, prefix + "Done cloning to %s" % checkout_module_abspath)
@@ -993,7 +1000,7 @@ class Submodule(IndexObject, TraversableIterableObj):
# If check is False, we might see a parent-commit that doesn't even contain the submodule anymore.
# in that case, mark our sha as being NULL
try:
- self.binsha = pctree[self.path].binsha # type: ignore
+ self.binsha = pctree[str(self.path)].binsha
except KeyError:
self.binsha = self.NULL_BIN_SHA
# end
diff --git a/git/objects/submodule/util.py b/git/objects/submodule/util.py
index cde18d08..5290000b 100644
--- a/git/objects/submodule/util.py
+++ b/git/objects/submodule/util.py
@@ -5,20 +5,11 @@ from io import BytesIO
import weakref
-# typing -----------------------------------------------------------------------
-
-from typing import Any, Sequence, TYPE_CHECKING, Union
-
-from git.types import PathLike
+from typing import Any, TYPE_CHECKING, Union
if TYPE_CHECKING:
from .base import Submodule
from weakref import ReferenceType
- from git.repo import Repo
- from git.refs import Head
- from git import Remote
- from git.refs import RemoteReference
-
__all__ = ('sm_section', 'sm_name', 'mkhead', 'find_first_remote_branch',
'SubmoduleConfigParser')
@@ -26,23 +17,23 @@ __all__ = ('sm_section', 'sm_name', 'mkhead', 'find_first_remote_branch',
#{ Utilities
-def sm_section(name: str) -> str:
+def sm_section(name):
""":return: section title used in .gitmodules configuration file"""
- return f'submodule {name}'
+ return 'submodule "%s"' % name
-def sm_name(section: str) -> str:
+def sm_name(section):
""":return: name of the submodule as parsed from the section name"""
section = section.strip()
return section[11:-1]
-def mkhead(repo: 'Repo', path: PathLike) -> 'Head':
+def mkhead(repo, path):
""":return: New branch/head instance"""
return git.Head(repo, git.Head.to_full_path(path))
-def find_first_remote_branch(remotes: Sequence['Remote'], branch_name: str) -> 'RemoteReference':
+def find_first_remote_branch(remotes, branch_name):
"""Find the remote branch matching the name of the given branch or raise InvalidGitRepositoryError"""
for remote in remotes:
try:
@@ -101,7 +92,7 @@ class SubmoduleConfigParser(GitConfigParser):
#{ Overridden Methods
def write(self) -> None:
- rval: None = super(SubmoduleConfigParser, self).write()
+ rval = super(SubmoduleConfigParser, self).write()
self.flush_to_index()
return rval
# END overridden methods