Skip to content

Commit dfc1286

Browse files
committed
Cover drive-rooted paths across Windows consumers
1 parent 912ddd0 commit dfc1286

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

test/test_config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,21 @@ def test_config_relative_path_include(self, rw_dir):
373373
with GitConfigParser(relative_config_path, read_only=True) as cr:
374374
assert cr.get_value("included", "value") == "included"
375375

376+
@pytest.mark.skipif(os.name != "nt", reason="Specifically for Windows drive-rooted paths.")
377+
@with_rw_directory
378+
def test_config_drive_rooted_path_include(self, rw_dir):
379+
included_path = osp.join(rw_dir, "included")
380+
with GitConfigParser(included_path, read_only=False) as cw:
381+
cw.set_value("included", "value", "included")
382+
383+
_drive, rooted_included_path = osp.splitdrive(included_path)
384+
config_path = osp.join(rw_dir, "config")
385+
with GitConfigParser(config_path, read_only=False) as cw:
386+
cw.set_value("include", "path", rooted_included_path)
387+
388+
with GitConfigParser(config_path, read_only=True) as cr:
389+
assert cr.get_value("included", "value") == "included"
390+
376391
@with_rw_directory
377392
def test_multiple_include_paths_with_same_key(self, rw_dir):
378393
"""Test that multiple 'path' entries under [include] are all respected.

test/test_repo.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,17 @@ def test_clone_from_keeps_env(self, rw_dir):
234234

235235
self.assertEqual(environment, cloned.git.environment())
236236

237+
@pytest.mark.skipif(os.name != "nt", reason="Specifically for Windows drive-rooted paths.")
238+
@with_rw_directory
239+
def test_clone_from_drive_rooted_destination(self, rw_dir):
240+
original_repo = Repo.init(osp.join(rw_dir, "repo"))
241+
destination = osp.join(rw_dir, "clone")
242+
_drive, rooted_destination = osp.splitdrive(destination)
243+
244+
cloned = Repo.clone_from(original_repo.git_dir, rooted_destination)
245+
246+
assert osp.samefile(cloned.working_tree_dir, destination)
247+
237248
@with_rw_directory
238249
def test_date_format(self, rw_dir):
239250
repo = Repo.init(osp.join(rw_dir, "repo"))
@@ -1222,6 +1233,25 @@ def test_git_work_tree_dotgit_relative(self):
12221233
# test_git_work_tree_dotgit; delegate instead
12231234
self.test_git_work_tree_dotgit(use_relative_paths=True)
12241235

1236+
@pytest.mark.skipif(os.name != "nt", reason="Specifically for Windows drive-rooted paths.")
1237+
@with_rw_directory
1238+
def test_linked_worktree_drive_rooted_gitdir_file(self, rw_dir):
1239+
main_repo = self.rorepo.clone(join_path_native(rw_dir, "main_repo"))
1240+
branch = main_repo.create_head("drive-rooted-worktree")
1241+
worktree_path = join_path_native(rw_dir, "worktree_repo")
1242+
main_repo.git.worktree("add", worktree_path, branch.name)
1243+
1244+
linked_repo = Repo(worktree_path)
1245+
gitdir_file = osp.join(linked_repo.git_dir, "gitdir")
1246+
worktree_gitfile = osp.join(worktree_path, ".git")
1247+
_drive, rooted_worktree_gitfile = osp.splitdrive(worktree_gitfile)
1248+
with open(gitdir_file, "w") as stream:
1249+
stream.write(rooted_worktree_gitfile)
1250+
1251+
reopened_repo = Repo(linked_repo.git_dir)
1252+
1253+
assert osp.samefile(reopened_repo.working_tree_dir, worktree_path)
1254+
12251255
@with_rw_directory
12261256
def test_git_work_tree_env(self, rw_dir):
12271257
"""Check that we yield to GIT_WORK_TREE."""

test/test_submodule.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,20 @@ class Repo:
12961296
self.assertRaises(ValueError, Submodule._to_relative_path, Repo(), R"\\server\share\outside")
12971297
self.assertRaises(ValueError, Submodule._to_relative_path, Repo(), R"\\?\C:\outside")
12981298

1299+
@skipUnless(sys.platform == "win32", "Specifically for Windows.")
1300+
@with_rw_directory
1301+
def test_find_submodule_git_dir_with_drive_rooted_gitfile(self, rwdir):
1302+
module = git.Repo.init(osp.join(rwdir, "module"))
1303+
_drive, rooted_git_dir = osp.splitdrive(module.git_dir)
1304+
gitfile = osp.join(rwdir, "gitfile")
1305+
with open(gitfile, "w") as stream:
1306+
stream.write(f"gitdir: {rooted_git_dir}")
1307+
1308+
resolved_git_dir = find_submodule_git_dir(gitfile)
1309+
1310+
assert resolved_git_dir is not None
1311+
assert osp.samefile(resolved_git_dir, module.git_dir)
1312+
12991313
@pytest.mark.xfail(
13001314
reason="for some unknown reason the assertion fails, even though it in fact is working in more common setup",
13011315
raises=AssertionError,

test/test_util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ def __repr__(self):
407407
class TestUtils(TestBase):
408408
"""Tests for most utilities in :mod:`git.util`."""
409409

410+
@pytest.mark.skipif(os.name != "nt", reason="Specifically for Windows drive-rooted paths.")
411+
def test_cygpath_drive_rooted_path(self):
412+
assert cygpath(R"\directory\file") == "/directory/file"
413+
410414
def test_it_should_dashify(self):
411415
self.assertEqual("this-is-my-argument", dashify("this_is_my_argument"))
412416
self.assertEqual("foo", dashify("foo"))

0 commit comments

Comments
 (0)