diff --git a/src/mxdev/tests/conftest.py b/src/mxdev/tests/conftest.py index b7fe338..66c8ca9 100644 --- a/src/mxdev/tests/conftest.py +++ b/src/mxdev/tests/conftest.py @@ -1,5 +1,6 @@ import os import pytest +from .utils import Process @pytest.fixture @@ -33,6 +34,22 @@ def _mkgitrepo(name): return _mkgitrepo +@pytest.fixture +def git_allow_file_protocol(): + """ + Allow file protocol + This is needed for the submodule to be added from a local path + """ + from .utils import GitRepo + + shell = Process() + file_allow = shell.check_call("git config --global --get protocol.file.allow")[0].decode("utf8").strip() + shell.check_call(f"git config --global protocol.file.allow always") + yield file_allow + shell.check_call(f"git config --global protocol.file.allow {file_allow}") + + + @pytest.fixture def develop(src): from mxdev.tests.utils import MockDevelop diff --git a/src/mxdev/tests/test_git_submodules.py b/src/mxdev/tests/test_git_submodules.py index 9293263..24b6856 100644 --- a/src/mxdev/tests/test_git_submodules.py +++ b/src/mxdev/tests/test_git_submodules.py @@ -10,7 +10,7 @@ @pytest.mark.skipif( condition=os.name == "nt", reason="submodules seem not to work on windows" ) -def test_checkout_with_submodule(mkgitrepo, src, caplog): +def test_checkout_with_submodule(mkgitrepo, src, caplog, git_allow_file_protocol): """ Tests the checkout of a module 'egg' with a submodule 'submodule_a' in itith """ @@ -50,7 +50,7 @@ def test_checkout_with_submodule(mkgitrepo, src, caplog): @pytest.mark.skipif( condition=os.name == "nt", reason="submodules seem not to work on windows" ) -def test_checkout_with_two_submodules(mkgitrepo, src): +def test_checkout_with_two_submodules(mkgitrepo, src, git_allow_file_protocol): """ Tests the checkout of a module 'egg' with a submodule 'submodule_a' and a submodule 'submodule_b' in it. @@ -102,7 +102,7 @@ def test_checkout_with_two_submodules(mkgitrepo, src): @pytest.mark.skipif( condition=os.name == "nt", reason="submodules seem not to work on windows" ) -def test_checkout_with_two_submodules_recursive(mkgitrepo, src): +def test_checkout_with_two_submodules_recursive(mkgitrepo, src, git_allow_file_protocol): """ Tests the checkout of a module 'egg' with a submodule 'submodule_a' and a submodule 'submodule_b' in it. @@ -145,7 +145,7 @@ def test_checkout_with_two_submodules_recursive(mkgitrepo, src): @pytest.mark.skipif( condition=os.name == "nt", reason="submodules seem not to work on windows" ) -def test_update_with_submodule(mkgitrepo, src): +def test_update_with_submodule(mkgitrepo, src, git_allow_file_protocol): """ Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it. Add a new 'submodule_b' to 'egg' and check it succesfully initializes. @@ -208,7 +208,7 @@ def test_update_with_submodule(mkgitrepo, src): @pytest.mark.skipif( condition=os.name == "nt", reason="submodules seem not to work on windows" ) -def test_update_with_submodule_recursive(mkgitrepo, src): +def test_update_with_submodule_recursive(mkgitrepo, src, git_allow_file_protocol): """ Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it. Add a new 'submodule_b' to 'egg' and check it succesfully initializes. @@ -265,7 +265,7 @@ def test_update_with_submodule_recursive(mkgitrepo, src): @pytest.mark.skipif( condition=os.name == "nt", reason="submodules seem not to work on windows" ) -def test_checkout_with_submodules_option_never(mkgitrepo, src): +def test_checkout_with_submodules_option_never(mkgitrepo, src, git_allow_file_protocol): """ Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it without initializing the submodule, restricted by global 'never' @@ -297,7 +297,7 @@ def test_checkout_with_submodules_option_never(mkgitrepo, src): @pytest.mark.skipif( condition=os.name == "nt", reason="submodules seem not to work on windows" ) -def test_checkout_with_submodules_option_never_source_always(mkgitrepo, src): +def test_checkout_with_submodules_option_never_source_always(mkgitrepo, src, git_allow_file_protocol): """ Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it and a module 'egg2' with the same submodule, initializing only the submodule @@ -358,7 +358,7 @@ def test_checkout_with_submodules_option_never_source_always(mkgitrepo, src): @pytest.mark.skipif( condition=os.name == "nt", reason="submodules seem not to work on windows" ) -def test_checkout_with_submodules_option_always_source_never(mkgitrepo, src): +def test_checkout_with_submodules_option_always_source_never(mkgitrepo, src, git_allow_file_protocol): """ Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it and a module 'egg2' with the same submodule, not initializing the submodule @@ -418,7 +418,7 @@ def test_checkout_with_submodules_option_always_source_never(mkgitrepo, src): @pytest.mark.skipif( condition=os.name == "nt", reason="submodules seem not to work on windows" ) -def test_update_with_submodule_checkout(mkgitrepo, src): +def test_update_with_submodule_checkout(mkgitrepo, src, git_allow_file_protocol): """ Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it. Add a new 'submodule_b' to 'egg' and check it doesn't get initialized. @@ -482,7 +482,7 @@ def test_update_with_submodule_checkout(mkgitrepo, src): @pytest.mark.skipif( condition=os.name == "nt", reason="submodules seem not to work on windows" ) -def test_update_with_submodule_dont_update_previous_submodules(mkgitrepo, src): +def test_update_with_submodule_dont_update_previous_submodules(mkgitrepo, src, git_allow_file_protocol): """ Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it. Commits changes in the detached submodule, and checks update didn't break diff --git a/src/mxdev/tests/utils.py b/src/mxdev/tests/utils.py index 5307b41..41adb48 100644 --- a/src/mxdev/tests/utils.py +++ b/src/mxdev/tests/utils.py @@ -167,10 +167,7 @@ def add_file(self, fname, msg=None): def add_submodule(self, submodule: "GitRepo", submodule_name: str): assert isinstance(submodule, GitRepo) assert isinstance(submodule_name, str) - - # Allow file protocol - # This is needed for the submodule to be added from a local path - self("git config --global protocol.file.allow always") + self(f"git submodule add {submodule.url}") self("git add .gitmodules") self(f"git add {submodule_name}")