| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 968b883 commit d72ffb3
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | import contextlib | |
| 5 | 5 | import gc | |
| 6 | + from functools import lru_cache | ||
| 6 | 7 | import os | |
| 7 | 8 | import os.path as osp | |
| 8 | 9 | from pathlib import Path | |
@@ -117,22 +118,49 @@ def test_submodule_cli_lifecycle(tmp_path, monkeypatch, object_format, ref_forma | |||
| 117 | 118 | assert not parent.submodules | |
| 118 | 119 | ||
| 119 | 120 | ||
| 121 | + @pytest.fixture(scope="module") | ||
| 122 | + def movable_submodule_baseline(tmp_path_factory): | ||
| 123 | + """Prepare each logical-name layout once; only copies are handed to tests.""" | ||
| 124 | + | ||
| 125 | + @lru_cache(maxsize=None) | ||
| 126 | + def prepare(name): | ||
| 127 | + root = tmp_path_factory.mktemp("movable-submodule") | ||
| 128 | + with git.Repo.init(root / "source") as source, git.Repo.init(root / "parent") as parent: | ||
| 129 | + source.git.symbolic_ref("HEAD", "refs/heads/master") | ||
| 130 | + (root / "source/file").write_text("content", encoding="utf-8") | ||
| 131 | + source.index.add(["file"]) | ||
| 132 | + source.index.commit("Create source") | ||
| 133 | + with _patch_git_config("protocol.file.allow", "always"): | ||
| 134 | + submodule = parent.create_submodule(name, "module", source.working_tree_dir) | ||
| 135 | + parent.index.commit("Create submodule") | ||
| 136 | + submodule.module().close() | ||
| 137 | + return root / "parent" | ||
| 138 | + | ||
| 139 | + return prepare | ||
| 140 | + | ||
| 141 | + | ||
| 120 | 142 | @pytest.fixture | |
| 121 | - def movable_submodule(tmp_path, request): | ||
| 122 | - """Create a committed local submodule whose logical name stays fixed when moved.""" | ||
| 123 | - with git.Repo.init(tmp_path / "source") as source, git.Repo.init(tmp_path / "parent") as parent: | ||
| 124 | - source.git.symbolic_ref("HEAD", "refs/heads/master") | ||
| 125 | - (tmp_path / "source" / "file").write_text("content", encoding="utf-8") | ||
| 126 | - source.index.add(["file"]) | ||
| 127 | - source.index.commit("Create source") | ||
| 128 | - with _patch_git_config("protocol.file.allow", "always"): | ||
| 129 | - submodule = parent.create_submodule( | ||
| 130 | - getattr(request, "param", "logical-name"), "module", source.working_tree_dir | ||
| 131 | - ) | ||
| 132 | - parent.index.commit("Create submodule") | ||
| 133 | - # Release clone handles before Windows moves the checkout. | ||
| 134 | - submodule.module().close() | ||
| 135 | - yield submodule | ||
| 143 | + def movable_submodule(tmp_path, request, movable_submodule_baseline): | ||
| 144 | + """Give each test independent writable metadata and a fresh Python wrapper.""" | ||
| 145 | + baseline = movable_submodule_baseline(getattr(request, "param", "logical-name")) | ||
| 146 | + shutil.copytree(baseline, tmp_path / "parent", symlinks=True) | ||
| 147 | + with git.Repo(tmp_path / "parent") as parent: | ||
| 148 | + yield parent.submodules[0] | ||
| 149 | + | ||
| 150 | + | ||
| 151 | + def test_movable_submodule_copies_are_isolated(movable_submodule, movable_submodule_baseline): | ||
| 152 | + sm = movable_submodule | ||
| 153 | + baseline = movable_submodule_baseline(sm.name) | ||
| 154 | + for relative in (".git/index", ".git/config", ".git/modules/logical-name/config", "module/file"): | ||
| 155 | + copy = Path(sm.repo.working_tree_dir, relative) | ||
| 156 | + original = baseline / relative | ||
| 157 | + assert copy.read_bytes() == original.read_bytes() | ||
| 158 | + assert not copy.samefile(original) | ||
| 159 | + Path(sm.abspath, "file").write_text("changed", encoding="utf-8") | ||
| 160 | + sm.repo.create_head("copy-only") | ||
| 161 | + assert (baseline / "module/file").read_text(encoding="utf-8") == "content" | ||
| 162 | + with git.Repo(baseline) as original: | ||
| 163 | + assert "copy-only" not in original.heads | ||
| 136 | 164 | ||
| 137 | 165 | ||
| 138 | 166 | def _move_snapshot(submodule): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments