Skip to content

Commit 11839ab

Browse files
authored
Merge pull request #1648 from EliahKagan/file-protocol
Only make config more permissive in tests that need it
2 parents 74e55ee + f6c3262 commit 11839ab

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

.github/workflows/cygwin-test.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
SHELLOPTS: igncr
1313
TMP: "/tmp"
1414
TEMP: "/tmp"
15-
15+
1616
steps:
1717
- name: Force LF line endings
1818
run: git config --global core.autocrlf input
@@ -24,9 +24,8 @@ jobs:
2424
packages: python39 python39-pip python39-virtualenv git
2525
- name: Tell git to trust this repo
2626
shell: bash.exe -eo pipefail -o igncr "{0}"
27-
run: |
28-
/usr/bin/git config --global --add safe.directory $(pwd)
29-
/usr/bin/git config --global protocol.file.allow always
27+
run: |
28+
/usr/bin/git config --global --add safe.directory "$(pwd)"
3029
- name: Install dependencies and prepare tests
3130
shell: bash.exe -eo pipefail -o igncr "{0}"
3231
run: |

.github/workflows/pythonpackage.yml

-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ jobs:
5252
set -x
5353
mypy -p git
5454
55-
- name: Tell git to trust this repo
56-
run: |
57-
/usr/bin/git config --global --add safe.directory $(pwd)
58-
/usr/bin/git config --global protocol.file.allow always
59-
6055
- name: Test with pytest
6156
run: |
6257
set -x

test/test_submodule.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# -*- coding: utf-8 -*-
22
# This module is part of GitPython and is released under
33
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
4+
import contextlib
45
import os
56
import shutil
67
import tempfile
78
from pathlib import Path
89
import sys
9-
from unittest import skipIf
10+
from unittest import mock, skipIf
1011

1112
import pytest
1213

@@ -31,6 +32,23 @@
3132
import os.path as osp
3233

3334

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+
3452
class TestRootProgress(RootUpdateProgress):
3553
"""Just prints messages, for now without checking the correctness of the states"""
3654

@@ -709,6 +727,7 @@ def test_add_empty_repo(self, rwdir):
709727
# end for each checkout mode
710728

711729
@with_rw_directory
730+
@_patch_git_config("protocol.file.allow", "always")
712731
def test_list_only_valid_submodules(self, rwdir):
713732
repo_path = osp.join(rwdir, "parent")
714733
repo = git.Repo.init(repo_path)
@@ -737,6 +756,7 @@ def test_list_only_valid_submodules(self, rwdir):
737756
""",
738757
)
739758
@with_rw_directory
759+
@_patch_git_config("protocol.file.allow", "always")
740760
def test_git_submodules_and_add_sm_with_new_commit(self, rwdir):
741761
parent = git.Repo.init(osp.join(rwdir, "parent"))
742762
parent.git.submodule("add", self._small_repo_url(), "module")

0 commit comments

Comments
 (0)