Skip to content

Commit bed2df4

Browse files
committed
Run drive-rooted tests on their target drive
1 parent b2e9b16 commit bed2df4

3 files changed

Lines changed: 41 additions & 41 deletions

File tree

test/test_config.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from git import GitConfigParser
1515
from git.config import _OMD, cp
16-
from git.util import rmfile
16+
from git.util import cwd, rmfile
1717

1818
from test.lib import SkipTest, TestCase, fixture_path, with_rw_directory
1919

@@ -376,17 +376,18 @@ def test_config_relative_path_include(self, rw_dir):
376376
@pytest.mark.skipif(os.name != "nt", reason="Specifically for Windows drive-rooted paths.")
377377
@with_rw_directory
378378
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"
379+
with cwd(rw_dir):
380+
included_path = osp.join(rw_dir, "included")
381+
with GitConfigParser(included_path, read_only=False) as cw:
382+
cw.set_value("included", "value", "included")
383+
384+
_drive, rooted_included_path = osp.splitdrive(included_path)
385+
config_path = osp.join(rw_dir, "config")
386+
with GitConfigParser(config_path, read_only=False) as cw:
387+
cw.set_value("include", "path", rooted_included_path)
388+
389+
with GitConfigParser(config_path, read_only=True) as cr:
390+
assert cr.get_value("included", "value") == "included"
390391

391392
@with_rw_directory
392393
def test_multiple_include_paths_with_same_key(self, rw_dir):

test/test_repo.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,8 @@ def test_clone_from_keeps_env(self, rw_dir):
238238
@with_rw_directory
239239
def test_clone_from_drive_rooted_destination(self, rw_dir):
240240
original_repo = Repo.init(osp.join(rw_dir, "repo"))
241-
242-
# Drive-rooted paths resolve on the current drive. Keep the destination
243-
# there even when the system temporary directory uses another drive.
244-
with tempfile.TemporaryDirectory(dir=os.getcwd()) as destination_root:
245-
destination = osp.join(destination_root, "clone")
241+
with cwd(rw_dir):
242+
destination = osp.join(rw_dir, "clone")
246243
_drive, rooted_destination = osp.splitdrive(destination)
247244

248245
cloned = Repo.clone_from(original_repo.git_dir, rooted_destination)
@@ -1240,21 +1237,22 @@ def test_git_work_tree_dotgit_relative(self):
12401237
@pytest.mark.skipif(os.name != "nt", reason="Specifically for Windows drive-rooted paths.")
12411238
@with_rw_directory
12421239
def test_linked_worktree_drive_rooted_gitdir_file(self, rw_dir):
1243-
main_repo = self.rorepo.clone(join_path_native(rw_dir, "main_repo"))
1244-
branch = main_repo.create_head("drive-rooted-worktree")
1245-
worktree_path = join_path_native(rw_dir, "worktree_repo")
1246-
main_repo.git.worktree("add", worktree_path, branch.name)
1247-
1248-
linked_repo = Repo(worktree_path)
1249-
gitdir_file = osp.join(linked_repo.git_dir, "gitdir")
1250-
worktree_gitfile = osp.join(worktree_path, ".git")
1251-
_drive, rooted_worktree_gitfile = osp.splitdrive(worktree_gitfile)
1252-
with open(gitdir_file, "w") as stream:
1253-
stream.write(rooted_worktree_gitfile)
1254-
1255-
reopened_repo = Repo(linked_repo.git_dir)
1256-
1257-
assert osp.samefile(reopened_repo.working_tree_dir, worktree_path)
1240+
with cwd(rw_dir):
1241+
main_repo = self.rorepo.clone(join_path_native(rw_dir, "main_repo"))
1242+
branch = main_repo.create_head("drive-rooted-worktree")
1243+
worktree_path = join_path_native(rw_dir, "worktree_repo")
1244+
main_repo.git.worktree("add", worktree_path, branch.name)
1245+
1246+
linked_repo = Repo(worktree_path)
1247+
gitdir_file = osp.join(linked_repo.git_dir, "gitdir")
1248+
worktree_gitfile = osp.join(worktree_path, ".git")
1249+
_drive, rooted_worktree_gitfile = osp.splitdrive(worktree_gitfile)
1250+
with open(gitdir_file, "w") as stream:
1251+
stream.write(rooted_worktree_gitfile)
1252+
1253+
reopened_repo = Repo(linked_repo.git_dir)
1254+
1255+
assert osp.samefile(reopened_repo.working_tree_dir, worktree_path)
12581256

12591257
@with_rw_directory
12601258
def test_git_work_tree_env(self, rw_dir):

test/test_submodule.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from git.objects.submodule.base import Submodule
2727
from git.objects.submodule.root import RootModule, RootUpdateProgress
2828
from git.repo.fun import find_submodule_git_dir, touch
29-
from git.util import HIDE_WINDOWS_KNOWN_ERRORS, join_path_native, to_native_path_linux
29+
from git.util import HIDE_WINDOWS_KNOWN_ERRORS, cwd, join_path_native, to_native_path_linux
3030

3131
from test.lib import TestBase, with_rw_directory, with_rw_repo, PathLikeMock
3232

@@ -1299,16 +1299,17 @@ class Repo:
12991299
@skipUnless(sys.platform == "win32", "Specifically for Windows.")
13001300
@with_rw_directory
13011301
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}")
1302+
with cwd(rwdir):
1303+
module = git.Repo.init(osp.join(rwdir, "module"))
1304+
_drive, rooted_git_dir = osp.splitdrive(module.git_dir)
1305+
gitfile = osp.join(rwdir, "gitfile")
1306+
with open(gitfile, "w") as stream:
1307+
stream.write(f"gitdir: {rooted_git_dir}")
13071308

1308-
resolved_git_dir = find_submodule_git_dir(gitfile)
1309+
resolved_git_dir = find_submodule_git_dir(gitfile)
13091310

1310-
assert resolved_git_dir is not None
1311-
assert osp.samefile(resolved_git_dir, module.git_dir)
1311+
assert resolved_git_dir is not None
1312+
assert osp.samefile(resolved_git_dir, module.git_dir)
13121313

13131314
@pytest.mark.xfail(
13141315
reason="for some unknown reason the assertion fails, even though it in fact is working in more common setup",

0 commit comments

Comments
 (0)