Throw error when deepen-since excludes all commits
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>
This commit is contained in:
parent
a579a56e3a
commit
f5fa1eaf39
|
@ -1279,6 +1279,26 @@ public void testV2FetchShallowSince() throws Exception {
|
|||
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);
|
||||
|
|
|
@ -467,6 +467,7 @@ newIdMustNotBeNull=New ID must not be null
|
|||
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}
|
||||
|
|
|
@ -528,6 +528,7 @@ public static JGitText get() {
|
|||
/***/ public String newlineInQuotesNotAllowed;
|
||||
/***/ public String noApplyInDelete;
|
||||
/***/ public String noClosingBracket;
|
||||
/***/ public String noCommitsSelectedForShallow;
|
||||
/***/ public String noCredentialsProvider;
|
||||
/***/ public String noHEADExistsAndNoExplicitStartingRevisionWasSpecified;
|
||||
/***/ public String noHMACsupport;
|
||||
|
|
|
@ -135,6 +135,10 @@ RevCommit next() throws MissingObjectException,
|
|||
if ((c.flags & RevWalk.PARSED) == 0)
|
||||
c.parseHeaders(walk);
|
||||
|
||||
if (c.getCommitTime() < deepenSince) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int newDepth = c.depth + 1;
|
||||
|
||||
for (RevCommit p : c.parents) {
|
||||
|
|
|
@ -1168,8 +1168,10 @@ private void computeShallowsAndUnshallows(FetchRequest req,
|
|||
}
|
||||
|
||||
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();
|
||||
|
||||
|
@ -1185,6 +1187,10 @@ private void computeShallowsAndUnshallows(FetchRequest req,
|
|||
unshallowFunc.accept(c.copy());
|
||||
}
|
||||
}
|
||||
if (!atLeastOne) {
|
||||
throw new PackProtocolException(
|
||||
JGitText.get().noCommitsSelectedForShallow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue