Skip to content

Commit 5938ae3

Browse files
CopilotByron
andcommitted
fix: resolve relative includes from relative config paths
Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
1 parent 6c7843a commit 5938ae3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

git/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,8 @@ def read(self) -> None: # type: ignore[override]
661661
continue
662662
# END ignore relative paths if we don't know the configuration file path
663663
file_path = cast(PathLike, file_path)
664-
assert osp.isabs(file_path), "Need absolute paths to be sure our cycle checks will work"
664+
if not osp.isabs(file_path):
665+
file_path = osp.abspath(file_path)
665666
include_path = osp.join(osp.dirname(file_path), include_path)
666667
# END make include path absolute
667668
include_path = osp.normpath(include_path)

test/test_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,17 @@ def check_test_value(cr, value):
246246
with GitConfigParser(fpa, read_only=True) as cr:
247247
check_test_value(cr, tv)
248248

249+
@with_rw_directory
250+
def test_relative_include_with_relative_config_path(self, rw_dir):
251+
fpa = osp.join(rw_dir, "a")
252+
fpb = osp.join(rw_dir, "b")
253+
with GitConfigParser(fpb, read_only=False) as cw:
254+
cw.set_value("b", "value", "b")
255+
with GitConfigParser(fpa, read_only=False) as cw:
256+
cw.set_value("include", "path", "b")
257+
with GitConfigParser(osp.relpath(fpa), read_only=True) as cr:
258+
assert cr.get_value("b", "value") == "b"
259+
249260
@with_rw_directory
250261
def test_multiple_include_paths_with_same_key(self, rw_dir):
251262
"""Test that multiple 'path' entries under [include] are all respected.

0 commit comments

Comments
 (0)