| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 430c316 commit c8ee26c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | from functools import partial | |
| 5 | 5 | from pathlib import Path | |
| 6 | + import shutil | ||
| 6 | 7 | from unittest import mock | |
| 7 | 8 | ||
| 8 | 9 | import pytest | |
@@ -22,9 +23,10 @@ def _cached_remote_refs(repo): | |||
| 22 | 23 | return {ref.path: ref.commit.hexsha for remote in repo.remotes for ref in remote.refs} | |
| 23 | 24 | ||
| 24 | 25 | ||
| 25 | - @pytest.fixture | ||
| 26 | - def local_submodule(tmp_path): | ||
| 26 | + @pytest.fixture(scope="module") | ||
| 27 | + def local_submodule_baseline(tmp_path_factory): | ||
| 27 | 28 | """Use only local repositories, with two commits already available in the clone.""" | |
| 29 | + tmp_path = tmp_path_factory.mktemp("local-submodule") | ||
| 28 | 30 | with Repo.init(tmp_path / "source") as source, Repo.init(tmp_path / "parent") as parent: | |
| 29 | 31 | # RootModule's URL-change handling currently assumes a master branch. | |
| 30 | 32 | source.git.symbolic_ref("HEAD", "refs/heads/master") | |
@@ -34,10 +36,39 @@ def local_submodule(tmp_path): | |||
| 34 | 36 | "module", "module", source.working_tree_dir, branch=source.head.reference.name | |
| 35 | 37 | ) | |
| 36 | 38 | parent.index.commit("Add submodule") | |
| 39 | + submodule.module().close() | ||
| 40 | + return tmp_path | ||
| 41 | + | ||
| 42 | + | ||
| 43 | + @pytest.fixture | ||
| 44 | + def local_submodule(tmp_path, local_submodule_baseline): | ||
| 45 | + shutil.copytree(local_submodule_baseline / "source", tmp_path / "source", symlinks=True) | ||
| 46 | + shutil.copytree(local_submodule_baseline / "parent", tmp_path / "parent", symlinks=True) | ||
| 47 | + with Repo(tmp_path / "source") as source, Repo(tmp_path / "parent") as parent: | ||
| 48 | + submodule = parent.submodules[0] | ||
| 49 | + url = Git.polish_url(source.working_tree_dir) | ||
| 50 | + with submodule.config_writer() as writer: | ||
| 51 | + writer.set_value("url", url) | ||
| 52 | + with parent.config_writer() as writer: | ||
| 53 | + writer.set_value('submodule "module"', "url", url) | ||
| 54 | + # RootModule compares URLs in committed history as well as current config. | ||
| 55 | + parent.index.commit("Relocate fixture source") | ||
| 56 | + # Re-enumerate after the config writer invalidates the submodule cache. | ||
| 57 | + submodule = parent.submodules[0] | ||
| 37 | 58 | with submodule.module() as module: | |
| 59 | + module.remotes.origin.set_url(url) | ||
| 38 | 60 | yield submodule, source, module | |
| 39 | 61 | ||
| 40 | 62 | ||
| 63 | + def test_local_submodule_source_is_isolated(local_submodule, local_submodule_baseline): | ||
| 64 | + submodule, source, module = local_submodule | ||
| 65 | + assert submodule.url == module.remotes.origin.url == Git.polish_url(source.working_tree_dir) | ||
| 66 | + remote_only = _commit_file(source, "private") | ||
| 67 | + with Repo(local_submodule_baseline / "source") as original: | ||
| 68 | + assert original.head.commit != remote_only | ||
| 69 | + assert Path(original.working_tree_dir, "file").read_text(encoding="utf-8") == "cached" | ||
| 70 | + | ||
| 71 | + | ||
| 41 | 72 | @pytest.fixture(params=["submodule", "root", "repo"]) | |
| 42 | 73 | def update_submodule(request, local_submodule): | |
| 43 | 74 | submodule, _, _ = local_submodule | |
| Back | FazBrowse Home | New Git URL |
0 commit comments