Browse Source

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>
stable-5.2
Jonathan Tan 6 years ago
parent
commit
f5fa1eaf39
  1. 20
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
  2. 1
      org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
  3. 1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
  4. 4
      org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java
  5. 6
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

20
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java

@ -1279,6 +1279,26 @@ public class UploadPackTest {
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);

1
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties

@ -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}

1
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

@ -528,6 +528,7 @@ public class JGitText extends TranslationBundle {
/***/ public String newlineInQuotesNotAllowed;
/***/ public String noApplyInDelete;
/***/ public String noClosingBracket;
/***/ public String noCommitsSelectedForShallow;
/***/ public String noCredentialsProvider;
/***/ public String noHEADExistsAndNoExplicitStartingRevisionWasSpecified;
/***/ public String noHMACsupport;

4
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java

@ -135,6 +135,10 @@ class DepthGenerator extends Generator {
if ((c.flags & RevWalk.PARSED) == 0)
c.parseHeaders(walk);
if (c.getCommitTime() < deepenSince) {
continue;
}
int newDepth = c.depth + 1;
for (RevCommit p : c.parents) {

6
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

@ -1168,8 +1168,10 @@ public class UploadPack {
}
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 @@ public class UploadPack {
unshallowFunc.accept(c.copy());
}
}
if (!atLeastOne) {
throw new PackProtocolException(
JGitText.get().noCommitsSelectedForShallow);
}
}
}

Loading…
Cancel
Save