本文整理汇总了Python中git.Repo.clone_from方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.clone_from方法的具体用法?Python Repo.clone_from怎么用?Python Repo.clone_from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Repo
的用法示例。
在下文中一共展示了Repo.clone_from方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def check(expanded_dir: str = ".") -> bool:
"""Checks to see if there have been any updates to the Cookiecutter template used
to generate this project.
"""
expanded_dir_path = Path(expanded_dir)
cruft_file = expanded_dir_path / ".cruft.json"
if not cruft_file.is_file():
raise NoCruftFound(expanded_dir_path.resolve())
cruft_state = json.loads(cruft_file.read_text())
with TemporaryDirectory() as cookiecutter_template_dir:
repo = Repo.clone_from(cruft_state["template"], cookiecutter_template_dir)
last_commit = repo.head.object.hexsha
if last_commit == cruft_state["commit"] or not repo.index.diff(cruft_state["commit"]):
return True
return False
示例2: setUpClass
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def setUpClass(cls):
if 'libclang' in autowig.parser:
autowig.parser.plugin = 'libclang'
cls.srcdir = Path('fp17')
if not cls.srcdir.exists():
Repo.clone_from('https://github.com/StatisKit/FP17.git', cls.srcdir.relpath('.'), recursive=True)
cls.srcdir = cls.srcdir/'share'/'git'/'ClangLite'
cls.incdir = Path(sys.prefix).abspath()
if any(platform.win32_ver()):
cls.incdir = cls.incdir/'Library'
subprocess.check_output(['scons', 'cpp', '--prefix=' + str(cls.incdir)],
cwd=cls.srcdir)
if any(platform.win32_ver()):
cls.scons = subprocess.check_output(['where', 'scons.bat']).strip()
else:
cls.scons = subprocess.check_output(['which', 'scons']).strip()
cls.incdir = cls.incdir/'include'/'clanglite'
示例3: setUpClass
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def setUpClass(cls):
if 'libclang' in autowig.parser:
autowig.parser.plugin = 'libclang'
autowig.generator.plugin = 'boost_python_internal'
cls.srcdir = Path('fp17')
cls.prefix = Path(Path(sys.prefix).abspath())
if any(platform.win32_ver()):
cls.prefix = cls.prefix/'Library'
if not cls.srcdir.exists():
Repo.clone_from('https://github.com/StatisKit/FP17.git', cls.srcdir.relpath('.'), recursive=True)
if any(platform.win32_ver()):
cls.scons = subprocess.check_output(['where', 'scons.bat']).strip()
else:
cls.scons = subprocess.check_output(['which', 'scons']).strip()
if six.PY3:
cls.scons = cls.scons.decode("ascii", "ignore")
subprocess.check_output([cls.scons, 'cpp', '--prefix=' + str(cls.prefix)],
cwd=cls.srcdir)
cls.incdir = cls.prefix/'include'/'basic'
示例4: test_publish_branch
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def test_publish_branch(self, mock_initialized_remote):
"""Method to test creating and listing tags"""
# Get a clone of the remote repo
git = mock_initialized_remote[0]
branches = git.repo.heads
assert len(branches) == 1
assert branches[0].name == "master"
# Create a branch
git.create_branch("test_branch1")
# Publish the branch
git.publish_branch("test_branch1", "origin")
branches = git.repo.heads
assert len(branches) == 2
assert branches[0].name == "master"
assert branches[1].name == "test_branch1"
# Create a new clone and make sure you got your branches
test_working_dir = os.path.join(tempfile.gettempdir(), uuid.uuid4().hex)
os.makedirs(test_working_dir)
test_repo = Repo.clone_from(mock_initialized_remote[3], test_working_dir)
assert len(test_repo.remotes["origin"].fetch()) == 3
示例5: __init__
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def __init__(
self, repo_owner, repo_name, repo_dir=None, do_clone=True,
from_branch=''):
self.repo_owner = repo_owner
self.repo_name = repo_name
repo_url = 'https://github.com/{0}/{1}'
self.repo_url = repo_url.format(self.repo_owner, self.repo_name)
self.repo_dir = repo_dir or self.repo_name
# by default, start on master.
self.from_branch = from_branch or 'master'
self.branch = self.from_branch
if do_clone:
self.repo = Repo.clone_from(
self.repo_url, self.repo_dir, branch=self.from_branch)
else:
self.repo = Repo(repo_dir)
self.git = self.repo.git
示例6: test_get_files_in_commit
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def test_get_files_in_commit():
finished = False # Authorize PermissionError on cleanup
try:
with tempfile.TemporaryDirectory() as temp_dir:
Repo.clone_from('https://github.com/lmazuel/swagger-to-sdk.git', temp_dir)
files = get_files_in_commit(temp_dir, "b40451e55b26e3db61ea17bd751181cbf91f60c5")
assert files == [
'swaggertosdk/generate_package.py',
'swaggertosdk/python_sdk_tools.py',
'swaggertosdk/restapi/sdkbot.py'
]
finished = True
except PermissionError:
if finished:
return
raise
示例7: test_configure
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def test_configure(self):
github_token = self.oauth_token
finished = False
try:
with tempfile.TemporaryDirectory() as temp_dir:
try:
Repo.clone_from('https://github.com/lmazuel/TestingRepo.git', temp_dir)
repo = Repo(temp_dir)
# If it's not throwing, I'm happy enough
configure_user(github_token, repo)
assert repo.git.config('--get', 'user.name') == 'Laurent Mazuel'
except Exception as err:
print(err)
pytest.fail(err)
else:
finished = True
except PermissionError:
if finished:
return
raise
示例8: download_repo
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def download_repo(name, github_repo):
try:
directory = os.path.expanduser('~/Repos/%s' % name)
if os.path.exists(directory):
shutil.rmtree(directory)
from git import Repo
from git import Git
git_ssh_identity_file = os.path.expanduser('~/.ssh/id_%s' % name)
git_ssh_cmd = 'ssh -i %s' % git_ssh_identity_file
Repo.clone_from(
github_repo, directory, env={
'GIT_SSH_COMMAND': git_ssh_cmd
})
return True, ""
except Exception as e:
return False, "download_repo: %s" % e
示例9: create_or_update
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def create_or_update(self, git_url, repo_dir):
for i in range(1, RETRY + 1):
try:
if os.path.isdir(repo_dir):
# pull
g = git.cmd.Git(repo_dir)
g.pull()
else:
# clone
Repo.clone_from(git_url, repo_dir)
except git.GitCommandError as ex:
logging.info("error:{0}: retry:{1}/{2}".format(ex, i, RETRY))
time.sleep(10 * i)
logging.info("retrying")
else:
return True
logging.exception("max retry count reached")
raise
示例10: __init__
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def __init__(self, path: str, diff_id: int, comment_file_path: str, token: str, url: str, git_hash: str,
push_branch: bool = False):
self.comment_file_path = comment_file_path
self.push_branch = push_branch # type: bool
self.conduit_token = token # type: Optional[str]
self.host = url # type: Optional[str]
self._load_arcrc()
self.diff_id = diff_id # type: int
if not self.host.endswith('/api/'):
self.host += '/api/'
self.phab = self._create_phab()
self.base_revision = git_hash # type: Optional[str]
self.msg = [] # type: List[str]
if not os.path.isdir(path):
print(f'{path} does not exist, cloning repository')
# TODO: progress of clonning
self.repo = Repo.clone_from(FORK_REMOTE_URL, path)
else:
print('repository exist, will reuse')
self.repo = Repo(path) # type: Repo
os.chdir(path)
print('working dir', os.getcwd())
示例11: clone_repo
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def clone_repo(self, local_directory_path=None):
"""
Clone the Git repository to the given file path.
:param local_directory_path: The file path to clone the repository to. If None, then use the default
directory path.
:return: The Git repository.
"""
if local_directory_path is None:
local_directory_path = self.local_directory_path
return Repo.clone_from(self.git_url, local_directory_path)
# Protected Methods
# Private Methods
# Properties
示例12: update
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def update(args):
"""Updates local copies of GTFOBins and LOLBAS"""
toUpdate = genReposToChange(args)
if toUpdate:
for repo in toUpdate:
print("Checking {0} for updates...".format(repo))
if not os.path.exists(repos[repo]['dir']):
print("Local copy of {0} not found, ".format(repo) +
"downloading...")
Repo.clone_from(repos[repo]['url'], repos[repo]['dir'])
print(green + "Local copy of {0} downloaded".format(repo) +
reset)
else:
rep = Repo(repos[repo]['dir'])
current = rep.head.commit
rep.remotes.origin.pull()
if current == rep.head.commit:
print(green + "Local copy of {0} is up to ".format(repo) +
"date" + reset)
else:
print(green + "Local copy of {0} ".format(repo) +
"updated" + reset)
else:
errorInvalidRepo()
示例13: main
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def main():
try:
shutil.rmtree('./tmp', ignore_errors=True)
Repo.clone_from(
'https://github.com/testdrivenio/pycon-sample', './tmp')
except Exception as e:
print(e)
raise
with stdoutIO() as std_out:
try:
p1 = subprocess.Popen(
['python3', 'tmp/test.py'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
p2 = p1.stdout.read().decode('utf-8')
p3 = p1.stderr.read().decode('utf-8')
if len(p2) > 0:
print(p2)
else:
print(p3)
except Exception as e:
print(e)
print(std_out.getvalue())
示例14: clone_or_pull
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def clone_or_pull(self):
if not self.remote_available():
raise exceptions.GitException(self, "Cannot clone or pull Git repository")
try:
if os.path.isdir(self.clone_dir):
git_repo = GitRepo(self.clone_dir)
git_repo.remotes.origin.fetch(tags=True, force=True)
git_repo.git.reset("--hard", "origin/master")
else:
git_repo = GitRepo.clone_from(self.git_url, self.clone_dir)
except GitError:
raise exceptions.GitException(self, "Cannot clone or pull Git repository")
self.git_repo = git_repo
示例15: __init__
# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import clone_from [as 别名]
def __init__(self, working_dir=None, verbose=False, tmp_dir=None, cache_backend=None):
self.verbose = verbose
self.log = logging.getLogger('gitpandas')
self.__delete_hook = False
self._git_repo_name = None
self.cache_backend = cache_backend
if working_dir is not None:
if working_dir[:3] == 'git':
# if a tmp dir is passed, clone into that, otherwise make a temp directory.
if tmp_dir is None:
if self.verbose:
print('cloning repository: %s into a temporary location' % (working_dir,))
dir_path = tempfile.mkdtemp()
else:
dir_path = tmp_dir
self.repo = Repo.clone_from(working_dir, dir_path)
self._git_repo_name = working_dir.split(os.sep)[-1].split('.')[0]
self.git_dir = dir_path
self.__delete_hook = True
else:
self.git_dir = working_dir
self.repo = Repo(self.git_dir)
else:
self.git_dir = os.getcwd()
self.repo = Repo(self.git_dir)
if self.verbose:
print('Repository [%s] instantiated at directory: %s' % (self._repo_name(), self.git_dir))