Commit 9734e300 authored by Ayush Tiwari's avatar Ayush Tiwari

Fixes a/q to review

parent f61b1e5a
......@@ -40,25 +40,25 @@ class GitCloneNonInformativeTests(unittest.TestCase):
submodule repo and create small commits as well as links the 2 repos.
"""
# Add files in both main as well as submodule repo
check_call('mkdir main_repo', cwd=self.dir, shell=True)
check_call('mkdir submodule_repo', cwd=self.dir, shell=True)
os.mkdir(os.path.join(self.dir, 'main_repo'))
os.mkdir(os.path.join(self.dir, 'submodule_repo'))
self.project_dir = os.path.join(self.dir, 'main_repo')
self.submodule_dir = os.path.join(self.dir ,'submodule_repo', )
self.submodule_dir = os.path.join(self.dir ,'submodule_repo')
# Add files in submodule repo and initialize git in it
check_call('cd submodule_repo', cwd=self.dir, shell=True)
check_call('git init', cwd=self.submodule_dir, shell=True)
check_call(['git', 'init'], cwd=self.submodule_dir)
self.setUpGitConfig(self.submodule_dir)
check_call('touch file1.py', cwd=self.submodule_dir, shell=True)
self.touch(self.submodule_dir, 'file1.py')
self.gitAdd(self.submodule_dir)
self.gitCommit(self.submodule_dir, msg='Add file1 in submodule repo')
# Add files and folder in main repo and initialize git in it
check_call('cd main_repo', cwd=self.dir, shell=True)
check_call('git init', cwd=self.project_dir, shell=True)
check_call(['git', 'init'], cwd=self.project_dir)
self.setUpGitConfig(self.project_dir)
check_call('mkdir dir1', cwd=self.project_dir, shell=True)
check_call('touch file1.py', cwd=self.project_dir, shell=True)
os.mkdir(os.path.join(self.project_dir, 'dir1'))
self.touch(self.project_dir, 'file1.py')
self.gitAdd(self.project_dir)
self.gitCommit(self.project_dir, msg='Add file and folder in main repo')
......@@ -97,32 +97,34 @@ class GitCloneNonInformativeTests(unittest.TestCase):
"""
cmd = 'git add ' + '-u' if update else '.'
try:
check_call('git add .', cwd=proj_dir, shell=True)
check_call(['git', 'add', '.'], cwd=proj_dir)
except CalledProcessError as e:
logging.error("'git add .' failed with '%s'" % e.returncode)
logging.error("'git add .' failed with '%s'" % e.returncode)
def gitCommit(self, proj_dir, msg):
"""runs a 'git commit -m msg' in the provided git repo
:param proj_dir: path to a git repo
"""
try:
check_call('git commit -m "%s"' % msg,
cwd=proj_dir,
shell=True)
check_call('git commit -m "%s"' % msg,
cwd=proj_dir,
shell=True)
except CalledProcessError as e:
logging.error("'git commit' failed with '%s'" % e.returncode)
logging.error("'git commit' failed with '%s'" % e.returncode)
def getRepositoryHeadCommit(self, proj_dir):
"""
Returns the sha of HEAD of a git repo
"""
try :
output = check_output('git rev-parse HEAD',
cwd=proj_dir, shell=True).decode("utf-8")
return output.rstrip()
output = check_output(['git', 'rev-parse', 'HEAD'], cwd=proj_dir).decode("utf-8")
return output.rstrip()
except CalledProcessError :
logging.error("failed to call 'git rev-parse'")
return None
logging.error("failed to call 'git rev-parse'")
return None
def touch(self, *parts):
os.close(os.open(os.path.join(*parts), os.O_CREAT, 0o666))
def makeGitCloneRecipe(self, options):
from slapos.recipe.gitclone import Recipe
......@@ -205,10 +207,10 @@ class GitCloneNonInformativeTests(unittest.TestCase):
submodule_repo_path)
# Update submodule repository and main repo separately
check_call('touch file2.py', cwd=self.project_dir, shell=True)
self.touch(self.project_dir, 'file2.py')
self.gitAdd(self.project_dir)
self.gitCommit(self.project_dir, msg='Add file2 in main repo')
check_call('touch file2.py', cwd=self.submodule_dir, shell=True)
self.touch(self.submodule_dir, 'file2.py')
self.gitAdd(self.submodule_dir)
self.gitCommit(self.submodule_dir, msg='Add file2 in submodule repo')
......@@ -221,7 +223,6 @@ class GitCloneNonInformativeTests(unittest.TestCase):
'revision': str(self.getRepositoryHeadCommit(self.project_dir))
}
)
#import pdb; pdb.set_trace()
recipe.update()
self.assertTrue(os.path.exists(main_repo_path))
# Check if the submodule is not empty
......@@ -233,12 +234,12 @@ class GitCloneNonInformativeTests(unittest.TestCase):
# Update main repo with changes of submodule
submodule_dir_main_repo = os.path.join(self.project_dir, 'dir1', 'submodule_repo')
check_call('git checkout master', cwd=submodule_dir_main_repo, shell=True)
check_call('git pull', cwd=submodule_dir_main_repo, shell=True)
check_call(['git', 'checkout', 'master'], cwd=submodule_dir_main_repo)
check_call(['git', 'pull', '--ff'], cwd=submodule_dir_main_repo)
self.gitAdd(self.project_dir)
self.gitCommit(self.project_dir, msg='Update submodule version')
# STEP II: Clone repositories in status M3 and S2 (M3---->S2)
# STEP III: Clone repositories in status M3 and S2 (M3---->S2)
# Update the recipe with new revision which points to submodule new revision
recipe = self.makeGitCloneRecipe(
{
......
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