@@ -246,6 +246,43 @@ 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_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+ with GitConfigParser (fp_inc1 , read_only = False ) as cw :
269+ cw .set_value ("user" , "name" , "from-inc1" )
270+
271+ with GitConfigParser (fp_inc2 , read_only = False ) as cw :
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+ with open (fp_main , "w" ) as f :
277+ f .write ("[include]\n " )
278+ f .write (f"\t path = { fp_inc1 } \n " )
279+ f .write (f"\t path = { fp_inc2 } \n " )
280+
281+ with GitConfigParser (fp_main , read_only = True ) as cr :
282+ # Both included files should be loaded.
283+ assert cr .get_value ("user" , "name" ) == "from-inc1"
284+ assert cr .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