From: Shawn O. Pearce Date: Thu, 17 Mar 2011 04:44:34 +0000 (-0700) Subject: Handle "ERR %s" when ACK/NAK is expected X-Git-Tag: v0.12.1~61 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F50%2F2750%2F2;p=jgit.git Handle "ERR %s" when ACK/NAK is expected If the remote peer replies with "ERR %s" instead of "ACK %s common" or "NAK" during ancestor negotiation in the fetch-pack/upload-pack protocol, treat that as an exception that aborts processing with the error text as supplied by the remote system. This matches behavior with "ERR %s" during the advertisements, which is also a way for the remote to abort processing. Change-Id: I2fe818e75c7f46156744ef4f703c40173cbc76d0 Signed-off-by: Shawn O. Pearce --- diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java index 59b019e6ab..6f930d737d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java @@ -52,6 +52,7 @@ import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.IOException; +import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.lib.ObjectId; @@ -317,6 +318,17 @@ public class PacketLineInTest { } } + @Test + public void testReadACK_ERR() throws IOException { + init("001aERR want is not valid\n"); + try { + in.readACK(new MutableObjectId()); + fail("incorrectly accepted ERR"); + } catch (PackProtocolException e) { + assertEquals("want is not valid", e.getMessage()); + } + } + // test support private void init(final String msg) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java index 01d92770bc..e5b2494c88 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java @@ -101,6 +101,8 @@ class PacketLineIn { else if (arg.equals(" ready")) return AckNackResult.ACK_READY; } + if (line.startsWith("ERR ")) + throw new PackProtocolException(line.substring(4)); throw new PackProtocolException(MessageFormat.format(JGitText.get().expectedACKNAKGot, line)); }