← Back to team overview

dulwich-users team mailing list archive

better error reporting in read_refs

 

Hi,

This little patch gives me better error reporting in
read_refs. Previously, when I tried to push to a read-only path at
github, I'd only see:

The remote server unexpectedly closed the connection.

This patch allows me to see the actual error message, as I would with
git push.
diff --git a/dulwich/client.py b/dulwich/client.py
--- a/dulwich/client.py
+++ b/dulwich/client.py
@@ -26,6 +26,7 @@
 import urlparse
 
 from dulwich.errors import (
+    GitProtocolError,
     SendPackError,
     UpdateRefsError,
     )
@@ -95,6 +96,8 @@
         # Receive refs from server
         for pkt in proto.read_pkt_seq():
             (sha, ref) = pkt.rstrip('\n').split(' ', 1)
+            if sha == 'ERR':
+                raise GitProtocolError(ref)
             if server_capabilities is None:
                 (ref, server_capabilities) = extract_capabilities(ref)
             refs[ref] = sha

Follow ups