Commit 20c724bb authored by Ayush Tiwari's avatar Ayush Tiwari

gitclone: Update tests and add functionality for git submodule update

parent 3f6b53d2
......@@ -163,8 +163,8 @@ When updating, it will do a "git fetch; git reset @{upstream}"::
>>> print(system(buildout))
Updating git-clone.
Fetching origin
HEAD is now at ...
Fetching origin ...
Specific branch
~~~~~~~~~~~~~~~
......@@ -208,8 +208,8 @@ When updating, it will do a "git fetch; git reset build"::
>>> cd(sample_buildout)
>>> print(system(buildout))
Updating git-clone.
Fetching origin
HEAD is now at ...
Fetching origin ...
Specific revision
~~~~~~~~~~~~~~~~~
......
......@@ -93,6 +93,100 @@ class GitCloneNonInformativeTests(unittest.TestCase):
self.assertTrue(os.path.exists(git_repository_path))
self.assertFalse(os.path.exists(bad_file_path), "pyc file not removed")
def test_clone_and_udpate_submodule(self):
"""
STEP I:
Repositories status: Main repo(M1) and Submodule repo (S1)
Main repo (M1) ---references---> Submodule(S1)
Install should be M1+S1
STEP II:
Repositories status: Main repo(M2) and Submodule repo (S2)
Main repo (M2) ---references---> Submodule(S1)
Install should be M2+S1
STEP III:
Repositories status: Main repo(M3) and Submodule repo (S2)
Main repo (M3) ---references---> Submodule(S2)
Install should be M3+S2
"""
# STEP I: Clone repositories in status M1 and S1 (M1---->S1)
recipe = self.makeGitCloneRecipe(
{
'repository': GIT_REPOSITORY_WITH_SUBMODULES,
'revision': '9db24704b3dece16d8bc0fbd20653018b754c0c3'
}
)
recipe.install()
main_repo_path = os.path.join(self.parts_directory_path, "test")
self.assertTrue(os.path.exists(main_repo_path))
submodule_repo_path = os.path.join(main_repo_path, 'dir2',
'test_erp5_submodule')
# Check if the submodule is not empty
self.assertTrue(os.listdir(submodule_repo_path))
# Get the head commit of the submodule repo
head_commit_submodule_after_clone = check_output(['git', 'rev-parse',
'HEAD'],
cwd=submodule_repo_path).strip()
# STEP II: Clone repositories in status M2 and S2 (M2---->S1)
# Update the recipe with new revision which still point to the submodule
# old revision
recipe = self.makeGitCloneRecipe(
{
'repository': GIT_REPOSITORY_WITH_SUBMODULES,
'revision': '69ebe9c81f7d87812b87d6fd6de45721b27520dc'
}
)
recipe.update()
self.assertTrue(os.path.exists(main_repo_path))
submodule_repo_path = os.path.join(main_repo_path, 'dir2',
'test_erp5_submodule')
# Check if the submodule is not empty
self.assertTrue(os.listdir(submodule_repo_path))
# Get the head commit of the submodule repo
head_commit_submodule_after_first_update = check_output(['git', 'rev-parse',
'HEAD'],
cwd=submodule_repo_path).strip()
# STEP II: Clone repositories in status M3 and S2 (M3---->S2)
# Update the recipe with new revision which points to submodule new revision
recipe = self.makeGitCloneRecipe(
{
'repository': GIT_REPOSITORY_WITH_SUBMODULES,
'revision': '05a26f99b2d366830e50088e90f94708fdd69f61'
}
)
recipe.update()
self.assertTrue(os.path.exists(main_repo_path))
submodule_repo_path = os.path.join(main_repo_path, 'dir2',
'test_erp5_submodule')
# Check if the submodule is not empty
self.assertTrue(os.listdir(submodule_repo_path))
# Get the head commit of the submodule repo
head_commit_submodule_after_second_update = check_output(['git', 'rev-parse',
'HEAD'],
cwd=submodule_repo_path).strip()
# Make another git clone of submodule and check the HEAD of the repo.
submodule_recipe = self.makeGitCloneRecipe(
{'repository': GIT_SUBMODULE_REPOSITORY}
)
submodule_recipe.install()
# Check the HEAD of the submodule
head_commit = check_output(['git', 'rev-parse', 'HEAD'],
cwd=main_repo_path).strip()
self.assertEqual(head_commit_submodule_after_clone,
head_commit_submodule_after_first_update)
self.assertNotEqual(head_commit_submodule_after_first_update,
head_commit_submodule_after_second_update)
self.assertEqual(head_commit_submodule_after_second_update,
head_commit)
def test_ignore_ssl_certificate(self, ignore_ssl_certificate=True):
import slapos.recipe.gitclone
......@@ -192,103 +286,8 @@ class GitCloneNonInformativeTests(unittest.TestCase):
head_commit = check_output(['git', 'rev-parse', 'HEAD'],
cwd=main_repo_path).strip()
self.assertNotEqual(head_commit_submodule_before_fetch, head_commit)
self.assertNotEqual(head_commit_after_udpate_before_checkout, head_commit)
self.assertEqual(head_commit_after_update_after_checkout, head_commit)
def test_udpate_for_submodule(self):
"""
STEP I:
Repositories status: Main repo(M1) and Submodule repo (S1)
Main repo (M1) ---references---> Submodule(S1)
Install should be M1+S1
STEP II:
Repositories status: Main repo(M2) and Submodule repo (S2)
Main repo (M2) ---references---> Submodule(S1)
Install should be M2+S1
STEP III:
Repositories status: Main repo(M3) and Submodule repo (S2)
Main repo (M3) ---references---> Submodule(S2)
Install should be M3+S2
"""
# STEP I: Clone repositories in status M1 and S1 (M1---->S1)
recipe = self.makeGitCloneRecipe(
{
'repository': GIT_REPOSITORY_WITH_SUBMODULES,
'revision': '9db24704b3dece16d8bc0fbd20653018b754c0c3'
}
)
recipe.install()
main_repo_path = os.path.join(self.parts_directory_path, "test")
self.assertTrue(os.path.exists(main_repo_path))
submodule_repo_path = os.path.join(main_repo_path, 'dir2',
'test_erp5_submodule')
# Check if the submodule is not empty
self.assertTrue(os.listdir(submodule_repo_path))
# Get the head commit of the submodule repo
head_commit_submodule_after_clone = check_output(['git', 'rev-parse',
'HEAD'],
cwd=submodule_repo_path).strip()
# STEP II: Clone repositories in status M2 and S2 (M2---->S1)
# Update the recipe with new revision which still point to the submodule
# old revision
recipe = self.makeGitCloneRecipe(
{
'repository': GIT_REPOSITORY_WITH_SUBMODULES,
'revision': '69ebe9c81f7d87812b87d6fd6de45721b27520dc'
}
)
recipe.update()
self.assertTrue(os.path.exists(main_repo_path))
submodule_repo_path = os.path.join(main_repo_path, 'dir2',
'test_erp5_submodule')
# Check if the submodule is not empty
self.assertTrue(os.listdir(submodule_repo_path))
# Get the head commit of the submodule repo
head_commit_submodule_after_first_update = check_output(['git', 'rev-parse',
'HEAD'],
cwd=submodule_repo_path).strip()
# STEP II: Clone repositories in status M3 and S2 (M3---->S2)
# Update the recipe with new revision which points to submodule new revision
recipe = self.makeGitCloneRecipe(
{
'repository': GIT_REPOSITORY_WITH_SUBMODULES,
'revision': '05a26f99b2d366830e50088e90f94708fdd69f61'
}
)
recipe.update()
self.assertTrue(os.path.exists(main_repo_path))
submodule_repo_path = os.path.join(main_repo_path, 'dir2',
'test_erp5_submodule')
# Check if the submodule is not empty
self.assertTrue(os.listdir(submodule_repo_path))
# Get the head commit of the submodule repo
head_commit_submodule_after_second_update = check_output(['git', 'rev-parse',
'HEAD'],
cwd=submodule_repo_path).strip()
# Make another git clone of submodule and check the HEAD of the repo.
submodule_recipe = self.makeGitCloneRecipe(
{'repository': GIT_SUBMODULE_REPOSITORY}
)
submodule_recipe.install()
# Check the HEAD of the submodule
head_commit = check_output(['git', 'rev-parse', 'HEAD'],
cwd=main_repo_path).strip()
self.assertEqual(head_commit_submodule_after_clone,
head_commit_submodule_after_first_update)
self.assertNotEqual(head_commit_submodule_after_first_update,
head_commit_submodule_after_second_update)
self.assertNotEqual(head_commit_submodule_after_second_update,
head_commit)
def test_suite():
suite = unittest.TestSuite((
doctest.DocFileSuite(
......
......@@ -34,7 +34,7 @@ import time
import traceback
from zc.buildout import UserError
from subprocess import call, check_call, CalledProcessError
from subprocess import call, check_call, check_output, CalledProcessError
import subprocess
try:
......@@ -238,6 +238,9 @@ class Recipe(object):
if self.use_cache:
upload_network_cached(os.path.join(self.location, '.git'),
self.repository, self.revision, self.networkcache)
if not self.ignore_cloning_submodules:
check_call([self.git_command, 'submodule', 'update', '--recursive'],
cwd=self.location)
except CalledProcessError:
print("Unable to download from git repository."
" Trying from network cache...")
......@@ -280,7 +283,19 @@ class Recipe(object):
revision_already_fetched = \
self.revision and \
call([self.git_command, 'rev-parse', '--verify', self.revision],
cwd=self.location) == 0
cwd=self.location) == 0 and \
check_output([self.git_command, 'rev-parse', 'HEAD'],
cwd=self.location).strip() == self.revision
# If develop parameter is set, don't reset/update.
# Otherwise, reset --hard
if not self.develop:
if self.revision:
self.gitReset(self.revision)
else:
self.gitReset('@{upstream}')
if not revision_already_fetched:
# With --recurse-submodules, it will fetch the updated branches of the
# submodules as well as of the main repo. It will remain in a detached
......@@ -289,16 +304,9 @@ class Recipe(object):
check_call([self.git_command, 'fetch', '--recurse-submodules', '--all'],
cwd=self.location)
# Also update the submodule directory
check_call([self.git_command, 'submodule', 'update', '--remote'],
check_call([self.git_command, 'submodule', 'update', '--recursive'],
cwd=self.location)
# If develop parameter is set, don't reset/update.
# Otherwise, reset --hard
if not self.develop:
if self.revision:
self.gitReset(self.revision)
else:
self.gitReset('@{upstream}')
except:
if not self.develop:
raise
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment