| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -335,7 +335,7 @@ def _write_git_file_and_module_config(cls, working_tree_dir, module_abspath): | |||
| 335 | 335 | ||
| 336 | 336 | @classmethod | |
| 337 | 337 | def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = None, | |
| 338 | - branch=None, no_checkout: bool = False, depth=None, env=None | ||
| 338 | + branch=None, no_checkout: bool = False, depth=None, env=None, clone_multi_options=None | ||
| 339 | 339 | ) -> 'Submodule': | |
| 340 | 340 | """Add a new submodule to the given repository. This will alter the index | |
| 341 | 341 | as well as the .gitmodules file, but will not create a new commit. | |
@@ -369,6 +369,8 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No | |||
| 369 | 369 | and is defined in `os.environ`, value from `os.environ` will be used. | |
| 370 | 370 | If you want to unset some variable, consider providing empty string | |
| 371 | 371 | as its value. | |
| 372 | + :param clone_multi_options: A list of Clone options. Please see ``git.repo.base.Repo.clone`` | ||
| 373 | + for details. | ||
| 372 | 374 | :return: The newly created submodule instance | |
| 373 | 375 | :note: works atomically, such that no change will be done if the repository | |
| 374 | 376 | update fails for instance""" | |
@@ -435,6 +437,8 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No | |||
| 435 | 437 | kwargs['depth'] = depth | |
| 436 | 438 | else: | |
| 437 | 439 | raise ValueError("depth should be an integer") | |
| 440 | + if clone_multi_options: | ||
| 441 | + kwargs['multi_options'] = clone_multi_options | ||
| 438 | 442 | ||
| 439 | 443 | # _clone_repo(cls, repo, url, path, name, **kwargs): | |
| 440 | 444 | mrepo = cls._clone_repo(repo, url, path, name, env=env, **kwargs) | |
@@ -469,7 +473,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No | |||
| 469 | 473 | return sm | |
| 470 | 474 | ||
| 471 | 475 | def update(self, recursive=False, init=True, to_latest_revision=False, progress=None, dry_run=False, | |
| 472 | - force=False, keep_going=False, env=None): | ||
| 476 | + force=False, keep_going=False, env=None, clone_multi_options=None): | ||
| 473 | 477 | """Update the repository of this submodule to point to the checkout | |
| 474 | 478 | we point at with the binsha of this instance. | |
| 475 | 479 | ||
@@ -500,6 +504,8 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress= | |||
| 500 | 504 | and is defined in `os.environ`, value from `os.environ` will be used. | |
| 501 | 505 | If you want to unset some variable, consider providing empty string | |
| 502 | 506 | as its value. | |
| 507 | + :param clone_multi_options: list of Clone options. Please see ``git.repo.base.Repo.clone`` | ||
| 508 | + for details. Only take effect with `init` option. | ||
| 503 | 509 | :note: does nothing in bare repositories | |
| 504 | 510 | :note: method is definitely not atomic if recurisve is True | |
| 505 | 511 | :return: self""" | |
@@ -566,7 +572,8 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress= | |||
| 566 | 572 | progress.update(BEGIN | CLONE, 0, 1, prefix + "Cloning url '%s' to '%s' in submodule %r" % | |
| 567 | 573 | (self.url, checkout_module_abspath, self.name)) | |
| 568 | 574 | if not dry_run: | |
| 569 | - mrepo = self._clone_repo(self.repo, self.url, self.path, self.name, n=True, env=env) | ||
| 575 | + mrepo = self._clone_repo(self.repo, self.url, self.path, self.name, n=True, env=env, | ||
| 576 | + multi_options=clone_multi_options) | ||
| 570 | 577 | # END handle dry-run | |
| 571 | 578 | progress.update(END | CLONE, 0, 1, prefix + "Done cloning to %s" % checkout_module_abspath) | |
| 572 | 579 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ | |||
| 9 | 9 | import git | |
| 10 | 10 | from git.cmd import Git | |
| 11 | 11 | from git.compat import is_win | |
| 12 | + from git.config import GitConfigParser, cp | ||
| 12 | 13 | from git.exc import ( | |
| 13 | 14 | InvalidGitRepositoryError, | |
| 14 | 15 | RepositoryDirtyError | |
@@ -945,3 +946,68 @@ def test_depth(self, rwdir): | |||
| 945 | 946 | sm_depth = 1 | |
| 946 | 947 | sm = parent.create_submodule(sm_name, sm_name, url=self._small_repo_url(), depth=sm_depth) | |
| 947 | 948 | 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') | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments