本文整理汇总了Python中git.repo.Repo.clone_from方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.clone_from方法的具体用法?Python Repo.clone_from怎么用?Python Repo.clone_from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.repo.Repo
的用法示例。
在下文中一共展示了Repo.clone_from方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _clone_repo
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def _clone_repo(repo_url):
user_home = os.path.expanduser('~')
# Assuming git url is of form [email protected]:user/git-repo.git
repo_name = repo_url[repo_url.rfind('/') + 1: repo_url.rfind('.')]
abs_local_path = os.path.join(user_home, repo_name)
Repo.clone_from(repo_url, abs_local_path)
return abs_local_path
示例2: _clone_repo
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def _clone_repo(repo_url, verifyssl=True, branch='master'):
user_home = os.path.expanduser('~')
# Assuming git url is of form [email protected]:user/git-repo.git
repo_name = repo_url[repo_url.rfind('/') + 1: repo_url.rfind('.')]
abs_local_path = os.path.join(user_home, repo_name)
# Disable SSL cert checking if explictly asked
if not verifyssl:
os.environ['GIT_SSL_NO_VERIFY'] = 'true'
Repo.clone_from(repo_url, abs_local_path, branch=branch)
return abs_local_path
示例3: _clone_repo
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def _clone_repo(repo_url, verifyssl=True, branch='master'):
user_home = os.path.expanduser('~')
# Assuming git url is of form [email protected]:user/git-repo.git
repo_name = repo_url[repo_url.rfind('/') + 1: repo_url.rfind('.')]
abs_local_path = os.path.join(user_home, repo_name)
# Disable SSL cert checking if explictly asked
if not verifyssl:
os.environ['GIT_SSL_NO_VERIFY'] = 'true'
# Shallow clone the repo to avoid getting all the metadata. We only need HEAD of a
# specific branch so save some download time.
Repo.clone_from(repo_url, abs_local_path, branch=branch, depth=1)
return abs_local_path
示例4: _clone_repo
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def _clone_repo(repo_url, verifyssl=True, branch="master"):
user_home = os.path.expanduser("~")
# Assuming git url is of form [email protected]:user/git-repo.git
repo_name = DownloadGitRepoAction._eval_repo_name(repo_url)
abs_local_path = os.path.join(user_home, repo_name)
# Disable SSL cert checking if explictly asked
if not verifyssl:
os.environ["GIT_SSL_NO_VERIFY"] = "true"
# Shallow clone the repo to avoid getting all the metadata. We only need HEAD of a
# specific branch so save some download time.
Repo.clone_from(repo_url, abs_local_path, branch=branch, depth=1)
return abs_local_path
示例5: _clone_repo
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def _clone_repo(temp_dir, repo_url, verifyssl=True, ref='master'):
# Switch to non-interactive mode
os.environ['GIT_TERMINAL_PROMPT'] = '0'
os.environ['GIT_ASKPASS'] = '/bin/echo'
# Disable SSL cert checking if explictly asked
if not verifyssl:
os.environ['GIT_SSL_NO_VERIFY'] = 'true'
# Clone the repo from git; we don't use shallow copying
# because we want the user to work with the repo in the
# future.
repo = Repo.clone_from(repo_url, temp_dir)
use_branch = False
# Try to match the reference to a branch name (i.e. "master")
gitref = DownloadGitRepoAction._get_gitref(repo, "origin/%s" % ref)
if gitref:
use_branch = True
# Try to match the reference to a commit hash, a tag, or "master"
if not gitref:
gitref = DownloadGitRepoAction._get_gitref(repo, ref)
# Try to match the reference to a "vX.Y.Z" tag
if not gitref and re.match(PACK_VERSION_REGEX, ref):
gitref = DownloadGitRepoAction._get_gitref(repo, "v%s" % ref)
# Giving up ¯\_(ツ)_/¯
if not gitref:
format_values = [ref, repo_url]
msg = '"%s" is not a valid version, hash, tag or branch in %s.'
valid_versions = DownloadGitRepoAction._get_valid_versions_for_repo(repo=repo)
if len(valid_versions) >= 1:
valid_versions_string = ', '.join(valid_versions)
msg += ' Available versions are: %s.'
format_values.append(valid_versions_string)
raise ValueError(msg % tuple(format_values))
# We're trying to figure out which branch the ref is actually on,
# since there's no direct way to check for this in git-python.
branches = repo.git.branch('-a', '--contains', gitref.hexsha)
branches = branches.replace('*', '').split()
if 'master' not in branches or use_branch:
branch = "origin/%s" % ref if use_branch else branches[0]
short_branch = ref if use_branch else branches[0].split('/')[-1]
repo.git.checkout('-b', short_branch, branch)
branch = repo.head.reference
else:
branch = 'master'
repo.git.checkout(gitref.hexsha)
repo.git.branch('-f', branch, gitref.hexsha)
repo.git.checkout(branch)
return temp_dir
示例6: _setup_repo
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def _setup_repo(self, already_cloned):
if already_cloned:
self._git_repo = Repo(self.repo_dir_path)
else:
_log.info('Cloning repo from %s into %s' % (
self._github_repo_url, self.repo_dir_path))
self._git_repo = Repo.clone_from(
self._github_repo_url, self.repo_dir_path)
_log.info('-Done-')
if self.branch:
self._git_repo.git.checkout(self.branch)
示例7: __init__
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def __init__(self, database):
logging.info("Initializing GitSync.")
self.database = database
self.charts = dict()
self.url = DEFAULT_GITREPO
try:
self.repo = Repo(REPO_DIRECTORY)
except InvalidGitRepositoryError:
logging.info("Cloning repository in %s", REPO_DIRECTORY)
self.repo = Repo.clone_from(self.url, REPO_DIRECTORY)
示例8: _clone_repo
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def _clone_repo(temp_dir, repo_url, verifyssl=True, ref='master'):
# Switch to non-interactive mode
os.environ['GIT_TERMINAL_PROMPT'] = '0'
# Disable SSL cert checking if explictly asked
if not verifyssl:
os.environ['GIT_SSL_NO_VERIFY'] = 'true'
# Clone the repo from git; we don't use shallow copying
# because we want the user to work with the repo in the
# future.
repo = Repo.clone_from(repo_url, temp_dir)
# Try to match the reference to a commit hash, a tag, or "master"
gitref = DownloadGitRepoAction._get_gitref(repo, ref)
# Try to match the reference to a "vX.Y.Z" tag
if not gitref and re.match(SEMVER_REGEX, ref):
gitref = DownloadGitRepoAction._get_gitref(repo, "v%s" % ref)
# Try to match the reference to a branch name
if not gitref:
gitref = DownloadGitRepoAction._get_gitref(repo, "origin/%s" % ref)
# Giving up ¯\_(ツ)_/¯
if not gitref:
raise ValueError(
"\"%s\" is not a valid version, hash, tag, or branch in %s." % (ref, repo_url)
)
# We're trying to figure out which branch the ref is actually on,
# since there's no direct way to check for this in git-python.
branches = repo.git.branch('--color=never', '--all', '--contains', gitref.hexsha)
branches = branches.replace('*', '').split()
if 'master' not in branches:
branch = branches[0]
repo.git.checkout('--track', branches[0])
branch = repo.head.reference
else:
branch = 'master'
repo.git.checkout('-B', branch, gitref.hexsha)
return temp_dir
示例9: setup
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def setup(self):
git_opts = self._config
if git_opts['url'] is None:
raise Exception('Remote git URL not set.')
self._url = git_opts['url']
default_clone_dir = os.path.join(os.path.dirname(__file__), 'clones')
self._local_path = git_opts.get('local_clone_path', default_clone_dir)
self._poll_interval = git_opts.get('poll_interval', self._poll_interval)
if os.path.exists(self._local_path):
self._repo = Repo.init(self._local_path)
else:
try:
self._repo = Repo.clone_from(self._url, self._local_path)
except Exception:
self._logger.exception('Unable to clone remote repo from %s',
self._url)
raise
self._remote = self._repo.remote('origin')
示例10: clone_repo
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def clone_repo(self, name, path):
Repo.clone_from("{}@{}:{}/{}.git".format(self.user,self.name,self.root,name),path)
示例11: clone_repo
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import clone_from [as 别名]
def clone_repo(temp_dir, repo_url, verify_ssl=True, ref='master'):
# Switch to non-interactive mode
os.environ['GIT_TERMINAL_PROMPT'] = '0'
os.environ['GIT_ASKPASS'] = '/bin/echo'
# Disable SSL cert checking if explictly asked
if not verify_ssl:
os.environ['GIT_SSL_NO_VERIFY'] = 'true'
# Clone the repo from git; we don't use shallow copying
# because we want the user to work with the repo in the
# future.
repo = Repo.clone_from(repo_url, temp_dir)
is_local_repo = repo_url.startswith('file://')
try:
active_branch = repo.active_branch
except TypeError as e:
if is_local_repo:
active_branch = None
else:
raise e
# Special case for local git repos - we allow users to install from repos which are checked out
# at a specific commit (aka detached HEAD)
if is_local_repo and not active_branch and not ref:
LOG.debug('Installing pack from git repo on disk, skipping branch checkout')
return temp_dir
use_branch = False
# Special case when a default repo branch is not "master"
# No ref provided so we just use a default active branch
if (not ref or ref == active_branch.name) and repo.active_branch.object == repo.head.commit:
gitref = repo.active_branch.object
else:
# Try to match the reference to a branch name (i.e. "master")
gitref = get_gitref(repo, 'origin/%s' % ref)
if gitref:
use_branch = True
# Try to match the reference to a commit hash, a tag, or "master"
if not gitref:
gitref = get_gitref(repo, ref)
# Try to match the reference to a "vX.Y.Z" tag
if not gitref and re.match(PACK_VERSION_REGEX, ref):
gitref = get_gitref(repo, 'v%s' % ref)
# Giving up ¯\_(ツ)_/¯
if not gitref:
format_values = [ref, repo_url]
msg = '"%s" is not a valid version, hash, tag or branch in %s.'
valid_versions = get_valid_versions_for_repo(repo=repo)
if len(valid_versions) >= 1:
valid_versions_string = ', '.join(valid_versions)
msg += ' Available versions are: %s.'
format_values.append(valid_versions_string)
raise ValueError(msg % tuple(format_values))
# We're trying to figure out which branch the ref is actually on,
# since there's no direct way to check for this in git-python.
branches = repo.git.branch('-a', '--contains', gitref.hexsha) # pylint: disable=no-member
branches = branches.replace('*', '').split()
if active_branch.name not in branches or use_branch:
branch = 'origin/%s' % ref if use_branch else branches[0]
short_branch = ref if use_branch else branches[0].split('/')[-1]
repo.git.checkout('-b', short_branch, branch)
branch = repo.head.reference
else:
branch = repo.active_branch.name
repo.git.checkout(gitref.hexsha) # pylint: disable=no-member
repo.git.branch('-f', branch, gitref.hexsha) # pylint: disable=no-member
repo.git.checkout(branch)
return temp_dir