Fix git submodule test sha comparison
MODIFY
tests/conftest.py
tests/conftest.py
@@ -136,23 +136,27 @@ def repo_with_submodule():
# create "parent" repository
subprocess.check_call(['git', 'init'], cwd=git_a_dir)
_add_content_to_git(git_a_dir)
- # create submodule repository
+ # create repository with 2 commits that will be the submodule
subprocess.check_call(['git', 'init'], cwd=git_b_dir)
_add_content_to_git(git_b_dir)
+ submod_sha1_b = _get_sha1(git_b_dir)
+ _add_content_to_git(git_b_dir)
# create a new branch in the parent to add the submodule
subprocess.check_call(['git', 'checkout', '-b', 'branch-with-submod'],
cwd=git_a_dir)
subprocess.check_call(['git', 'submodule', 'add', git_b_dir, 'submod'],
cwd=git_a_dir)
+ # checkout the first commit for the submod, not the latest
+ subprocess.check_call(['git', 'checkout', submod_sha1_b],
+ cwd=os.path.join(git_a_dir, 'submod'))
subprocess.check_call(['git', 'add', git_a_dir, ".gitmodules"],
cwd=git_a_dir)
subprocess.check_call(['git', 'commit', '-m', 'Add B repos submod'],
cwd=git_a_dir)
sha1_a = _get_sha1(git_a_dir)
- sha1_b = _get_sha1(git_b_dir)
- yield git_a_dir, sha1_a, sha1_b
+ yield git_a_dir, sha1_a, submod_sha1_b
class Repo2DockerTest(pytest.Function):

MODIFY
tests/unit/contentproviders/test_git.py
tests/unit/contentproviders/test_git.py
@@ -21,7 +21,7 @@ def test_clone(repo_with_content):
def test_submodule_clone(repo_with_submodule):
"""Test git clone containing a git submodule."""
- upstream, sha1_upstream, sha1_submod = repo_with_submodule
+ upstream, expected_sha1_upstream, expected_sha1_submod = repo_with_submodule
with TemporaryDirectory() as clone_dir:
submod_dir = os.path.join(clone_dir, 'submod') # set by fixture
@@ -37,8 +37,8 @@ def test_submodule_clone(repo_with_submodule):
sha1 = subprocess.Popen(cmd, stdout=subprocess.PIPE, cwd=submod_dir)
submod_sha1 = sha1.stdout.read().decode().strip()
- assert git_content.content_id == sha1_upstream[:7]
- assert submod_sha1[:7] == submod_sha1[:7]
+ assert git_content.content_id == expected_sha1_upstream[:7]
+ assert submod_sha1[:7] == expected_sha1_submod[:7]
def test_bad_ref(repo_with_content):

Fix git submodule test sha comparison