diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2011-03-16 21:44:34 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2011-03-17 10:51:31 -0700 |
commit | b0a29c3fcfae9f23949db5cbee46db30448531cf (patch) | |
tree | 40932c9742b454c493c5be41b859cf3500a5eea7 | |
parent | 00a50401478171b900b5f1ea16c43618293706ce (diff) | |
download | jgit-b0a29c3fcfae9f23949db5cbee46db30448531cf.tar.gz jgit-b0a29c3fcfae9f23949db5cbee46db30448531cf.zip |
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 <spearce@spearce.org>
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java | 12 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java | 2 |
2 files changed, 14 insertions, 0 deletions
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)); } |