diff --git a/.github/workflows/cygwin-test.yml b/.github/workflows/cygwin-test.yml index b612ca94a..808dc5608 100644 --- a/.github/workflows/cygwin-test.yml +++ b/.github/workflows/cygwin-test.yml @@ -46,8 +46,4 @@ jobs: shell: bash.exe -eo pipefail -o igncr "{0}" run: | /usr/bin/python -m pytest - env: - GIT_CONFIG_COUNT: "1" - GIT_CONFIG_KEY_0: protocol.file.allow - GIT_CONFIG_VALUE_0: always continue-on-error: false diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 207714810..a6af507d1 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -56,10 +56,6 @@ jobs: run: | set -x pytest - env: - GIT_CONFIG_COUNT: "1" - GIT_CONFIG_KEY_0: protocol.file.allow - GIT_CONFIG_VALUE_0: always continue-on-error: false - name: Documentation diff --git a/test/test_submodule.py b/test/test_submodule.py index 982226411..aeb6f746a 100644 --- a/test/test_submodule.py +++ b/test/test_submodule.py @@ -1,12 +1,13 @@ # -*- coding: utf-8 -*- # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php +import contextlib import os import shutil import tempfile from pathlib import Path import sys -from unittest import skipIf +from unittest import mock, skipIf import pytest @@ -31,6 +32,23 @@ import os.path as osp +@contextlib.contextmanager +def _allow_file_protocol(): + """Temporarily set protocol.file.allow to always, using environment variables.""" + pair_index = int(os.getenv("GIT_CONFIG_COUNT", "0")) + + # This is recomputed each time the context is entered, for compatibility with + # existing GIT_CONFIG_* environment variables, even if changed in this process. + patcher = mock.patch.dict(os.environ, { + "GIT_CONFIG_COUNT": str(pair_index + 1), + f"GIT_CONFIG_KEY_{pair_index}": "protocol.file.allow", + f"GIT_CONFIG_VALUE_{pair_index}": "always", + }) + + with patcher: + yield + + class TestRootProgress(RootUpdateProgress): """Just prints messages, for now without checking the correctness of the states""" @@ -709,6 +727,7 @@ def test_add_empty_repo(self, rwdir): # end for each checkout mode @with_rw_directory + @_allow_file_protocol def test_list_only_valid_submodules(self, rwdir): repo_path = osp.join(rwdir, "parent") repo = git.Repo.init(repo_path) @@ -737,6 +756,7 @@ def test_list_only_valid_submodules(self, rwdir): """, ) @with_rw_directory + @_allow_file_protocol def test_git_submodules_and_add_sm_with_new_commit(self, rwdir): parent = git.Repo.init(osp.join(rwdir, "parent")) parent.git.submodule("add", self._small_repo_url(), "module")