]> source.dussan.org Git - jgit.git/commitdiff
Handle "ERR %s" when ACK/NAK is expected 50/2750/2
authorShawn O. Pearce <spearce@spearce.org>
Thu, 17 Mar 2011 04:44:34 +0000 (21:44 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Thu, 17 Mar 2011 17:51:31 +0000 (10:51 -0700)
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>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java

index 59b019e6ab180a700c35d396e747a1cfb029e2f6..6f930d737dd2d0256bd8af0e16ecaa63aad53e68 100644 (file)
@@ -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) {
index 01d92770bca80ee24149ca3d8f0a544b131064dd..e5b2494c888350497f9c93f426f7fb4da7aeb3f6 100644 (file)
@@ -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));
        }