def create_local_repo(remote_git,dir,branch):
""" Uses the git.clone_from method to clone a remote git repository locally
Args:
remote_git: Url of the remote git repository
dir: Local directory where the contents of the
remote git will be downloaded
branch: Name of the branch on the remote git which will be used for cloning
Returns:
git.repo: Reference to the local git repository
Raises:
git.exc.InvalidGitRepositoryError: If remote git repository is bare
git.exc.GitCommandError: If remote git repository does not exist
"""
if(os.path.exists(dir)):
shutil.rmtree(dir)
try:
repo = Repo.clone_from(
url=remote_git,
to_path=dir,
branch=branch
)
if repo.bare:
raise git.exc.InvalidGitRepositoryError
else:
return repo
except git.exc.GitCommandError:
print "Please make sure you have the correct access rights and the repository exists"
评论列表
文章目录