def init(pod, theme_url, force=False): if '//' not in theme_url or ':' not in theme_url: repo_url = THEME_REPO_URL.format(theme_url) else: repo_url = theme_url git_client = client.HttpGitClient(repo_url) logging.info('Initializing with {}...'.format(repo_url)) temp_repo = MemoryRepo() temp_repo.clone(git_client) tree = temp_repo['refs/heads/master'].tree # Build the tree into a temp directory. temp_root = tempfile.mkdtemp() local_repo = repo.Repo.init(temp_root) index_file = local_repo.index_path() index.build_index_from_tree(local_repo.path, index_file, temp_repo.object_store, tree) shutil.rmtree(os.path.join(temp_root, '.git')) # Automatically enable "force" for empty directories. if pod.list_dir('/') == []: force = True try: _copy_files_to_pod(temp_root, pod, force=force) except OSError as e: if 'File exists' in str(e): text = ( '{} already exists and is not empty. Delete the directory before' ' proceeding or use --force.') logging.info(text.format(pod.root)) return logging.info('Pod ready to go: {}'.format(pod.root))
def get_transport_and_path(self, uri): # pass hg's ui.ssh config to dulwich if not issubclass(client.get_ssh_vendor, _ssh.SSHVendor): client.get_ssh_vendor = _ssh.generate_ssh_vendor(self.ui) for handler, transport in (("git://", client.TCPGitClient), ("git@", client.SSHGitClient), ("git+ssh://", client.SSHGitClient)): if uri.startswith(handler): # We need to split around : or /, whatever comes first hostpath = uri[len(handler):] if (hostpath.find(':') > 0 and hostpath.find('/') > 0): # we have both, whatever is first wins. if hostpath.find(':') < hostpath.find('/'): hostpath_seper = ':' else: hostpath_seper = '/' elif hostpath.find(':') > 0: hostpath_seper = ':' else: hostpath_seper = '/' port = None host, path = hostpath.split(hostpath_seper, 1) if hostpath_seper == '/': transportpath = '/' + path else: # port number should be recognized m = re.match('^(?P<port>\d+)?(?P<path>.*)$', path) if m.group('port'): client.port = m.group('port') port = client.port transportpath = m.group('path') else: transportpath = path return transport(host, thin_packs=False, port=port), transportpath httpclient = getattr(client, 'HttpGitClient', None) if uri.startswith('git+http://') or uri.startswith('git+https://'): uri = uri[4:] if uri.startswith('http://') or uri.startswith('https://'): if not httpclient: raise RepoError('git via HTTP requires dulwich 0.8.1 or later') else: return client.HttpGitClient(uri, thin_packs=False), uri # if its not git or git+ssh, try a local url.. return client.SubprocessGitClient(thin_packs=False), uri
def get_transport_and_path(self, uri): # pass hg's ui.ssh config to dulwich if not issubclass(client.get_ssh_vendor, _ssh.SSHVendor): client.get_ssh_vendor = _ssh.generate_ssh_vendor(self.ui) # Test for git:// and git+ssh:// URI. # Support several URL forms, including separating the # host and path with either a / or : (sepr) git_pattern = re.compile( r'^(?P<scheme>git([+]ssh)?://)(?P<host>.*?)(:(?P<port>\d+))?' r'(?P<sepr>[:/])(?P<path>.*)$') git_match = git_pattern.match(uri) if git_match: res = git_match.groupdict() transport = client.SSHGitClient if 'ssh' in res[ 'scheme'] else client.TCPGitClient host, port, sepr, path = res['host'], res['port'], res[ 'sepr'], res['path'] if sepr == '/': path = '/' + path # strip trailing slash for heroku-style URLs # ssh+git://[email protected]:project.git/ if sepr == ':' and path.endswith('.git/'): path = path.rstrip('/') if port: client.port = port return transport(host, thin_packs=False, port=port), path httpclient = getattr(client, 'HttpGitClient', None) if uri.startswith('git+http://') or uri.startswith('git+https://'): uri = uri[4:] if uri.startswith('http://') or uri.startswith('https://'): if not httpclient: raise RepoError('git via HTTP requires dulwich 0.8.1 or later') else: return client.HttpGitClient(uri, thin_packs=False), uri # if its not git or git+ssh, try a local url.. return client.SubprocessGitClient(thin_packs=False), uri
def _client(self): return client.HttpGitClient(self._httpd.get_url())
from dulwich import client from dulwich import index from dulwich.repo import Repo url = "https://gitee.com/sdf321/ascend-deployer" local_repo = Repo.init('ad', mkdir=True) remote_repo = client.HttpGitClient(url, pool_manager=None) remote_refs = remote_repo.fetch(url, local_repo) local_repo[b"HEAD"] = remote_refs[b"refs/heads/support_msinstaller"] index_file = local_repo.index_path() tree = local_repo[b"HEAD"].tree index.build_index_from_tree(local_repo.path, index_file, local_repo.object_store, tree)