|
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 | +import contextlib |
4 | 5 | import os
|
5 | 6 | import shutil
|
6 | 7 | import tempfile
|
7 | 8 | from pathlib import Path
|
8 | 9 | import sys
|
9 |
| -from unittest import skipIf |
| 10 | +from unittest import mock, skipIf |
10 | 11 |
|
11 | 12 | import pytest
|
12 | 13 |
|
|
31 | 32 | import os.path as osp
|
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 | + with patcher: |
| 49 | + yield |
| 50 | + |
| 51 | + |
34 | 52 | class TestRootProgress(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 | def test_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 | def test_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