From e665e3fcd4fdb5097332c0e048c80ccc0dd05caf Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Wed, 29 Aug 2018 16:36:42 -0700 Subject: UploadPack: avoid conflating shallow commit lists in protocol v2 At the moment there are two copies of the client shallow commit list: one in the request and another in the clientShallowCommits member of the class. The verifyShallowCommit function was removing missing object ids from the member but not the request list, and code afterwards was using the request's version. In practice, this didn't cause trouble because these shallow commits are used as endpoint for a walk, and missing ids are just never reached. Change-Id: I70a8f1fd46de135da09f16e5d954693c8438ffcb Signed-off-by: Ivan Frade --- .../org/eclipse/jgit/transport/UploadPackTest.java | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'org.eclipse.jgit.test') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 79d3d87e2d..4c6076a20b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -1417,6 +1417,44 @@ public class UploadPackTest { assertFalse(client.hasObject(parent.toObjectId())); } + @Test + public void testV2FetchMissingShallow() throws Exception { + RevCommit one = remote.commit().message("1").create(); + RevCommit two = remote.commit().message("2").parent(one).create(); + RevCommit three = remote.commit().message("3").parent(two).create(); + remote.update("three", three); + + server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", + true); + + ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n", + PacketLineIn.DELIM, + "want-ref refs/heads/three\n", + "deepen 3", + "shallow 0123012301230123012301230123012301230123", + "shallow " + two.getName() + '\n', + "done\n", + PacketLineIn.END); + PacketLineIn pckIn = new PacketLineIn(recvStream); + + assertThat(pckIn.readString(), is("shallow-info")); + assertThat(pckIn.readString(), + is("shallow " + one.toObjectId().getName())); + assertThat(pckIn.readString(), + is("unshallow " + two.toObjectId().getName())); + assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertThat(pckIn.readString(), is("wanted-refs")); + assertThat(pckIn.readString(), + is(three.toObjectId().getName() + " refs/heads/three")); + assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertThat(pckIn.readString(), is("packfile")); + parsePack(recvStream); + + assertTrue(client.hasObject(one.toObjectId())); + assertTrue(client.hasObject(two.toObjectId())); + assertTrue(client.hasObject(three.toObjectId())); + } + private static class RejectAllRefFilter implements RefFilter { @Override public Map filter(Map refs) { -- cgit v1.2.3