| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2d2ff03 commit ba57175
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -316,7 +316,8 @@ def _write_git_file_and_module_config(cls, working_tree_dir, module_abspath): | |||
| 316 | 316 | #{ Edit Interface | |
| 317 | 317 | ||
| 318 | 318 | @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): | ||
| 320 | 321 | """Add a new submodule to the given repository. This will alter the index | |
| 321 | 322 | as well as the .gitmodules file, but will not create a new commit. | |
| 322 | 323 | 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 | |||
| 349 | 350 | and is defined in `os.environ`, value from `os.environ` will be used. | |
| 350 | 351 | If you want to unset some variable, consider providing empty string | |
| 351 | 352 | as its value. | |
| 353 | + :param clone_multi_options: A list of Clone options. Please see ``git.repo.base.Repo.clone`` | ||
| 354 | + for details. | ||
| 352 | 355 | :return: The newly created submodule instance | |
| 353 | 356 | :note: works atomically, such that no change will be done if the repository | |
| 354 | 357 | update fails for instance""" | |
@@ -415,6 +418,8 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False, depth=N | |||
| 415 | 418 | kwargs['depth'] = depth | |
| 416 | 419 | else: | |
| 417 | 420 | raise ValueError("depth should be an integer") | |
| 421 | + if clone_multi_options: | ||
| 422 | + kwargs['multi_options'] = clone_multi_options | ||
| 418 | 423 | ||
| 419 | 424 | # _clone_repo(cls, repo, url, path, name, **kwargs): | |
| 420 | 425 | 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 | |||
| 449 | 454 | return sm | |
| 450 | 455 | ||
| 451 | 456 | 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): | ||
| 453 | 458 | """Update the repository of this submodule to point to the checkout | |
| 454 | 459 | we point at with the binsha of this instance. | |
| 455 | 460 | ||
@@ -480,6 +485,8 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress= | |||
| 480 | 485 | and is defined in `os.environ`, value from `os.environ` will be used. | |
| 481 | 486 | If you want to unset some variable, consider providing empty string | |
| 482 | 487 | 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. | ||
| 483 | 490 | :note: does nothing in bare repositories | |
| 484 | 491 | :note: method is definitely not atomic if recurisve is True | |
| 485 | 492 | :return: self""" | |
@@ -546,7 +553,8 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress= | |||
| 546 | 553 | progress.update(BEGIN | CLONE, 0, 1, prefix + "Cloning url '%s' to '%s' in submodule %r" % | |
| 547 | 554 | (self.url, checkout_module_abspath, self.name)) | |
| 548 | 555 | 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) | ||
| 550 | 558 | # END handle dry-run | |
| 551 | 559 | progress.update(END | CLONE, 0, 1, prefix + "Done cloning to %s" % checkout_module_abspath) | |
| 552 | 560 | ||
| 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