Commit 59d6f829 authored by Ayush Tiwari's avatar Ayush Tiwari

Add functions for git in local repo

parent abed6449
......@@ -5,6 +5,7 @@ import os
import re
import shutil
import stat
import subprocess
import tempfile
import unittest
import zc.buildout.testing
......@@ -29,11 +30,96 @@ def setUp(test):
zc.buildout.testing.buildoutSetUp(test)
zc.buildout.testing.install_develop('slapos.recipe.build', test)
def check_exists(fips_dir=None) :
"""test if git is in the path
:returns: True if git is in the path
"""
try :
subprocess.check_output(['git', '--version'])
return True
except (OSError, subprocess.CalledProcessError) :
return False
def git_add(proj_dir, update=False):
"""runs a 'git add .' in the provided git repo
:param proj_dir: path to a git repo
:update: if True, will run 'git add -u'
"""
check_exists_with_error()
cmd = 'git add ' + '-u' if update else '.'
try:
subprocess.check_call('git add .', cwd=proj_dir, shell=True)
except subprocess.CalledProcessError as e:
log.error("'git add .' failed with '{}'".format(e.returncode))
def git_commit(proj_dir, msg):
"""runs a 'git commit -m msg' in the provided git repo
:param proj_dir: path to a git repo
"""
check_exists_with_error()
try:
subprocess.check_call('git commit -m "{}"'.format(msg), cwd=proj_dir, shell=True)
except subprocess.CalledProcessError as e:
log.error("'git commit' failed with '{}'".format(e.returncode))
def git_push(repo_dir):
"""Pushes any changes in the Git repository located in supplied repository
directory to remote git repository.
:param repo_dir: Directory containing git repository to push.
"""
cmd = 'git push '
execute_shell_command(cmd, repo_dir)
def git_create_submodule():
"""
Steps to create local submodule:
1. Create a directory
2. init the directory with git
3. Add some files and commit
"""
pass
def git_create_main_repo():
"""
Steps to create main repo which will later point to a submodule repo:
1. Create a directory
2. init the directory with git
3. Add some files and commit
4. Add a folder and commit
5. Add a submodule in the repo and commit
"""
pass
def update_submodule():
"""
Steps to update submodule:
1. Add more files and commit
"""
pass
def update_main_repo_after_submodule_changes():
pass
def get_repo_head_commit(prof_dir, branch='master'):
"""
Returns the sha of HEAD of a git repo
"""
try :
output = subprocess.check_output('git rev-parse {}'.format(branch),
cwd=proj_dir, shell=True).decode("utf-8")
return output.rstrip()
except subprocess.CalledProcessError :
log.error("failed to call 'git rev-parse'")
return None
class GitCloneNonInformativeTests(unittest.TestCase):
def setUp(self):
self.dir = os.path.realpath(tempfile.mkdtemp())
self.parts_directory_path = os.path.join(self.dir, 'test_parts')
# Add repository with submodules in a temporary directory
def tearDown(self):
shutil.rmtree(self.dir)
......
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