| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | 14 | from git import GitConfigParser | |
| 15 | 15 | from git.config import _OMD, cp | |
| 16 | - from git.util import rmfile | ||
| 16 | + from git.util import cwd, rmfile | ||
| 17 | 17 | ||
| 18 | 18 | from test.lib import SkipTest, TestCase, fixture_path, with_rw_directory | |
| 19 | 19 | ||
@@ -376,17 +376,18 @@ def test_config_relative_path_include(self, rw_dir): | |||
| 376 | 376 | @pytest.mark.skipif(os.name != "nt", reason="Specifically for Windows drive-rooted paths.") | |
| 377 | 377 | @with_rw_directory | |
| 378 | 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" | ||
| 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" | ||
| 390 | 391 | ||
| 391 | 392 | @with_rw_directory | |
| 392 | 393 | def test_multiple_include_paths_with_same_key(self, rw_dir): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -238,11 +238,8 @@ def test_clone_from_keeps_env(self, rw_dir): | |||
| 238 | 238 | @with_rw_directory | |
| 239 | 239 | def test_clone_from_drive_rooted_destination(self, rw_dir): | |
| 240 | 240 | 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") | ||
| 246 | 243 | _drive, rooted_destination = osp.splitdrive(destination) | |
| 247 | 244 | ||
| 248 | 245 | cloned = Repo.clone_from(original_repo.git_dir, rooted_destination) | |
@@ -1240,21 +1237,22 @@ def test_git_work_tree_dotgit_relative(self): | |||
| 1240 | 1237 | @pytest.mark.skipif(os.name != "nt", reason="Specifically for Windows drive-rooted paths.") | |
| 1241 | 1238 | @with_rw_directory | |
| 1242 | 1239 | 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) | ||
| 1258 | 1256 | ||
| 1259 | 1257 | @with_rw_directory | |
| 1260 | 1258 | def test_git_work_tree_env(self, rw_dir): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,7 +26,7 @@ | |||
| 26 | 26 | from git.objects.submodule.base import Submodule | |
| 27 | 27 | from git.objects.submodule.root import RootModule, RootUpdateProgress | |
| 28 | 28 | 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 | ||
| 30 | 30 | ||
| 31 | 31 | from test.lib import TestBase, with_rw_directory, with_rw_repo, PathLikeMock | |
| 32 | 32 | ||
@@ -1299,16 +1299,17 @@ class Repo: | |||
| 1299 | 1299 | @skipUnless(sys.platform == "win32", "Specifically for Windows.") | |
| 1300 | 1300 | @with_rw_directory | |
| 1301 | 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}") | ||
| 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}") | ||
| 1307 | 1308 | ||
| 1308 | - resolved_git_dir = find_submodule_git_dir(gitfile) | ||
| 1309 | + resolved_git_dir = find_submodule_git_dir(gitfile) | ||
| 1309 | 1310 | ||
| 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) | ||
| 1312 | 1313 | ||
| 1313 | 1314 | @pytest.mark.xfail( | |
| 1314 | 1315 | reason="for some unknown reason the assertion fails, even though it in fact is working in more common setup", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments