Skip to content

Commit

Permalink
Raise GitProtocolError when encountering HTTP Errors in HTTPGitClient.
Browse files Browse the repository at this point in the history
Fixes #1199
  • Loading branch information
jelmer committed Aug 9, 2023
1 parent 2c9cf9d commit a19c29b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* Support ``init.defaultBranch`` config.
(Jelmer Vernooij)

* Raise GitProtocolError when encountering HTTP Errors in
HTTPGitClient. (Jelmer Vernooij, #1199)

0.21.3 2023-02-17

* Add support for ``worktreeconfig`` extension.
Expand Down
19 changes: 12 additions & 7 deletions dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,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 @@ -2205,13 +2207,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

0 comments on commit a19c29b

Please sign in to comment.