summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.test/tst
diff options
context:
space:
mode:
authorRobin Müller <eclipse@mail.coder-hugo.de>2022-05-13 13:46:13 +0200
committerThomas Wolf <twolf@apache.org>2022-07-31 14:08:47 +0200
commit207dd4c938830e84c9101d30edb7fe626e04bbe1 (patch)
tree7279856259550f207ac821d2ab83ecf3b4687acc /org.eclipse.jgit.http.test/tst
parent559be665296e7587e3ff0425152b631c93b4b56d (diff)
downloadjgit-207dd4c938830e84c9101d30edb7fe626e04bbe1.tar.gz
jgit-207dd4c938830e84c9101d30edb7fe626e04bbe1.zip
Fetch: add support for shallow
This adds support for shallow cloning. The CloneCommand and the FetchCommand now have the new methods setDepth, setShallowSince and addShallowExclude to tell the server that the client doesn't want to download the complete history. Bug: 475615 Change-Id: Ic80fb6efb5474543ae59be590ebe385bec21cc0d
Diffstat (limited to 'org.eclipse.jgit.http.test/tst')
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java109
1 files changed, 109 insertions, 0 deletions
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
index 3438c52c8d..6b067273a9 100644
--- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
@@ -24,13 +24,16 @@ import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
import java.text.MessageFormat;
+import java.time.Instant;
import java.util.List;
+import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.errors.NoRemoteRepositoryException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.errors.TransportException;
@@ -408,4 +411,110 @@ public class HttpClientTests extends AllFactoriesHttpTestCase {
assertEquals(200, c.getResponseCode());
}
+
+ @Test
+ public void testCloneWithDepth() throws Exception {
+ remoteRepository.getRepository().getConfig().setInt(
+ "protocol", null, "version", 0);
+ File directory = createTempDirectory("testCloneWithDepth");
+ Git git = Git.cloneRepository()
+ .setDirectory(directory)
+ .setDepth(1)
+ .setURI(smartAuthNoneURI.toString())
+ .call();
+
+ assertEquals(Set.of(git.getRepository().resolve(Constants.HEAD)), git.getRepository().getObjectDatabase().getShallowCommits());
+ }
+
+ @Test
+ public void testCloneWithDeepenSince() throws Exception {
+ remoteRepository.getRepository().getConfig().setInt(
+ "protocol", null, "version", 0);
+ RevCommit commit = remoteRepository.commit()
+ .parent(remoteRepository.git().log().call().iterator().next())
+ .message("Test")
+ .add("test.txt", "Hello world")
+ .create();
+ remoteRepository.update(master, commit);
+
+ File directory = createTempDirectory("testCloneWithDeepenSince");
+ Git git = Git.cloneRepository()
+ .setDirectory(directory)
+ .setShallowSince(Instant.ofEpochSecond(commit.getCommitTime()))
+ .setURI(smartAuthNoneURI.toString())
+ .call();
+
+ assertEquals(Set.of(git.getRepository().resolve(Constants.HEAD)), git.getRepository().getObjectDatabase().getShallowCommits());
+ }
+
+ @Test
+ public void testCloneWithDeepenNot() throws Exception {
+ remoteRepository.getRepository().getConfig().setInt(
+ "protocol", null, "version", 0);
+ RevCommit commit = remoteRepository.git().log().call().iterator().next();
+ remoteRepository.update(master, remoteRepository.commit()
+ .parent(commit)
+ .message("Test")
+ .add("test.txt", "Hello world")
+ .create());
+
+ File directory = createTempDirectory("testCloneWithDeepenNot");
+ Git git = Git.cloneRepository()
+ .setDirectory(directory)
+ .addShallowExclude(commit.getId())
+ .setURI(smartAuthNoneURI.toString())
+ .call();
+
+ assertEquals(Set.of(git.getRepository().resolve(Constants.HEAD)), git.getRepository().getObjectDatabase().getShallowCommits());
+ }
+
+ @Test
+ public void testV2CloneWithDepth() throws Exception {
+ File directory = createTempDirectory("testV2CloneWithDepth");
+ Git git = Git.cloneRepository()
+ .setDirectory(directory)
+ .setDepth(1)
+ .setURI(smartAuthNoneURI.toString())
+ .call();
+
+ assertEquals(Set.of(git.getRepository().resolve(Constants.HEAD)), git.getRepository().getObjectDatabase().getShallowCommits());
+ }
+
+ @Test
+ public void testV2CloneWithDeepenSince() throws Exception {
+ RevCommit commit = remoteRepository.commit()
+ .parent(remoteRepository.git().log().call().iterator().next())
+ .message("Test")
+ .add("test.txt", "Hello world")
+ .create();
+ remoteRepository.update(master, commit);
+
+ File directory = createTempDirectory("testV2CloneWithDeepenSince");
+ Git git = Git.cloneRepository()
+ .setDirectory(directory)
+ .setShallowSince(Instant.ofEpochSecond(commit.getCommitTime()))
+ .setURI(smartAuthNoneURI.toString())
+ .call();
+
+ assertEquals(Set.of(git.getRepository().resolve(Constants.HEAD)), git.getRepository().getObjectDatabase().getShallowCommits());
+ }
+
+ @Test
+ public void testV2CloneWithDeepenNot() throws Exception {
+ RevCommit commit = remoteRepository.git().log().call().iterator().next();
+ remoteRepository.update(master, remoteRepository.commit()
+ .parent(commit)
+ .message("Test")
+ .add("test.txt", "Hello world")
+ .create());
+
+ File directory = createTempDirectory("testV2CloneWithDeepenNot");
+ Git git = Git.cloneRepository()
+ .setDirectory(directory)
+ .addShallowExclude(commit.getId())
+ .setURI(smartAuthNoneURI.toString())
+ .call();
+
+ assertEquals(Set.of(git.getRepository().resolve(Constants.HEAD)), git.getRepository().getObjectDatabase().getShallowCommits());
+ }
}