Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit22e0b52

Browse files
authored
Merge pull request#2100 from daniel7an/fix-issue-2099-multiple-includes
Fix GitConfigParser ignoring multiple [include] path entries
2 parents57bbea9 +1a74bce commit22e0b52

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

‎git/config.py‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,21 @@ def _included_paths(self) -> List[Tuple[str, str]]:
549549
:return:
550550
The list of paths, where each path is a tuple of (option, value).
551551
"""
552+
553+
def_all_items(section:str)->List[Tuple[str,str]]:
554+
"""Return all (key, value) pairs for a section, including duplicate keys."""
555+
return [
556+
(key,value)
557+
forkey,valuesinself._sections[section].items_all()
558+
ifkey!="__name__"
559+
forvalueinvalues
560+
]
561+
552562
paths= []
553563

554564
forsectioninself.sections():
555565
ifsection=="include":
556-
paths+=self.items(section)
566+
paths+=_all_items(section)
557567

558568
match=CONDITIONAL_INCLUDE_REGEXP.search(section)
559569
ifmatchisNoneorself._repoisNone:
@@ -579,7 +589,7 @@ def _included_paths(self) -> List[Tuple[str, str]]:
579589
)
580590
ifself._repo.git_dir:
581591
iffnmatch.fnmatchcase(os.fspath(self._repo.git_dir),value):
582-
paths+=self.items(section)
592+
paths+=_all_items(section)
583593

584594
elifkeyword=="onbranch":
585595
try:
@@ -589,11 +599,11 @@ def _included_paths(self) -> List[Tuple[str, str]]:
589599
continue
590600

591601
iffnmatch.fnmatchcase(branch_name,value):
592-
paths+=self.items(section)
602+
paths+=_all_items(section)
593603
elifkeyword=="hasconfig:remote.*.url":
594604
forremoteinself._repo.remotes:
595605
iffnmatch.fnmatchcase(remote.url,value):
596-
paths+=self.items(section)
606+
paths+=_all_items(section)
597607
break
598608
returnpaths
599609

‎test/test_config.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,43 @@ def check_test_value(cr, value):
246246
withGitConfigParser(fpa,read_only=True)ascr:
247247
check_test_value(cr,tv)
248248

249+
@with_rw_directory
250+
deftest_multiple_include_paths_with_same_key(self,rw_dir):
251+
"""Test that multiple 'path' entries under [include] are all respected.
252+
253+
Regression test for https://github.com/gitpython-developers/GitPython/issues/2099.
254+
Git config allows multiple ``path`` values under ``[include]``, e.g.::
255+
256+
[include]
257+
path = file1
258+
path = file2
259+
260+
Previously only one of these was included because _OMD.items() returns
261+
only the last value for each key.
262+
"""
263+
# Create two config files to be included.
264+
fp_inc1=osp.join(rw_dir,"inc1.cfg")
265+
fp_inc2=osp.join(rw_dir,"inc2.cfg")
266+
fp_main=osp.join(rw_dir,"main.cfg")
267+
268+
withGitConfigParser(fp_inc1,read_only=False)ascw:
269+
cw.set_value("user","name","from-inc1")
270+
271+
withGitConfigParser(fp_inc2,read_only=False)ascw:
272+
cw.set_value("core","bar","from-inc2")
273+
274+
# Write a config with two path entries under a single [include] section.
275+
# We write it manually because set_value would overwrite the key.
276+
withopen(fp_main,"w")asf:
277+
f.write("[include]\n")
278+
f.write(f"\tpath ={fp_inc1}\n")
279+
f.write(f"\tpath ={fp_inc2}\n")
280+
281+
withGitConfigParser(fp_main,read_only=True)ascr:
282+
# Both included files should be loaded.
283+
assertcr.get_value("user","name")=="from-inc1"
284+
assertcr.get_value("core","bar")=="from-inc2"
285+
249286
@pytest.mark.xfail(
250287
sys.platform=="win32",
251288
reason='Second config._has_includes() assertion fails (for "config is included if path is matching git_dir")',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp