Skip to content

Commit

Permalink
Merge pull request jelmer#1200 from jelmer/http-error
Browse files Browse the repository at this point in the history
Raise GitProtocolError when encountering HTTP Errors in HTTPGitClient
  • Loading branch information
jelmer authored Aug 9, 2023
2 parents 7574997 + 47e157e commit 4af6b54
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 12 additions & 7 deletions dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,8 @@ def _http_request(self, url, headers=None, data=None):
redirect_location properties, and read is a consumable read
method for the response data.
Raises:
GitProtocolError
"""
raise NotImplementedError(self._http_request)

Expand Down Expand Up @@ -2225,13 +2227,16 @@ def _http_request(self, url, headers=None, data=None):
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()
Expand Down
2 changes: 1 addition & 1 deletion dulwich/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down
4 changes: 2 additions & 2 deletions dulwich/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ def test_run_command_password_and_privkey(self):
)

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(
Expand Down Expand Up @@ -1583,7 +1583,7 @@ def test_run_command_password(self):
)

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(
Expand Down
2 changes: 1 addition & 1 deletion dulwich/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ def test_shell_hook_post_commit(self):
"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(
Expand Down

0 comments on commit 4af6b54

Please sign in to comment.