Skip to content

Commit 3e59876

Browse files
authored
Merge pull request #2169 from gitpython-developers/fix-config-assert
Allow relative config paths with includes
2 parents f033017 + 1551238 commit 3e59876

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

git/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@ def read(self) -> None: # type: ignore[override]
634634
files_to_read = list(self._file_or_files)
635635
# END ensure we have a copy of the paths to handle
636636

637+
files_to_read = [osp.abspath(path) if isinstance(path, (str, os.PathLike)) else path for path in files_to_read]
638+
637639
seen = set(files_to_read)
638640
num_read_include_files = 0
639641
while files_to_read:

test/test_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,20 @@ def check_test_value(cr, value):
310310
with GitConfigParser(fpa, read_only=True) as cr:
311311
check_test_value(cr, tv)
312312

313+
@with_rw_directory
314+
def test_config_relative_path_include(self, rw_dir):
315+
included_path = osp.join(rw_dir, "included")
316+
with GitConfigParser(included_path, read_only=False) as cw:
317+
cw.set_value("included", "value", "included")
318+
319+
config_path = osp.join(rw_dir, "config")
320+
with GitConfigParser(config_path, read_only=False) as cw:
321+
cw.set_value("include", "path", "included")
322+
323+
relative_config_path = osp.relpath(config_path)
324+
with GitConfigParser(relative_config_path, read_only=True) as cr:
325+
assert cr.get_value("included", "value") == "included"
326+
313327
@with_rw_directory
314328
def test_multiple_include_paths_with_same_key(self, rw_dir):
315329
"""Test that multiple 'path' entries under [include] are all respected.

0 commit comments

Comments
 (0)