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

Sign up
Appearance settings

Commit 8ad4f59

Browse files
authored
Merge pull request #1280 from Lakhtenkov-iv/feature/add-clone-multi-options-to-submodule
Added clone multi_options to Submodule
2 parents 2d2ff03 + ba57175 commit 8ad4f59

File tree

2 files changed

+77
-3
lines changed

2 files changed

+77
-3
lines changed

‎git/objects/submodule/base.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ def _write_git_file_and_module_config(cls, working_tree_dir, module_abspath):
316316
#{ Edit Interface
317317

318318
@classmethod
319-
def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=None, env=None):
319+
def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=None, env=None,
320+
clone_multi_options=None):
320321
"""Add a new submodule to the given repository. This will alter the index
321322
as well as the .gitmodules file, but will not create a new commit.
322323
If the submodule already exists, no matter if the configuration differs
@@ -349,6 +350,8 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=N
349350
and is defined in `os.environ`, value from `os.environ` will be used.
350351
If you want to unset some variable, consider providing empty string
351352
as its value.
353+
:param clone_multi_options: A list of Clone options. Please see ``git.repo.base.Repo.clone``
354+
for details.
352355
:return: The newly created submodule instance
353356
:note: works atomically, such that no change will be done if the repository
354357
update fails for instance"""
@@ -415,6 +418,8 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=N
415418
kwargs['depth'] = depth
416419
else:
417420
raise ValueError("depth should be an integer")
421+
if clone_multi_options:
422+
kwargs['multi_options'] = clone_multi_options
418423

419424
# _clone_repo(cls, repo, url, path, name, **kwargs):
420425
mrepo = cls._clone_repo(repo, url, path, name, env=env, **kwargs)
@@ -449,7 +454,7 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=N
449454
return sm
450455

451456
def update(self, recursive=False, init=True, to_latest_revision=False, progress=None, dry_run=False,
452-
force=False, keep_going=False, env=None):
457+
force=False, keep_going=False, env=None, clone_multi_options=None):
453458
"""Update the repository of this submodule to point to the checkout
454459
we point at with the binsha of this instance.
455460
@@ -480,6 +485,8 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
480485
and is defined in `os.environ`, value from `os.environ` will be used.
481486
If you want to unset some variable, consider providing empty string
482487
as its value.
488+
:param clone_multi_options: list of Clone options. Please see ``git.repo.base.Repo.clone``
489+
for details. Only take effect with `init` option.
483490
:note: does nothing in bare repositories
484491
:note: method is definitely not atomic if recurisve is True
485492
:return: self"""
@@ -546,7 +553,8 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
546553
progress.update(BEGIN | CLONE, 0, 1, prefix + "Cloning url '%s' to '%s' in submodule %r" %
547554
(self.url, checkout_module_abspath, self.name))
548555
if not dry_run:
549-
mrepo = self._clone_repo(self.repo, self.url, self.path, self.name, n=True, env=env)
556+
mrepo = self._clone_repo(self.repo, self.url, self.path, self.name, n=True, env=env,
557+
multi_options=clone_multi_options)
550558
# END handle dry-run
551559
progress.update(END | CLONE, 0, 1, prefix + "Done cloning to %s" % checkout_module_abspath)
552560

‎test/test_submodule.py‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import git
1010
from git.cmd import Git
1111
from git.compat import is_win
12+
from git.config import GitConfigParser, cp
1213
from git.exc import (
1314
InvalidGitRepositoryError,
1415
RepositoryDirtyError
@@ -945,3 +946,68 @@ def test_depth(self, rwdir):
945946
sm_depth = 1
946947
sm = parent.create_submodule(sm_name, sm_name, url=self._small_repo_url(), depth=sm_depth)
947948
self.assertEqual(len(list(sm.module().iter_commits())), sm_depth)
949+
950+
@with_rw_directory
951+
def test_update_clone_multi_options_argument(self, rwdir):
952+
#Arrange
953+
parent = git.Repo.init(osp.join(rwdir, 'parent'))
954+
sm_name = 'foo'
955+
sm_url = self._small_repo_url()
956+
sm_branch = 'refs/heads/master'
957+
sm_hexsha = git.Repo(self._small_repo_url()).head.commit.hexsha
958+
sm = Submodule(parent, bytes.fromhex(sm_hexsha), name=sm_name, path=sm_name, url=sm_url,
959+
branch_path=sm_branch)
960+
961+
#Act
962+
sm.update(init=True, clone_multi_options=['--config core.eol=true'])
963+
964+
#Assert
965+
sm_config = GitConfigParser(file_or_files=osp.join(parent.git_dir, 'modules', sm_name, 'config'))
966+
self.assertTrue(sm_config.get_value('core', 'eol'))
967+
968+
@with_rw_directory
969+
def test_update_no_clone_multi_options_argument(self, rwdir):
970+
#Arrange
971+
parent = git.Repo.init(osp.join(rwdir, 'parent'))
972+
sm_name = 'foo'
973+
sm_url = self._small_repo_url()
974+
sm_branch = 'refs/heads/master'
975+
sm_hexsha = git.Repo(self._small_repo_url()).head.commit.hexsha
976+
sm = Submodule(parent, bytes.fromhex(sm_hexsha), name=sm_name, path=sm_name, url=sm_url,
977+
branch_path=sm_branch)
978+
979+
#Act
980+
sm.update(init=True)
981+
982+
#Assert
983+
sm_config = GitConfigParser(file_or_files=osp.join(parent.git_dir, 'modules', sm_name, 'config'))
984+
with self.assertRaises(cp.NoOptionError):
985+
sm_config.get_value('core', 'eol')
986+
987+
@with_rw_directory
988+
def test_add_clone_multi_options_argument(self, rwdir):
989+
#Arrange
990+
parent = git.Repo.init(osp.join(rwdir, 'parent'))
991+
sm_name = 'foo'
992+
993+
#Act
994+
Submodule.add(parent, sm_name, sm_name, url=self._small_repo_url(),
995+
clone_multi_options=['--config core.eol=true'])
996+
997+
#Assert
998+
sm_config = GitConfigParser(file_or_files=osp.join(parent.git_dir, 'modules', sm_name, 'config'))
999+
self.assertTrue(sm_config.get_value('core', 'eol'))
1000+
1001+
@with_rw_directory
1002+
def test_add_no_clone_multi_options_argument(self, rwdir):
1003+
#Arrange
1004+
parent = git.Repo.init(osp.join(rwdir, 'parent'))
1005+
sm_name = 'foo'
1006+
1007+
#Act
1008+
Submodule.add(parent, sm_name, sm_name, url=self._small_repo_url())
1009+
1010+
#Assert
1011+
sm_config = GitConfigParser(file_or_files=osp.join(parent.git_dir, 'modules', sm_name, 'config'))
1012+
with self.assertRaises(cp.NoOptionError):
1013+
sm_config.get_value('core', 'eol')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /