| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2bfd829 commit 415c211
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1226,6 +1226,12 @@ def remove( | |||
| 1226 | 1226 | Doesn't work atomically, as failure to remove any part of the submodule will | |
| 1227 | 1227 | leave an inconsistent state. | |
| 1228 | 1228 | ||
| 1229 | + :note: | ||
| 1230 | + Metadata-directory aliases under ``.git/modules`` are retained. A link | ||
| 1231 | + directly to the deleted repository becomes dangling; adding or initializing | ||
| 1232 | + the submodule again recreates its target. Linked parent directories remain | ||
| 1233 | + available to sibling submodules. | ||
| 1234 | + | ||
| 1229 | 1235 | :raise git.exc.InvalidGitRepositoryError: | |
| 1230 | 1236 | Thrown if the repository cannot be deleted. | |
| 1231 | 1237 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ | |||
| 9 | 9 | import shutil | |
| 10 | 10 | import sys | |
| 11 | 11 | import tempfile | |
| 12 | + from types import SimpleNamespace | ||
| 12 | 13 | from unittest import mock, skipUnless | |
| 13 | 14 | ||
| 14 | 15 | import pytest | |
@@ -316,8 +317,9 @@ def test_submodule_allows_symlink_above_worktree( | |||
| 316 | 317 | def metadata_realpath(request): | |
| 317 | 318 | """Model Python 3.7 on Windows without altering pathlib's own resolver.""" | |
| 318 | 319 | if request.param: | |
| 319 | - with mock.patch("git.objects.submodule.base.osp", wraps=osp) as paths: | ||
| 320 | - paths.realpath.side_effect = osp.abspath | ||
| 320 | + paths = SimpleNamespace(**vars(osp)) | ||
| 321 | + paths.realpath = osp.abspath | ||
| 322 | + with mock.patch("git.objects.submodule.base.osp", paths): | ||
| 321 | 323 | yield | |
| 322 | 324 | else: | |
| 323 | 325 | yield | |
@@ -361,7 +363,7 @@ def test_submodule_allows_existing_metadata_symlinks( | |||
| 361 | 363 | ||
| 362 | 364 | Cover linked metadata directories, gitfiles, configs, and internal aliases. | |
| 363 | 365 | Update, move, and rename must retain a usable checkout; forced removal must | |
| 364 | - still remove it. | ||
| 366 | + still remove both the checkout and the resolved metadata directory. | ||
| 365 | 367 | """ | |
| 366 | 368 | sm = movable_submodule | |
| 367 | 369 | sm.rename("nested/module") | |
@@ -387,8 +389,20 @@ def test_submodule_allows_existing_metadata_symlinks( | |||
| 387 | 389 | sm.repo.git.config("--file", str(modules / "nested/module/config"), "core.worktree", str(root / "module")) | |
| 388 | 390 | assert sm.module_exists() | |
| 389 | 391 | if operation == "remove": | |
| 392 | + metadata_dir = (modules / "nested/module").resolve() | ||
| 393 | + assert metadata_dir.is_dir() | ||
| 394 | + url = sm.url | ||
| 390 | 395 | sm.remove(force=True) | |
| 391 | 396 | assert not (root / "module").exists() | |
| 397 | + assert not metadata_dir.exists() | ||
| 398 | + if kind in ("modules", "intermediate", "alias"): | ||
| 399 | + assert link.is_symlink() and link.is_dir() | ||
| 400 | + replacement = Submodule.add(sm.repo, "nested/module", "module", url) | ||
| 401 | + if kind == "leaf": | ||
| 402 | + assert link.is_symlink() and link.is_dir() | ||
| 403 | + assert target.is_dir() | ||
| 404 | + with replacement.module() as module: | ||
| 405 | + assert Path(module.git.rev_parse("--show-toplevel")).resolve() == (root / "module").resolve() | ||
| 392 | 406 | return | |
| 393 | 407 | if operation == "update": | |
| 394 | 408 | sm.update() | |
@@ -407,6 +421,36 @@ def test_submodule_allows_existing_metadata_symlinks( | |||
| 407 | 421 | assert Path(sm.abspath, "file").read_text() == "content" | |
| 408 | 422 | ||
| 409 | 423 | ||
| 424 | + @pytest.mark.parametrize("kind", ["modules", "intermediate", "leaf"]) | ||
| 425 | + def test_remove_linked_metadata_keeps_siblings_and_can_reinitialize( | ||
| 426 | + movable_submodule, tmp_path, kind, metadata_realpath | ||
| 427 | + ): | ||
| 428 | + sm = movable_submodule | ||
| 429 | + sm.rename("nested/module") | ||
| 430 | + sibling = Submodule.add(sm.repo, "nested/sibling", "sibling", sm.url) | ||
| 431 | + sm.repo.index.commit("Add sibling") | ||
| 432 | + modules = Path(sm.repo.git_dir) / "modules" | ||
| 433 | + link = {"modules": modules, "intermediate": modules / "nested", "leaf": modules / "nested/module"}[kind] | ||
| 434 | + target = tmp_path / "outside" | ||
| 435 | + link.rename(target) | ||
| 436 | + link.symlink_to(target, target_is_directory=True) | ||
| 437 | + for child in (sm, sibling): | ||
| 438 | + sm.repo.git.config("--file", str(modules / child.name / "config"), "core.worktree", str(child.abspath)) | ||
| 439 | + | ||
| 440 | + sm.remove(force=True, configuration=False) | ||
| 441 | + | ||
| 442 | + assert link.is_symlink() | ||
| 443 | + assert link.exists() == (kind != "leaf") | ||
| 444 | + with sibling.module() as module: | ||
| 445 | + assert Path(module.git.rev_parse("--show-toplevel")).resolve() == Path(sibling.abspath).resolve() | ||
| 446 | + assert Path(sibling.abspath, "file").read_text() == "content" | ||
| 447 | + sm.update(init=True) | ||
| 448 | + assert link.is_symlink() and link.is_dir() | ||
| 449 | + assert Path(sm.abspath, "file").read_text() == "content" | ||
| 450 | + with sm.module() as module: | ||
| 451 | + assert Path(module.git.rev_parse("--show-toplevel")).resolve() == Path(sm.abspath).resolve() | ||
| 452 | + | ||
| 453 | + | ||
| 410 | 454 | class TestRootProgress(RootUpdateProgress): | |
| 411 | 455 | """Just prints messages, for now without checking the correctness of the states""" | |
| 412 | 456 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments