def load_mirror_index(self, remote_mirror):
# See if there is a mirror index available from the BASE_URL
mirror_index = os.path.join(self.conf_dir, 'mirror-index')
try:
cmd = [self.tools['git'], 'ls-remote', remote_mirror, self.base_branch]
utils_setup.run_cmd(cmd, log=2, environment=self.env, cwd=self.project_dir, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
except:
try:
remote_mirror += "/.git"
cmd = [self.tools['git'], 'ls-remote', remote_mirror, self.base_branch]
utils_setup.run_cmd(cmd, log=2, environment=self.env, cwd=self.project_dir, stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
except:
# No mirror, return
return None
logger.plain('Loading the mirror index from %s (%s)...' % (remote_mirror, self.base_branch))
# This MIGHT be a valid mirror..
if not os.path.exists(mirror_index):
os.makedirs(mirror_index)
cmd = [self.tools['git'], 'init' ]
utils_setup.run_cmd(cmd, log=2, environment=self.env, cwd=mirror_index)
try:
cmd = [self.tools['git'], 'fetch', '-f', '-n', '-u', remote_mirror, self.base_branch + ':' + self.base_branch]
utils_setup.run_cmd(cmd, log=2, environment=self.env, cwd=mirror_index)
except:
# Could not fetch, return
return None
logger.debug('Found mirrored index.')
cmd = [self.tools['git'], 'checkout', self.base_branch ]
utils_setup.run_cmd(cmd, log=2, environment=self.env, cwd=mirror_index)
cmd = [self.tools['git'], 'reset', '--hard' ]
utils_setup.run_cmd(cmd, log=2, environment=self.env, cwd=mirror_index)
return mirror_index
评论列表
文章目录