File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -576,8 +576,11 @@ def _all_items(section: str) -> List[Tuple[str, str]]:
576576 value = match .group (2 ).strip ()
577577
578578 if keyword in ["gitdir" , "gitdir/i" ]:
579- value = osp .expanduser (value ).replace ("\\ " , "/" )
580- git_dir = os .fspath (self ._repo .git_dir ).replace ("\\ " , "/" ) if self ._repo .git_dir else None
579+ value = osp .expanduser (value )
580+ git_dir = os .fspath (self ._repo .git_dir ) if self ._repo .git_dir else None
581+ if sys .platform == "win32" :
582+ value = value .replace ("\\ " , "/" )
583+ git_dir = git_dir .replace ("\\ " , "/" ) if git_dir else None
581584
582585 drive , _tail = osp .splitdrive (value )
583586 if not drive and not any (value .startswith (s ) for s in ["./" , "/" ]):
Original file line number Diff line number Diff line change 77import io
88import os
99import os .path as osp
10+ import sys
1011from unittest import mock
1112
1213import pytest
@@ -501,6 +502,22 @@ def test_conditional_includes_from_git_dir(self, rw_dir):
501502 assert config ._has_includes ()
502503 assert config ._included_paths () == [("path" , path2 )]
503504
505+ @pytest .mark .skipif (sys .platform == "win32" , reason = "Backslashes are path separators on Windows." )
506+ @with_rw_directory
507+ def test_conditional_includes_preserve_posix_backslashes (self , rw_dir ):
508+ git_dir = osp .join (rw_dir , "target" , "repo" )
509+ repo = mock .Mock (git_dir = git_dir )
510+ config_path = osp .join (rw_dir , "config" )
511+ included_path = osp .join (rw_dir , "included" )
512+ pattern = git_dir .replace ("/target/repo" , R"/target\repo" )
513+
514+ with open (config_path , "w" ) as stream :
515+ stream .write (f'[includeIf "gitdir:{ pattern } "]\n path={ included_path } \n ' )
516+
517+ with GitConfigParser (config_path , repo = repo ) as config :
518+ assert config ._has_includes ()
519+ assert config ._included_paths () == []
520+
504521 @with_rw_directory
505522 def test_conditional_includes_from_branch_name (self , rw_dir ):
506523 # Initiate mocked branch.
You can’t perform that action at this time.
0 commit comments