Skip to content

Commit 721f623

Browse files
committed
Accept UNC share roots as rooted paths
1 parent d47df54 commit 721f623

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

git/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ def _is_path_rooted(path: PathLike) -> bool:
324324
On POSIX, which has no drive concept, this simply distinguishes absolute
325325
paths such as ``/directory`` from relative paths such as ``directory``.
326326
"""
327-
_drive, tail = osp.splitdrive(os.fspath(path))
327+
drive, tail = osp.splitdrive(os.fspath(path))
328328
separators = (os.sep,) if os.altsep is None else (os.sep, os.altsep)
329-
return tail.startswith(separators)
329+
return tail.startswith(separators) or bool(drive) and osp.isabs(path)
330330

331331

332332
def _to_relative_path(root: PathLike, path: PathLike) -> str:

test/test_index.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,15 @@ class Mocked:
10901090
actual_path = index._to_relative_path(path)
10911091
self.assertEqual(expected_path, actual_path)
10921092

1093+
@pytest.mark.skipif(sys.platform != "win32", reason="Specifically for Windows.")
1094+
def test__to_relative_path_windows_unc_share_root(self):
1095+
for repo_root in [R"\\server\share", R"\\?\UNC\server\share"]:
1096+
with self.subTest(repo_root=repo_root):
1097+
repo = mock.Mock(bare=False, git_dir=repo_root, working_tree_dir=repo_root)
1098+
index = IndexFile(repo)
1099+
1100+
self.assertEqual(index._to_relative_path(repo_root), ".")
1101+
10931102
@pytest.mark.skipif(sys.platform != "win32", reason="Specifically for Windows.")
10941103
@with_rw_directory
10951104
def test__to_relative_path_windows_path_kinds(self, rw_dir):

0 commit comments

Comments
 (0)