Skip to content

Commit

Permalink
fixture git_allow_file_protocol for temporarily allowing file protoco…
Browse files Browse the repository at this point in the history
…l for git submodule
  • Loading branch information
zworkb committed Apr 13, 2024
1 parent c8460e2 commit ec8b22c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
17 changes: 17 additions & 0 deletions src/mxdev/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pytest
from .utils import Process


@pytest.fixture
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/mxdev/tests/test_git_submodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/mxdev/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit ec8b22c

Please sign in to comment.