Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/scmrepo/git/backend/dulwich/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def iter_remote_refs(self, url: str, base: Optional[str] = None, **kwargs):
def get_refs_containing(self, rev: str, pattern: Optional[str] = None):
raise NotImplementedError

def push_refspecs(
def push_refspecs( # noqa: C901
self,
url: str,
refspecs: Union[str, Iterable[str]],
Expand Down Expand Up @@ -568,7 +568,7 @@ def update_refs(refs):
return new_refs

try:
client.send_pack(
result = client.send_pack(
path,
update_refs,
self.repo.object_store.generate_pack_data,
Expand All @@ -579,6 +579,17 @@ def update_refs(refs):
raise SCMError(f"Git failed to push '{src}' to '{url}'") from exc
except HTTPUnauthorized as exc:
raise AuthError(url) from exc
if result.ref_status and any(
(value is not None) for value in result.ref_status.values()
):
reasons = ", ".join(
(
f"{os.fsdecode(ref)}: {reason}"
for ref, reason in result.ref_status.items()
if reason is not None
)
)
raise SCMError(f"Git failed to push some refs to '{url}' ({reasons})")
return change_result

def fetch_refspecs(
Expand Down
28 changes: 24 additions & 4 deletions src/scmrepo/git/backend/dulwich/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional
from typing import Dict, Iterator, List, Optional, Union

from dulwich.client import HTTPUnauthorized, Urllib3HttpGitClient

Expand Down Expand Up @@ -27,10 +27,28 @@ def _http_request(
self,
url: str,
headers: Optional[Dict[str, str]] = None,
data: Any = None,
data: Optional[Union[bytes, Iterator[bytes]]] = None,
):
cached_chunks: List[bytes] = []

def _cached_data() -> Iterator[bytes]:
assert data is not None
if isinstance(data, bytes):
yield data
return

if cached_chunks:
yield from cached_chunks
return

for chunk in data:
cached_chunks.append(chunk)
yield chunk

try:
result = super()._http_request(url, headers=headers, data=data)
result = super()._http_request(
url, headers=headers, data=None if data is None else _cached_data()
)
except HTTPUnauthorized:
auth_header = self._get_auth()
if not auth_header:
Expand All @@ -39,7 +57,9 @@ def _http_request(
headers.update(auth_header)
else:
headers = auth_header
result = super()._http_request(url, headers=headers, data=data)
result = super()._http_request(
url, headers=headers, data=None if data is None else _cached_data()
)
if self._store_credentials is not None:
self._store_credentials.approve()
return result
Expand Down