fetch-pack: show clearer error message upon ERR

Currently, fetch-pack prints a confusing error message ("expected ACK/NAK") when the server it's communicating with sends a pkt-line starting with "ERR". Replace it with a less confusing error message. Also update the documentation describing the fetch-pack/upload-pack protocol (pack-protocol.txt) to indicate that "ERR" can be sent in the place of "ACK" or "NAK". In practice, this has been done for quite some time by other Git implementations (e.g. JGit sends "want $id not valid") and by Git itself (since commit bdb31ea: "upload-pack: report "not our ref" to client", 2017-02-23) whenever a "want" line references an object that it does not have. (This is uncommon, but can happen if a repository is garbage-collected during a negotiation.) Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Apr 12, 2017 at 11:06 UTC 8e2c7bef034f0712c6db776974ee4b40f1150a56
2 files changed +8 -1
Documentation/technical/pack-protocol.txt
+6 -1
@@ -351,14 +351,19 @@ ACK after 'done' if there is at least one common base and multi_ack or
351 multi_ack_detailed is enabled. The server always sends NAK after 'done'
352 if there is no common base found.
353
354 +Instead of 'ACK' or 'NAK', the server may send an error message (for
355 +example, if it does not recognize an object in a 'want' line received
356 +from the client).
357 +
358 Then the server will start sending its packfile data.
359
360 ----
357 - server-response = *ack_multi ack / nak
361 + server-response = *ack_multi ack / nak / error-line
362 ack_multi = PKT-LINE("ACK" SP obj-id ack_status)
363 ack_status = "continue" / "common" / "ready"
364 ack = PKT-LINE("ACK" SP obj-id)
365 nak = PKT-LINE("NAK")
366 + error-line = PKT-LINE("ERR" SP explanation-text)
367 ----
368
369 A simple clone may look like this (with no 'have' lines):
fetch-pack.c
+2
@@ -240,6 +240,8 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1)
240 return ACK;
241 }
242 }
243 + if (skip_prefix(line, "ERR ", &arg))
244 + die(_("remote error: %s"), arg);
245 die(_("git fetch-pack: expected ACK/NAK, got '%s'"), line);
246 }
247