In C Git, when a client fetches with "git fetch --shallow-since=<date>
origin <ref>", and all commits reachable from <ref> are older than
<date>, the server dies with a message "no commits selected for shallow
requests". That is, (1) the --shallow-since filter applies to the commit
pointed to by the ref itself, and (2) there is a check that at least one
commit is not filtered out. (The pack-protocol.txt documentation does
not describe this, but the C implementation does this.)
The implementation in commit
1bb430dc21 ("UploadPack: support
deepen-since in protocol v2", 2018-09-27) does neither (1) nor (2), so
do both of these.
Change-Id: I9946327a71627626ecce34ca2d017d2add8867fc
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
assertTrue(client.hasObject(merge.toObjectId()));
}
+ @Test
+ public void testV2FetchShallowSince_noCommitsSelected() throws Exception {
+ PersonIdent person = new PersonIdent(remote.getRepository());
+
+ RevCommit tooOld = remote.commit()
+ .committer(new PersonIdent(person, 1500000000, 0)).create();
+
+ remote.update("branch1", tooOld);
+
+ thrown.expect(PackProtocolException.class);
+ thrown.expectMessage("No commits selected for shallow request");
+ uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "deepen-since 1510000\n",
+ "want " + tooOld.toObjectId().getName() + "\n",
+ "done\n",
+ PacketLineIn.END);
+ }
+
@Test
public void testV2FetchUnrecognizedArgument() throws Exception {
thrown.expect(PackProtocolException.class);
newlineInQuotesNotAllowed=Newline in quotes not allowed
noApplyInDelete=No apply in delete
noClosingBracket=No closing {0} found for {1} at index {2}.
+noCommitsSelectedForShallow=No commits selected for shallow request
noCredentialsProvider=Authentication is required but no CredentialsProvider has been registered
noHEADExistsAndNoExplicitStartingRevisionWasSpecified=No HEAD exists and no explicit starting revision was specified
noHMACsupport=No {0} support: {1}
/***/ public String newlineInQuotesNotAllowed;
/***/ public String noApplyInDelete;
/***/ public String noClosingBracket;
+ /***/ public String noCommitsSelectedForShallow;
/***/ public String noCredentialsProvider;
/***/ public String noHEADExistsAndNoExplicitStartingRevisionWasSpecified;
/***/ public String noHMACsupport;
if ((c.flags & RevWalk.PARSED) == 0)
c.parseHeaders(walk);
+ if (c.getCommitTime() < deepenSince) {
+ continue;
+ }
+
int newDepth = c.depth + 1;
for (RevCommit p : c.parents) {
}
RevCommit o;
+ boolean atLeastOne = false;
while ((o = depthWalk.next()) != null) {
DepthWalk.Commit c = (DepthWalk.Commit) o;
+ atLeastOne = true;
boolean isBoundary = (c.getDepth() == walkDepth) || c.isBoundary();
unshallowFunc.accept(c.copy());
}
}
+ if (!atLeastOne) {
+ throw new PackProtocolException(
+ JGitText.get().noCommitsSelectedForShallow);
+ }
}
}