| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 958002b commit 4f18c15
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -377,6 +377,18 @@ def _clone_repo( | |||
| 377 | 377 | repo.unsafe_git_clone_options, | |
| 378 | 378 | ) | |
| 379 | 379 | allow_unsafe_options = True | |
| 380 | + if osp.islink(module_abspath): | ||
| 381 | + # Clone into the target while retaining the metadata alias. Git for | ||
| 382 | + # Windows cannot initialize through a dangling directory symlink. | ||
| 383 | + # Read the link explicitly for Python 3.7, and remove the Windows | ||
| 384 | + # namespace prefix returned by newer Python versions for Git. | ||
| 385 | + target = os.readlink(module_abspath) | ||
| 386 | + if sys.platform == "win32": | ||
| 387 | + if target.startswith("\\\\?\\UNC\\"): | ||
| 388 | + target = "\\\\" + target[8:] | ||
| 389 | + elif target.startswith("\\\\?\\"): | ||
| 390 | + target = target[4:] | ||
| 391 | + module_abspath = to_native_path_linux(osp.join(osp.dirname(module_abspath), target)) | ||
| 380 | 392 | kwargs["separate_git_dir"] = module_abspath | |
| 381 | 393 | module_abspath_dir = osp.dirname(module_abspath) | |
| 382 | 394 | if not osp.isdir(module_abspath_dir): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -451,6 +451,25 @@ def test_remove_linked_metadata_keeps_siblings_and_can_reinitialize( | |||
| 451 | 451 | assert Path(module.git.rev_parse("--show-toplevel")).resolve() == Path(sm.abspath).resolve() | |
| 452 | 452 | ||
| 453 | 453 | ||
| 454 | + @pytest.mark.parametrize("relative_target", [False, True], ids=["absolute-target", "relative-target"]) | ||
| 455 | + def test_add_to_dangling_metadata_symlink(movable_submodule, tmp_path, metadata_realpath, relative_target): | ||
| 456 | + sm = movable_submodule | ||
| 457 | + link = Path(sm.repo.git_dir) / "modules/new" | ||
| 458 | + target = tmp_path / "missing" / "metadata" | ||
| 459 | + link.symlink_to(osp.relpath(target, link.parent) if relative_target else target, target_is_directory=True) | ||
| 460 | + link_target = os.readlink(link) | ||
| 461 | + | ||
| 462 | + added = Submodule.add(sm.repo, "new", "new", sm.url) | ||
| 463 | + | ||
| 464 | + assert link.is_symlink() and link.is_dir() | ||
| 465 | + assert os.readlink(link) == link_target | ||
| 466 | + assert (target / "HEAD").is_file() | ||
| 467 | + with added.module() as module: | ||
| 468 | + assert Path(module.git_dir).resolve() == target.resolve() | ||
| 469 | + assert Path(module.git.rev_parse("--show-toplevel")).resolve() == Path(added.abspath).resolve() | ||
| 470 | + assert Path(added.abspath, "file").read_text() == "content" | ||
| 471 | + | ||
| 472 | + | ||
| 454 | 473 | class TestRootProgress(RootUpdateProgress): | |
| 455 | 474 | """Just prints messages, for now without checking the correctness of the states""" | |
| 456 | 475 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments