From a615d01ad53772548068d57f66972d184e4f53a3 Mon Sep 17 00:00:00 2001 From: Stefan Sperling Date: Tue, 19 Dec 2023 11:10:31 +0000 Subject: [PATCH] emulate Git's behaviour when a server does not support object filtering Git prints a warning and proceeds with an unfiltered clone/fetch operation. Make dulwich behave the same way, for now. --- dulwich/client.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dulwich/client.py b/dulwich/client.py index 2b6abc9f1..726552f5d 100644 --- a/dulwich/client.py +++ b/dulwich/client.py @@ -1091,6 +1091,15 @@ def archive( """Retrieve an archive of the specified tree.""" raise NotImplementedError(self.archive) + @staticmethod + def _warn_filter_objects(): + import warnings + + warnings.warn( + "object filtering not recognized by server, ignoring", + UserWarning, + ) + def check_wants(wants, refs): """Check that a set of wants is valid. @@ -1332,6 +1341,10 @@ def fetch_pack( if find_capability(negotiated_capabilities, CAPABILITY_FETCH, CAPABILITY_FILTER) and filter_spec: proto.write(pkt_line(b"filter %s\n" % filter_spec)) + elif filter_spec: + self._warn_filter_objects() + elif filter_spec: + self._warn_filter_objects() (new_shallow, new_unshallow) = _handle_upload_pack_head( proto, negotiated_capabilities, @@ -2483,8 +2496,12 @@ def fetch_pack( if find_capability(negotiated_capabilities, CAPABILITY_FETCH, CAPABILITY_FILTER) and filter_spec: data += pkt_line(b"filter %s\n" % filter_spec) + elif filter_spec: + self._warn_filter_objects() data += req_data.getvalue() else: + if filter_spec: + self._warn_filter_objects() data = req_data.getvalue() resp, read = self._smart_request( "git-upload-pack", url, data) try: