|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # This module is part of GitPython and is released under |
3 | 3 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php |
| 4 | +importcontextlib |
4 | 5 | importos |
5 | 6 | importshutil |
6 | 7 | importtempfile |
7 | 8 | frompathlibimportPath |
8 | 9 | importsys |
9 | | -fromunittestimportskipIf |
| 10 | +fromunittestimportmock, skipIf |
10 | 11 |
|
11 | 12 | importpytest |
12 | 13 |
|
|
31 | 32 | importos.pathasosp |
32 | 33 |
|
33 | 34 |
|
| 35 | +@contextlib.contextmanager |
| 36 | +def_patch_git_config(name, value): |
| 37 | +"""Temporarily add a git config name-value pair, using environment variables.""" |
| 38 | +pair_index=int(os.getenv("GIT_CONFIG_COUNT", "0")) |
| 39 | + |
| 40 | +# This is recomputed each time the context is entered, for compatibility with |
| 41 | +# existing GIT_CONFIG_* environment variables, even if changed in this process. |
| 42 | +patcher=mock.patch.dict(os.environ, { |
| 43 | +"GIT_CONFIG_COUNT": str(pair_index+1), |
| 44 | +f"GIT_CONFIG_KEY_{pair_index}": name, |
| 45 | +f"GIT_CONFIG_VALUE_{pair_index}": value, |
| 46 | + }) |
| 47 | + |
| 48 | +withpatcher: |
| 49 | +yield |
| 50 | + |
| 51 | + |
34 | 52 | classTestRootProgress(RootUpdateProgress): |
35 | 53 | """Just prints messages, for now without checking the correctness of the states""" |
36 | 54 |
|
@@ -709,6 +727,7 @@ def test_add_empty_repo(self, rwdir): |
709 | 727 | # end for each checkout mode |
710 | 728 |
|
711 | 729 | @with_rw_directory |
| 730 | +@_patch_git_config("protocol.file.allow", "always") |
712 | 731 | deftest_list_only_valid_submodules(self, rwdir): |
713 | 732 | repo_path=osp.join(rwdir, "parent") |
714 | 733 | repo=git.Repo.init(repo_path) |
@@ -737,6 +756,7 @@ def test_list_only_valid_submodules(self, rwdir): |
737 | 756 | """, |
738 | 757 | ) |
739 | 758 | @with_rw_directory |
| 759 | +@_patch_git_config("protocol.file.allow", "always") |
740 | 760 | deftest_git_submodules_and_add_sm_with_new_commit(self, rwdir): |
741 | 761 | parent=git.Repo.init(osp.join(rwdir, "parent")) |
742 | 762 | parent.git.submodule("add", self._small_repo_url(), "module") |
|
0 commit comments