Skip to content

Commit ec8b22c

Browse files
committed
fixture git_allow_file_protocol for temporarily allowing file protocol for git submodule
1 parent c8460e2 commit ec8b22c

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

src/mxdev/tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import pytest
3+
from .utils import Process
34

45

56
@pytest.fixture
@@ -33,6 +34,22 @@ def _mkgitrepo(name):
3334
return _mkgitrepo
3435

3536

37+
@pytest.fixture
38+
def git_allow_file_protocol():
39+
"""
40+
Allow file protocol
41+
This is needed for the submodule to be added from a local path
42+
"""
43+
from .utils import GitRepo
44+
45+
shell = Process()
46+
file_allow = shell.check_call("git config --global --get protocol.file.allow")[0].decode("utf8").strip()
47+
shell.check_call(f"git config --global protocol.file.allow always")
48+
yield file_allow
49+
shell.check_call(f"git config --global protocol.file.allow {file_allow}")
50+
51+
52+
3653
@pytest.fixture
3754
def develop(src):
3855
from mxdev.tests.utils import MockDevelop

src/mxdev/tests/test_git_submodules.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@pytest.mark.skipif(
1111
condition=os.name == "nt", reason="submodules seem not to work on windows"
1212
)
13-
def test_checkout_with_submodule(mkgitrepo, src, caplog):
13+
def test_checkout_with_submodule(mkgitrepo, src, caplog, git_allow_file_protocol):
1414
"""
1515
Tests the checkout of a module 'egg' with a submodule 'submodule_a' in itith
1616
"""
@@ -50,7 +50,7 @@ def test_checkout_with_submodule(mkgitrepo, src, caplog):
5050
@pytest.mark.skipif(
5151
condition=os.name == "nt", reason="submodules seem not to work on windows"
5252
)
53-
def test_checkout_with_two_submodules(mkgitrepo, src):
53+
def test_checkout_with_two_submodules(mkgitrepo, src, git_allow_file_protocol):
5454
"""
5555
Tests the checkout of a module 'egg' with a submodule 'submodule_a'
5656
and a submodule 'submodule_b' in it.
@@ -102,7 +102,7 @@ def test_checkout_with_two_submodules(mkgitrepo, src):
102102
@pytest.mark.skipif(
103103
condition=os.name == "nt", reason="submodules seem not to work on windows"
104104
)
105-
def test_checkout_with_two_submodules_recursive(mkgitrepo, src):
105+
def test_checkout_with_two_submodules_recursive(mkgitrepo, src, git_allow_file_protocol):
106106
"""
107107
Tests the checkout of a module 'egg' with a submodule 'submodule_a'
108108
and a submodule 'submodule_b' in it.
@@ -145,7 +145,7 @@ def test_checkout_with_two_submodules_recursive(mkgitrepo, src):
145145
@pytest.mark.skipif(
146146
condition=os.name == "nt", reason="submodules seem not to work on windows"
147147
)
148-
def test_update_with_submodule(mkgitrepo, src):
148+
def test_update_with_submodule(mkgitrepo, src, git_allow_file_protocol):
149149
"""
150150
Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it.
151151
Add a new 'submodule_b' to 'egg' and check it succesfully initializes.
@@ -208,7 +208,7 @@ def test_update_with_submodule(mkgitrepo, src):
208208
@pytest.mark.skipif(
209209
condition=os.name == "nt", reason="submodules seem not to work on windows"
210210
)
211-
def test_update_with_submodule_recursive(mkgitrepo, src):
211+
def test_update_with_submodule_recursive(mkgitrepo, src, git_allow_file_protocol):
212212
"""
213213
Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it.
214214
Add a new 'submodule_b' to 'egg' and check it succesfully initializes.
@@ -265,7 +265,7 @@ def test_update_with_submodule_recursive(mkgitrepo, src):
265265
@pytest.mark.skipif(
266266
condition=os.name == "nt", reason="submodules seem not to work on windows"
267267
)
268-
def test_checkout_with_submodules_option_never(mkgitrepo, src):
268+
def test_checkout_with_submodules_option_never(mkgitrepo, src, git_allow_file_protocol):
269269
"""
270270
Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it
271271
without initializing the submodule, restricted by global 'never'
@@ -297,7 +297,7 @@ def test_checkout_with_submodules_option_never(mkgitrepo, src):
297297
@pytest.mark.skipif(
298298
condition=os.name == "nt", reason="submodules seem not to work on windows"
299299
)
300-
def test_checkout_with_submodules_option_never_source_always(mkgitrepo, src):
300+
def test_checkout_with_submodules_option_never_source_always(mkgitrepo, src, git_allow_file_protocol):
301301
"""
302302
Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it
303303
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):
358358
@pytest.mark.skipif(
359359
condition=os.name == "nt", reason="submodules seem not to work on windows"
360360
)
361-
def test_checkout_with_submodules_option_always_source_never(mkgitrepo, src):
361+
def test_checkout_with_submodules_option_always_source_never(mkgitrepo, src, git_allow_file_protocol):
362362
"""
363363
Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it
364364
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):
418418
@pytest.mark.skipif(
419419
condition=os.name == "nt", reason="submodules seem not to work on windows"
420420
)
421-
def test_update_with_submodule_checkout(mkgitrepo, src):
421+
def test_update_with_submodule_checkout(mkgitrepo, src, git_allow_file_protocol):
422422
"""
423423
Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it.
424424
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):
482482
@pytest.mark.skipif(
483483
condition=os.name == "nt", reason="submodules seem not to work on windows"
484484
)
485-
def test_update_with_submodule_dont_update_previous_submodules(mkgitrepo, src):
485+
def test_update_with_submodule_dont_update_previous_submodules(mkgitrepo, src, git_allow_file_protocol):
486486
"""
487487
Tests the checkout of a module 'egg' with a submodule 'submodule_a' in it.
488488
Commits changes in the detached submodule, and checks update didn't break

src/mxdev/tests/utils.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,7 @@ def add_file(self, fname, msg=None):
167167
def add_submodule(self, submodule: "GitRepo", submodule_name: str):
168168
assert isinstance(submodule, GitRepo)
169169
assert isinstance(submodule_name, str)
170-
171-
# Allow file protocol
172-
# This is needed for the submodule to be added from a local path
173-
self("git config --global protocol.file.allow always")
170+
174171
self(f"git submodule add {submodule.url}")
175172
self("git add .gitmodules")
176173
self(f"git add {submodule_name}")

0 commit comments

Comments
 (0)