threads / patch / 16121

v2connect.c: add a way for git-daemon to pass an error back to client

Subject: [PATCH v2] connect.c: add a way for git-daemon to pass an error back to client

## tl;dr

One message between Nov 1, 2008 and Nov 1, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Tom Preston-Werner· Nov 1, 2008, 18:44 UTC · lore

The current behavior of git-daemon is to simply close the connection on any error condition. This leaves the client without any information as to the cause of the failed fetch/push/etc.

This patch allows get_remote_heads to accept a line prefixed with "ERR" that it can display to the user in an informative fashion. Once clients can understand this ERR line, git-daemon can be made to properly report "repository not found", "permission denied", or other errors.

Example
S: ERR No matching repository.
C: fatal: remote error: No matching repository.
Signed-off-by: Tom Preston-Werner <tom@github.com>
---
Use prefixcmp instead of memcmp and test for "ERR " instead of "ERR"
 connect.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Show changes to connect.c +3 −0
diff --git a/connect.c b/connect.c
index 0c50d0a..584e04c 100644
--- a/connect.c
+++ b/connect.c
@@ -70,6 +70,9 @@ struct ref **get_remote_heads(int in, struct ref **list,
 		if (buffer[len-1] == '\n')
 			buffer[--len] = 0;

+		if (len > 4 && !prefixcmp(buffer, "ERR "))
+			die("remote error: %s", buffer + 4);
+
 		if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
 			die("protocol error: expected sha/ref, got '%s'", buffer);
 		name = buffer + 41;
-- 
1.6.0.2

← back to recent threads