Browse Source

Merge pull request #1200 from jelmer/http-error

Raise GitProtocolError when encountering HTTP Errors in HTTPGitClient
Jelmer Vernooij 1 year ago
parent
commit
4af6b54c4c
5 changed files with 19 additions and 11 deletions
  1. 3 0
      NEWS
  2. 12 7
      dulwich/client.py
  3. 1 1
      dulwich/objects.py
  4. 2 2
      dulwich/tests/test_client.py
  5. 1 1
      dulwich/tests/test_repository.py

+ 3 - 0
NEWS

@@ -17,6 +17,9 @@
  * objects: Define a stricter return type for _parse_message
    (Vincent Lorentz)
 
+ * Raise GitProtocolError when encountering HTTP Errors in
+   HTTPGitClient. (Jelmer Vernooij, #1199)
+
 0.21.5	2023-05-04
 
  * Be more tolerant to non-3-length tuple versions.

+ 12 - 7
dulwich/client.py

@@ -1949,6 +1949,8 @@ class AbstractHttpGitClient(GitClient):
           redirect_location properties, and read is a consumable read
           method for the response data.
 
+        Raises:
+          GitProtocolError
         """
         raise NotImplementedError(self._http_request)
 
@@ -2225,13 +2227,16 @@ class Urllib3HttpGitClient(AbstractHttpGitClient):
             req_headers.update(headers)
         req_headers["Pragma"] = "no-cache"
 
-        if data is None:
-            resp = self.pool_manager.request(
-                "GET", url, headers=req_headers, preload_content=False)
-        else:
-            resp = self.pool_manager.request(
-                "POST", url, headers=req_headers, body=data, preload_content=False
-            )
+        try:
+            if data is None:
+                resp = self.pool_manager.request(
+                    "GET", url, headers=req_headers, preload_content=False)
+            else:
+                resp = self.pool_manager.request(
+                    "POST", url, headers=req_headers, body=data, preload_content=False
+                )
+        except urllib3.exceptions.HTTPError as e:
+            raise GitProtocolError(str(e)) from e
 
         if resp.status == 404:
             raise NotGitRepository()

+ 1 - 1
dulwich/objects.py

@@ -141,7 +141,7 @@ def hex_to_filename(path, hex):
     # os.path.join accepts bytes or unicode, but all args must be of the same
     # type. Make sure that hex which is expected to be bytes, is the same type
     # as path.
-    if type(path) != type(hex) and getattr(path, "encode", None) is not None:
+    if type(path) is not type(hex) and getattr(path, "encode", None) is not None:
         hex = hex.decode("ascii")
     dir = hex[:2]
     file = hex[2:]

+ 2 - 2
dulwich/tests/test_client.py

@@ -1538,7 +1538,7 @@ class PLinkSSHVendorTests(TestCase):
         )
 
         for w in warnings_list:
-            if type(w) == type(expected_warning) and w.args == expected_warning.args:
+            if type(w) is type(expected_warning) and w.args == expected_warning.args:
                 break
         else:
             raise AssertionError(
@@ -1583,7 +1583,7 @@ class PLinkSSHVendorTests(TestCase):
         )
 
         for w in warnings_list:
-            if type(w) == type(expected_warning) and w.args == expected_warning.args:
+            if type(w) is type(expected_warning) and w.args == expected_warning.args:
                 break
         else:
             raise AssertionError(

+ 1 - 1
dulwich/tests/test_repository.py

@@ -842,7 +842,7 @@ exit 1
             "non-zero status 1",
         )
         for w in warnings_list:
-            if type(w) == type(expected_warning) and w.args == expected_warning.args:
+            if type(w) is type(expected_warning) and w.args == expected_warning.args:
                 break
         else:
             raise AssertionError(