|
|
@ -43,7 +43,9 @@ |
|
|
|
package org.eclipse.jgit.transport; |
|
|
|
package org.eclipse.jgit.transport; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
import static org.junit.Assert.fail; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.eclipse.jgit.errors.PackProtocolException; |
|
|
|
import org.eclipse.jgit.lib.ObjectId; |
|
|
|
import org.eclipse.jgit.lib.ObjectId; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
@ -57,14 +59,34 @@ public class BaseReceivePackTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void parseCommand() { |
|
|
|
public void parseCommand() throws Exception { |
|
|
|
String input = "0000000000000000000000000000000000000000" |
|
|
|
String o = "0000000000000000000000000000000000000000"; |
|
|
|
+ " deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" |
|
|
|
String n = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; |
|
|
|
+ " refs/heads/master"; |
|
|
|
String r = "refs/heads/master"; |
|
|
|
ReceiveCommand cmd = BaseReceivePack.parseCommand(input); |
|
|
|
ReceiveCommand cmd = BaseReceivePack.parseCommand(o + " " + n + " " + r); |
|
|
|
assertEquals(ObjectId.zeroId(), cmd.getOldId()); |
|
|
|
assertEquals(ObjectId.zeroId(), cmd.getOldId()); |
|
|
|
assertEquals("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", |
|
|
|
assertEquals("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", |
|
|
|
cmd.getNewId().name()); |
|
|
|
cmd.getNewId().name()); |
|
|
|
assertEquals("refs/heads/master", cmd.getRefName()); |
|
|
|
assertEquals("refs/heads/master", cmd.getRefName()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertParseCommandFails(null); |
|
|
|
|
|
|
|
assertParseCommandFails(""); |
|
|
|
|
|
|
|
assertParseCommandFails(o.substring(35) + " " + n.substring(35) |
|
|
|
|
|
|
|
+ " " + r + "\n"); |
|
|
|
|
|
|
|
assertParseCommandFails(o + " " + n + " " + r + "\n"); |
|
|
|
|
|
|
|
assertParseCommandFails(o + " " + n + " " + "refs^foo"); |
|
|
|
|
|
|
|
assertParseCommandFails(o + " " + n.substring(10) + " " + r); |
|
|
|
|
|
|
|
assertParseCommandFails(o.substring(10) + " " + n + " " + r); |
|
|
|
|
|
|
|
assertParseCommandFails("X" + o.substring(1) + " " + n + " " + r); |
|
|
|
|
|
|
|
assertParseCommandFails(o + " " + "X" + n.substring(1) + " " + r); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void assertParseCommandFails(String input) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
BaseReceivePack.parseCommand(input); |
|
|
|
|
|
|
|
fail(); |
|
|
|
|
|
|
|
} catch (PackProtocolException e) { |
|
|
|
|
|
|
|
// Expected.
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|