def fetch(repo, remote_location, remote_name=b'origin', outstream=sys.stdout, errstream=default_bytes_err_stream, message=None, depth=None, **kwargs): """Fetch objects from a remote server. :param repo: Path to the repository :param remote_location: String identifying a remote server :param remote_name: Name for remote server :param outstream: Output stream (defaults to stdout) :param errstream: Error stream (defaults to stderr) :param message: Reflog message (defaults to b"fetch: from <remote_name>") :param depth: Depth to fetch at :return: Dictionary with refs on the remote """ if message is None: message = b'fetch: from ' + remote_location.encode("utf-8") with open_repo_closing(repo) as r: client, path = get_transport_and_path( remote_location, config=r.get_config_stack(), **kwargs) fetch_result = client.fetch(path, r, progress=errstream.write, depth=depth) stripped_refs = strip_peeled_refs(fetch_result.refs) branches = { n[len(b'refs/heads/'):]: v for (n, v) in stripped_refs.items() if n.startswith(b'refs/heads/')} r.refs.import_refs( b'refs/remotes/' + remote_name, branches, message=message) tags = { n[len(b'refs/tags/'):]: v for (n, v) in stripped_refs.items() if n.startswith(b'refs/tags/') and not n.endswith(ANNOTATED_TAG_SUFFIX)} r.refs.import_refs(b'refs/tags', tags, message=message) return fetch_result.refs
def fetch(repo, remote_location, remote_name=b'origin', outstream=sys.stdout, errstream=default_bytes_err_stream, message=None, **kwargs): """Fetch objects from a remote server. :param repo: Path to the repository :param remote_location: String identifying a remote server :param remote_name: Name for remote server :param outstream: Output stream (defaults to stdout) :param errstream: Error stream (defaults to stderr) :param message: Reflog message (defaults to b"fetch: from <remote_name>") :return: Dictionary with refs on the remote """ if message is None: message = b'fetch: from ' + remote_location.encode("utf-8") with open_repo_closing(repo) as r: client, path = get_transport_and_path( remote_location, config=r.get_config_stack(), **kwargs) fetch_result = client.fetch(path, r, progress=errstream.write) stripped_refs = strip_peeled_refs(fetch_result.refs) branches = { n[len(b'refs/heads/'):]: v for (n, v) in stripped_refs.items() if n.startswith(b'refs/heads/')} r.refs.import_refs( b'refs/remotes/' + remote_name, branches, message=message) tags = { n[len(b'refs/tags/'):]: v for (n, v) in stripped_refs.items() if n.startswith(b'refs/tags/') and not n.endswith(ANNOTATED_TAG_SUFFIX)} r.refs.import_refs(b'refs/tags', tags, message=message) return fetch_result.refs
def fetch(repo, remote_location, remote_name=b'origin', outstream=sys.stdout, errstream=default_bytes_err_stream, **kwargs): """Fetch objects from a remote server. :param repo: Path to the repository :param remote_location: String identifying a remote server :param remote_name: Name for remote server :param outstream: Output stream (defaults to stdout) :param errstream: Error stream (defaults to stderr) :return: Dictionary with refs on the remote """ with open_repo_closing(repo) as r: client, path = get_transport_and_path( remote_location, config=r.get_config_stack(), **kwargs) fetch_result = client.fetch(path, r, progress=errstream.write) ref_name = b'refs/remotes/' + remote_name r.refs.import_refs(ref_name, strip_peeled_refs(fetch_result.refs)) return fetch_result.refs
def fetch(repo, remote_location, remote_name=b'origin', outstream=sys.stdout, errstream=default_bytes_err_stream, **kwargs): """Fetch objects from a remote server. :param repo: Path to the repository :param remote_location: String identifying a remote server :param remote_name: Name for remote server :param outstream: Output stream (defaults to stdout) :param errstream: Error stream (defaults to stderr) :return: Dictionary with refs on the remote """ with open_repo_closing(repo) as r: client, path = get_transport_and_path( remote_location, config=r.get_config_stack(), **kwargs) fetch_result = client.fetch(path, r, progress=errstream.write) ref_name = b'refs/remotes/' + remote_name r.refs.import_refs(ref_name, strip_peeled_refs(fetch_result.refs)) return fetch_result.refs
def test_strip_peeled_refs(self): # Simple check of two dicts self.assertEqual(strip_peeled_refs(self.all_refs), self.non_peeled_refs)
def test_strip_peeled_refs(self): # Simple check of two dicts self.assertEqual( strip_peeled_refs(self.all_refs), self.non_peeled_refs)