def clone(self):
clone_path = self.context.clone_path
source_repo = self.context.source['repository']['full_name']
if self.context.clone_depth > 0:
# Use shallow clone to speed up
clone_kwargs = dict(
depth=self.context.clone_depth,
branch=self.context.source['branch']['name']
)
if self.context.type == 'commit':
# ci retry on commit
clone_kwargs['no_single_branch'] = True
bitbucket.clone(
source_repo,
clone_path,
**clone_kwargs
)
else:
# Full clone for ci retry in single commit
bitbucket.clone(source_repo, clone_path)
gitcmd = git.Git(clone_path)
if self.context.target:
self._merge_pull_request(gitcmd)
else:
# Push to branch or ci retry comment on some commit
if not self.is_commit_exists(gitcmd, self.commit_hash):
logger.info('Unshallowing a shallow cloned repository')
output = gitcmd.fetch('--unshallow')
logger.info('%s', output)
logger.info('Checkout commit %s', self.commit_hash)
gitcmd.checkout(self.commit_hash)
gitmodules = os.path.join(clone_path, '.gitmodules')
if os.path.exists(gitmodules):
output = gitcmd.submodule('update', '--init', '--recursive')
logger.info('%s', output)
评论列表
文章目录