aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--org.eclipse.jgit.test/META-INF/MANIFEST.MF107
-rw-r--r--org.eclipse.jgit.test/build.properties2
-rw-r--r--org.eclipse.jgit.test/pom.xml2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java61
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java47
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java26
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java21
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java40
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java28
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java23
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java95
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackConnectionTest.java233
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpConfigTest.java98
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java11
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java48
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java222
19 files changed, 972 insertions, 108 deletions
diff --git a/org.eclipse.jgit.test/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jgit.test/.settings/org.eclipse.jdt.core.prefs
index 4c4634ada3..b853c6a7ed 100644
--- a/org.eclipse.jgit.test/.settings/org.eclipse.jdt.core.prefs
+++ b/org.eclipse.jgit.test/.settings/org.eclipse.jdt.core.prefs
@@ -51,7 +51,7 @@ org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=error
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected
-org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=no_tag
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
index 1ce4c2b25f..fc79f43526 100644
--- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Automatic-Module-Name: org.eclipse.jgit.test
Bundle-SymbolicName: org.eclipse.jgit.test
-Bundle-Version: 5.9.1.qualifier
+Bundle-Version: 5.10.1.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %Bundle-Vendor
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
@@ -16,58 +16,59 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
org.apache.commons.compress.compressors.gzip;version="[1.15.0,2.0)",
org.apache.commons.compress.compressors.xz;version="[1.15.0,2.0)",
org.assertj.core.api;version="[3.14.0,4.0.0)",
- org.eclipse.jgit.annotations;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.api;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.api.errors;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.archive;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.attributes;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.awtui;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.blame;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.diff;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.dircache;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.errors;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.events;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.fnmatch;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.gitrepo;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.hooks;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.ignore;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.ignore.internal;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal.fsck;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal.storage.dfs;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal.storage.file;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal.storage.io;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal.storage.pack;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal.storage.reftable;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal.storage.reftree;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal.transport.connectivity;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal.transport.http;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.internal.transport.parser;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.junit;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.junit.time;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.lfs;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.lib;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.lib.internal;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.merge;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.nls;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.notes;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.patch;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.pgm;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.pgm.internal;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.revplot;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.revwalk;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.revwalk.filter;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.storage.file;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.storage.pack;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.submodule;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.transport;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.transport.http;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.transport.resolver;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.treewalk;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.treewalk.filter;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.util;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.util.io;version="[5.9.1,5.10.0)",
- org.eclipse.jgit.util.sha1;version="[5.9.1,5.10.0)",
+ org.eclipse.jgit.annotations;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.api;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.api.errors;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.archive;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.attributes;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.awtui;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.blame;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.diff;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.dircache;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.errors;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.events;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.fnmatch;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.gitrepo;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.hooks;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.ignore;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.ignore.internal;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal.fsck;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal.storage.dfs;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal.storage.io;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal.storage.pack;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal.storage.reftable;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal.storage.reftree;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal.transport.connectivity;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal.transport.http;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.internal.transport.parser;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.junit;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.junit.time;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.lfs;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.lib;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.lib.internal;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.logging;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.merge;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.nls;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.notes;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.patch;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.pgm;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.pgm.internal;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.revplot;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.revwalk;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.revwalk.filter;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.storage.file;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.storage.pack;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.submodule;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.transport;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.transport.http;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.transport.resolver;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.treewalk;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.util;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.util.io;version="[5.10.1,5.11.0)",
+ org.eclipse.jgit.util.sha1;version="[5.10.1,5.11.0)",
org.junit;version="[4.13,5.0.0)",
org.junit.experimental.theories;version="[4.13,5.0.0)",
org.junit.function;version="[4.13.0,5.0.0)",
diff --git a/org.eclipse.jgit.test/build.properties b/org.eclipse.jgit.test/build.properties
index 7dc26c0b0d..b527a74790 100644
--- a/org.eclipse.jgit.test/build.properties
+++ b/org.eclipse.jgit.test/build.properties
@@ -8,4 +8,4 @@ bin.includes = META-INF/,\
bin-tst/,\
bin/
additional.bundles = org.apache.log4j,\
- org.slf4j.impl.log4j12
+ org.slf4j.binding.log4j12
diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml
index d9c9a3da6a..0037684add 100644
--- a/org.eclipse.jgit.test/pom.xml
+++ b/org.eclipse.jgit.test/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit-parent</artifactId>
- <version>5.9.1-SNAPSHOT</version>
+ <version>5.10.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jgit.test</artifactId>
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
index b737bbec0e..de25870bd0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java
@@ -92,7 +92,6 @@ public class CloneCommandTest extends RepositoryTestCase {
command.setURI(fileUri());
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
ObjectId id = git2.getRepository().resolve("tag-for-blob");
assertNotNull(id);
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/test");
@@ -277,8 +276,7 @@ public class CloneCommandTest extends RepositoryTestCase {
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
- assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
+ assertEquals("refs/heads/master", git2.getRepository().getFullBranch());
assertEquals(
"refs/heads/master, refs/remotes/origin/master, refs/remotes/origin/test",
allRefNames(git2.branchList().setListMode(ListMode.ALL).call()));
@@ -293,7 +291,6 @@ public class CloneCommandTest extends RepositoryTestCase {
git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
assertEquals("refs/remotes/origin/master, refs/remotes/origin/test",
allRefNames(git2.branchList().setListMode(ListMode.ALL).call()));
@@ -308,8 +305,7 @@ public class CloneCommandTest extends RepositoryTestCase {
git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
- assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
+ assertEquals("refs/heads/master", git2.getRepository().getFullBranch());
assertEquals("refs/heads/master, refs/heads/test", allRefNames(git2
.branchList().setListMode(ListMode.ALL).call()));
}
@@ -324,7 +320,6 @@ public class CloneCommandTest extends RepositoryTestCase {
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertEquals("refs/heads/test", git2.getRepository().getFullBranch());
}
@@ -338,7 +333,6 @@ public class CloneCommandTest extends RepositoryTestCase {
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
ObjectId taggedCommit = db.resolve("tag-initial^{commit}");
assertEquals(taggedCommit.name(), git2
.getRepository().getFullBranch());
@@ -355,10 +349,9 @@ public class CloneCommandTest extends RepositoryTestCase {
command.setURI(fileUri());
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertNull(git2.getRepository().resolve("tag-for-blob"));
assertNotNull(git2.getRepository().resolve("tag-initial"));
- assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
+ assertEquals("refs/heads/master", git2.getRepository().getFullBranch());
assertEquals("refs/remotes/origin/master", allRefNames(git2
.branchList().setListMode(ListMode.REMOTE).call()));
RemoteConfig cfg = new RemoteConfig(git2.getRepository().getConfig(),
@@ -383,10 +376,9 @@ public class CloneCommandTest extends RepositoryTestCase {
command.setBare(true);
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertNull(git2.getRepository().resolve("tag-for-blob"));
assertNotNull(git2.getRepository().resolve("tag-initial"));
- assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
+ assertEquals("refs/heads/master", git2.getRepository().getFullBranch());
assertEquals("refs/heads/master", allRefNames(git2.branchList()
.setListMode(ListMode.ALL).call()));
RemoteConfig cfg = new RemoteConfig(git2.getRepository().getConfig(),
@@ -409,11 +401,10 @@ public class CloneCommandTest extends RepositoryTestCase {
command.setURI(fileUri());
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertTrue(git2.getRepository().isBare());
assertNotNull(git2.getRepository().resolve("tag-for-blob"));
assertNotNull(git2.getRepository().resolve("tag-initial"));
- assertEquals(git2.getRepository().getFullBranch(), "refs/heads/master");
+ assertEquals("refs/heads/master", git2.getRepository().getFullBranch());
assertEquals("refs/heads/master, refs/heads/test", allRefNames(
git2.branchList().setListMode(ListMode.ALL).call()));
assertNotNull(git2.getRepository().exactRef("refs/meta/foo/bar"));
@@ -436,7 +427,6 @@ public class CloneCommandTest extends RepositoryTestCase {
command.setURI(fileUri());
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertNull(git2.getRepository().resolve("tag-for-blob"));
assertNull(git2.getRepository().resolve("refs/heads/master"));
assertNotNull(git2.getRepository().resolve("tag-initial"));
@@ -464,8 +454,7 @@ public class CloneCommandTest extends RepositoryTestCase {
command.setURI(fileUri());
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
- assertEquals(git2.getRepository().getFullBranch(), "refs/heads/test");
+ assertEquals("refs/heads/test", git2.getRepository().getFullBranch());
// Expect both remote branches to exist; setCloneAllBranches(true)
// should override any setBranchesToClone().
assertNotNull(
@@ -492,8 +481,7 @@ public class CloneCommandTest extends RepositoryTestCase {
command.setURI(fileUri());
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
- assertEquals(git2.getRepository().getFullBranch(), "refs/heads/test");
+ assertEquals("refs/heads/test", git2.getRepository().getFullBranch());
// Expect only the test branch; allBranches was re-set to false
assertNull(git2.getRepository().resolve("refs/remotes/origin/master"));
assertNotNull(git2.getRepository().resolve("refs/remotes/origin/test"));
@@ -525,7 +513,6 @@ public class CloneCommandTest extends RepositoryTestCase {
command.setURI(fileUri());
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
// clone again
command = Git.cloneRepository();
command.setDirectory(directory);
@@ -551,7 +538,6 @@ public class CloneCommandTest extends RepositoryTestCase {
clone.setURI(fileUri());
Git git2 = clone.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertEquals(Constants.MASTER, git2.getRepository().getBranch());
}
@@ -595,7 +581,6 @@ public class CloneCommandTest extends RepositoryTestCase {
clone.setURI(fileUri());
Git git2 = clone.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertEquals(Constants.MASTER, git2.getRepository().getBranch());
assertTrue(new File(git2.getRepository().getWorkTree(), path
@@ -683,7 +668,6 @@ public class CloneCommandTest extends RepositoryTestCase {
clone.setURI(git.getRepository().getDirectory().toURI().toString());
Git git2 = clone.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertEquals(Constants.MASTER, git2.getRepository().getBranch());
assertTrue(new File(git2.getRepository().getWorkTree(), path
@@ -813,7 +797,6 @@ public class CloneCommandTest extends RepositoryTestCase {
command.setNoTags();
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertNotNull(git2.getRepository().resolve("refs/heads/test"));
assertNull(git2.getRepository().resolve("tag-initial"));
assertNull(git2.getRepository().resolve("tag-for-blob"));
@@ -833,13 +816,41 @@ public class CloneCommandTest extends RepositoryTestCase {
command.setTagOption(TagOpt.FETCH_TAGS);
Git git2 = command.call();
addRepoToClose(git2.getRepository());
- assertNotNull(git2);
assertNull(git2.getRepository().resolve("refs/heads/test"));
assertNotNull(git2.getRepository().resolve("tag-initial"));
assertNotNull(git2.getRepository().resolve("tag-for-blob"));
assertTagOption(git2.getRepository(), TagOpt.FETCH_TAGS);
}
+ @Test
+ public void testCloneWithHeadSymRefIsMasterCopy() throws IOException, GitAPIException {
+ // create a branch with the same head as master and switch to it
+ git.checkout().setStartPoint("master").setCreateBranch(true).setName("master-copy").call();
+
+ // when we clone the HEAD symref->master-copy means we start on master-copy and not master
+ File directory = createTempDirectory("testCloneRepositorySymRef_master-copy");
+ CloneCommand command = Git.cloneRepository();
+ command.setDirectory(directory);
+ command.setURI(fileUri());
+ Git git2 = command.call();
+ addRepoToClose(git2.getRepository());
+ assertEquals("refs/heads/master-copy", git2.getRepository().getFullBranch());
+ }
+
+ @Test
+ public void testCloneWithHeadSymRefIsNonMasterCopy() throws IOException, GitAPIException {
+ // create a branch with the same head as test and switch to it
+ git.checkout().setStartPoint("test").setCreateBranch(true).setName("test-copy").call();
+
+ File directory = createTempDirectory("testCloneRepositorySymRef_test-copy");
+ CloneCommand command = Git.cloneRepository();
+ command.setDirectory(directory);
+ command.setURI(fileUri());
+ Git git2 = command.call();
+ addRepoToClose(git2.getRepository());
+ assertEquals("refs/heads/test-copy", git2.getRepository().getFullBranch());
+ }
+
private void assertTagOption(Repository repo, TagOpt expectedTagOption)
throws URISyntaxException {
RemoteConfig remoteConfig = new RemoteConfig(
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
index 7ba7c8d2be..b460e3f52e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
@@ -310,7 +310,7 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertEquals(
"2 commits for describe commit increment expected since lightweight tag: c4 and c3",
"t2-2-g119892b", describe(c4)); // 2 commits: c4 and c3
- } else if (!useAnnotatedTags && !describeUseAllTags) {
+ } else if (!useAnnotatedTags) {
assertEquals("no matching commits expected", null, describe(c4));
} else {
assertEquals(
@@ -405,6 +405,46 @@ public class DescribeCommandTest extends RepositoryTestCase {
}
}
+ @Test
+ public void testDescribeUseAllRefsMaster() throws Exception {
+ final ObjectId c1 = modify("aaa");
+ tag("t1");
+
+ if (useAnnotatedTags || describeUseAllTags) {
+ assertEquals("t1", describe(c1));
+ } else {
+ assertEquals(null, describe(c1));
+ }
+ assertEquals("heads/master", describeAll(c1));
+ }
+
+ /**
+ * Branch off from master and then tag
+ *
+ * <pre>
+ * c1 -+ -> c2
+ * |
+ * +-> t1
+ * </pre>
+ * @throws Exception
+ * */
+ @Test
+ public void testDescribeUseAllRefsBranch() throws Exception {
+ final ObjectId c1 = modify("aaa");
+ modify("bbb");
+
+ branch("b", c1);
+ final ObjectId c3 = modify("ccc");
+ tag("t1");
+
+ if (!useAnnotatedTags && !describeUseAllTags) {
+ assertEquals(null, describe(c3));
+ } else {
+ assertEquals("t1", describe(c3));
+ }
+ assertEquals("heads/b", describeAll(c3));
+ }
+
private ObjectId merge(ObjectId c2) throws GitAPIException {
return git.merge().include(c2).call().getNewHead();
}
@@ -444,6 +484,11 @@ public class DescribeCommandTest extends RepositoryTestCase {
return describe(c1, false, false);
}
+ private String describeAll(ObjectId c1) throws GitAPIException, IOException {
+ return git.describe().setTarget(c1).setTags(describeUseAllTags)
+ .setLong(false).setAlways(false).setAll(true).call();
+ }
+
private String describe(ObjectId c1, String... patterns) throws Exception {
return git.describe().setTarget(c1).setTags(describeUseAllTags)
.setMatch(patterns).call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java
index 00f84e9aea..12ec2aae57 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/LsRemoteCommandTest.java
@@ -11,9 +11,11 @@ package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.Collection;
+import java.util.Optional;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
@@ -34,7 +36,7 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
git.add().addFilepattern("Test.txt").call();
git.commit().setMessage("Initial commit").call();
- // create a master branch and switch to it
+ // create a test branch and switch to it
git.branchCreate().setName("test").call();
RefUpdate rup = db.updateRef(Constants.HEAD);
rup.link("refs/heads/test");
@@ -104,6 +106,28 @@ public class LsRemoteCommandTest extends RepositoryTestCase {
assertEquals(2, refs.size());
}
+ @Test
+ public void testLsRemoteWithSymRefs() throws Exception {
+ File directory = createTempDirectory("testRepository");
+ CloneCommand command = Git.cloneRepository();
+ command.setDirectory(directory);
+ command.setURI(fileUri());
+ command.setCloneAllBranches(true);
+ Git git2 = command.call();
+ addRepoToClose(git2.getRepository());
+
+
+ LsRemoteCommand lsRemoteCommand = git2.lsRemote();
+ Collection<Ref> refs = lsRemoteCommand.call();
+ assertNotNull(refs);
+ assertEquals(6, refs.size());
+
+ Optional<Ref> headRef = refs.stream().filter(ref -> ref.getName().equals(Constants.HEAD)).findFirst();
+ assertTrue("expected a HEAD Ref", headRef.isPresent());
+ assertTrue("expected HEAD Ref to be a Symbolic", headRef.get().isSymbolic());
+ assertEquals("refs/heads/test", headRef.get().getTarget().getName());
+ }
+
private String fileUri() {
return "file://" + git.getRepository().getWorkTree().getAbsolutePath();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java
index e0a1c1d61b..f52b715d39 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011, Kevin Sawicki <kevin@github.com> and others
+ * Copyright (C) 2011, 2020 Kevin Sawicki <kevin@github.com> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -24,6 +24,7 @@ import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.ConfigConstants;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.StoredConfig;
@@ -310,6 +311,16 @@ public class PathCheckoutCommandTest extends RepositoryTestCase {
}
@Test
+ public void testCheckoutFileWithConflict() throws Exception {
+ setupConflictingState();
+ assertEquals('[' + FILE1 + ']',
+ git.status().call().getConflicting().toString());
+ git.checkout().setStartPoint(Constants.HEAD).addPath(FILE1).call();
+ assertEquals("3", read(FILE1));
+ assertTrue(git.status().call().isClean());
+ }
+
+ @Test
public void testCheckoutOursWhenNoBase() throws Exception {
String file = "added.txt";
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
index 7e0de82d82..5311edb0eb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
@@ -160,4 +160,25 @@ public class StatusCommandTest extends RepositoryTestCase {
assertTrue("Expected no differences", status.isClean());
}
}
+
+ @Test
+ public void testFolderPrefix() throws Exception {
+ // "audio" is a prefix of "audio-new" and "audio.new".
+ try (Git git = new Git(db)) {
+ // Order here is the git order, but that doesn't really matter.
+ // They are processed by StatusCommand in this order even if written
+ // in a different order. Bug 566799 would, when having processed
+ // audio/foo, remove previously recorded untracked folders that have
+ // "audio" as a prefix: audio-new and audio.new.
+ writeTrashFile("audi", "foo", "foo");
+ writeTrashFile("audio-new", "foo", "foo");
+ writeTrashFile("audio.new", "foo", "foo");
+ writeTrashFile("audio", "foo", "foo");
+ writeTrashFile("audio_new", "foo", "foo");
+ Status stat = git.status().call();
+ assertEquals(Sets.of("audi", "audio-new", "audio.new", "audio",
+ "audio_new"), stat.getUntrackedFolders());
+ }
+ }
+
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
index 5477f565f4..8e84dfa318 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheEntryTest.java
@@ -242,6 +242,46 @@ public class DirCacheEntryTest {
}
@Test
+ public void testSetStage() {
+ DirCacheEntry e = new DirCacheEntry("some/path", DirCacheEntry.STAGE_1);
+ e.setAssumeValid(true);
+ e.setCreationTime(2L);
+ e.setFileMode(FileMode.EXECUTABLE_FILE);
+ e.setLastModified(EPOCH.plusMillis(3L));
+ e.setLength(100L);
+ e.setObjectId(ObjectId
+ .fromString("0123456789012345678901234567890123456789"));
+ e.setUpdateNeeded(true);
+ e.setStage(DirCacheEntry.STAGE_2);
+
+ assertTrue(e.isAssumeValid());
+ assertEquals(2L, e.getCreationTime());
+ assertEquals(
+ ObjectId.fromString("0123456789012345678901234567890123456789"),
+ e.getObjectId());
+ assertEquals(FileMode.EXECUTABLE_FILE, e.getFileMode());
+ assertEquals(EPOCH.plusMillis(3L), e.getLastModifiedInstant());
+ assertEquals(100L, e.getLength());
+ assertEquals(DirCacheEntry.STAGE_2, e.getStage());
+ assertTrue(e.isUpdateNeeded());
+ assertEquals("some/path", e.getPathString());
+
+ e.setStage(DirCacheEntry.STAGE_0);
+
+ assertTrue(e.isAssumeValid());
+ assertEquals(2L, e.getCreationTime());
+ assertEquals(
+ ObjectId.fromString("0123456789012345678901234567890123456789"),
+ e.getObjectId());
+ assertEquals(FileMode.EXECUTABLE_FILE, e.getFileMode());
+ assertEquals(EPOCH.plusMillis(3L), e.getLastModifiedInstant());
+ assertEquals(100L, e.getLength());
+ assertEquals(DirCacheEntry.STAGE_0, e.getStage());
+ assertTrue(e.isUpdateNeeded());
+ assertEquals("some/path", e.getPathString());
+ }
+
+ @Test
public void testCopyMetaDataWithStage() {
copyMetaDataHelper(false);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
index 39a1f01803..5778d28d6f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCachePathEditTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011, Robin Rosenberg and others
+ * Copyright (C) 2011, 2020 Robin Rosenberg and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -124,6 +124,32 @@ public class DirCachePathEditTest {
}
@Test
+ public void testPathEditWithStagesAndReset() throws Exception {
+ DirCache dc = DirCache.newInCore();
+ DirCacheBuilder builder = new DirCacheBuilder(dc, 3);
+ builder.add(createEntry("a", DirCacheEntry.STAGE_1));
+ builder.add(createEntry("a", DirCacheEntry.STAGE_2));
+ builder.add(createEntry("a", DirCacheEntry.STAGE_3));
+ builder.finish();
+
+ DirCacheEditor editor = dc.editor();
+ PathEdit edit = new PathEdit("a") {
+
+ @Override
+ public void apply(DirCacheEntry ent) {
+ ent.setStage(DirCacheEntry.STAGE_0);
+ }
+ };
+ editor.add(edit);
+ editor.finish();
+
+ assertEquals(1, dc.getEntryCount());
+ DirCacheEntry entry = dc.getEntry(0);
+ assertEquals("a", entry.getPathString());
+ assertEquals(DirCacheEntry.STAGE_0, entry.getStage());
+ }
+
+ @Test
public void testFileReplacesTree() throws Exception {
DirCache dc = DirCache.newInCore();
DirCacheEditor editor = dc.editor();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java
index e8d1cd3d7e..d007dd4511 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java
@@ -80,6 +80,29 @@ public class GcBasicPackingTest extends GcTestCase {
}
@Theory
+ public void testPack2Commits_noPackFolder(boolean aggressive) throws Exception {
+ File packDir = repo.getObjectDatabase().getPackDirectory();
+ assertTrue(packDir.delete());
+
+ BranchBuilder bb = tr.branch("refs/heads/master");
+ bb.commit().add("A", "A").add("B", "B").create();
+ bb.commit().add("A", "A2").add("B", "B2").create();
+
+ stats = gc.getStatistics();
+ assertEquals(8, stats.numberOfLooseObjects);
+ assertEquals(0, stats.numberOfPackedObjects);
+ configureGc(gc, aggressive);
+ gc.gc();
+ stats = gc.getStatistics();
+ assertEquals(0, stats.numberOfLooseObjects);
+ assertEquals(8, stats.numberOfPackedObjects);
+ assertEquals(1, stats.numberOfPackFiles);
+ assertEquals(2, stats.numberOfBitmaps);
+
+ assertTrue(packDir.exists());
+ }
+
+ @Theory
public void testPackAllObjectsInOnePack(boolean aggressive)
throws Exception {
tr.branch("refs/heads/master").commit().add("A", "A").add("B", "B")
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java
new file mode 100644
index 0000000000..f3c1ddec8a
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java
@@ -0,0 +1,95 @@
+package org.eclipse.jgit.logging;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import java.util.List;
+
+/**
+ * Tests for performance log context utilities.
+ */
+public class PerformanceLogContextTest {
+
+ @Test
+ public void testAddEvent() {
+ PerformanceLogRecord record = new PerformanceLogRecord("record", 0);
+ PerformanceLogContext.getInstance().addEvent(record);
+
+ List<PerformanceLogRecord> eventRecords = PerformanceLogContext
+ .getInstance().getEventRecords();
+ assertTrue(eventRecords.contains(record));
+ assertEquals(1, eventRecords.size());
+ }
+
+ @Test
+ public void testCleanEvents() {
+ PerformanceLogRecord record1 = new PerformanceLogRecord("record1", 0);
+ PerformanceLogContext.getInstance().addEvent(record1);
+
+ PerformanceLogRecord record2 = new PerformanceLogRecord("record2", 0);
+ PerformanceLogContext.getInstance().addEvent(record2);
+
+ PerformanceLogContext.getInstance().cleanEvents();
+ List<PerformanceLogRecord> eventRecords = PerformanceLogContext
+ .getInstance().getEventRecords();
+ assertEquals(0, eventRecords.size());
+ }
+
+ @Test
+ public void testAddEventsTwoThreads() throws InterruptedException {
+ TestRunnable runnable1 = new TestRunnable("record1", 1);
+ TestRunnable runnable2 = new TestRunnable("record2", 2);
+
+ Thread thread1 = new Thread(runnable1);
+ Thread thread2 = new Thread(runnable2);
+
+ thread1.start();
+ thread2.start();
+
+ thread1.join();
+ thread2.join();
+ assertEquals(1, runnable1.getEventRecordsCount());
+ assertEquals(1, runnable2.getEventRecordsCount());
+ assertFalse(runnable1.isThrown());
+ assertFalse(runnable2.isThrown());
+ }
+
+ private static class TestRunnable implements Runnable {
+ private String name;
+
+ private long durationMs;
+
+ private long eventRecordsCount;
+
+ private boolean thrown = false;
+
+ public TestRunnable(String name, long durationMs) {
+ this.name = name;
+ this.durationMs = durationMs;
+ }
+
+ public boolean isThrown() {
+ return thrown;
+ }
+
+ public long getEventRecordsCount() {
+ return eventRecordsCount;
+ }
+
+ @Override
+ public void run() {
+ PerformanceLogRecord record = new PerformanceLogRecord(name,
+ durationMs);
+ try {
+ PerformanceLogContext.getInstance().addEvent(record);
+ eventRecordsCount = PerformanceLogContext.getInstance()
+ .getEventRecords().size();
+ PerformanceLogContext.getInstance().cleanEvents();
+ } catch (Exception e) {
+ thrown = true;
+ }
+ }
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java
index 70175c8205..ea994f06aa 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java
@@ -455,6 +455,7 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
final CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree());
try (SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub")) {
+ assertEquals(arbitraryName, gen.getModuleName());
assertEquals(path, gen.getPath());
assertEquals(subId, gen.getObjectId());
assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackConnectionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackConnectionTest.java
new file mode 100644
index 0000000000..64b16f659a
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackConnectionTest.java
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2020, Lee Worrall and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.transport;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectIdRef;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.SymbolicRef;
+import org.junit.Test;
+
+public class BasePackConnectionTest {
+
+ @Test
+ public void testExtractSymRefsFromCapabilities() {
+ final Map<String, String> symRefs = BasePackConnection
+ .extractSymRefsFromCapabilities(
+ Arrays.asList("symref=HEAD:refs/heads/main",
+ "symref=refs/heads/sym:refs/heads/other"));
+
+ assertEquals(2, symRefs.size());
+ assertEquals("refs/heads/main", symRefs.get("HEAD"));
+ assertEquals("refs/heads/other", symRefs.get("refs/heads/sym"));
+ }
+
+ @Test
+ public void testUpdateWithSymRefsAdds() {
+ final Ref mainRef = new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE,
+ "refs/heads/main", ObjectId.fromString(
+ "0000000000000000000000000000000000000001"));
+
+ final Map<String, Ref> refMap = new HashMap<>();
+ refMap.put(mainRef.getName(), mainRef);
+ refMap.put("refs/heads/other",
+ new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE, "refs/heads/other",
+ ObjectId.fromString(
+ "0000000000000000000000000000000000000002")));
+
+ final Map<String, String> symRefs = new HashMap<>();
+ symRefs.put("HEAD", "refs/heads/main");
+
+ BasePackConnection.updateWithSymRefs(refMap, symRefs);
+
+ assertThat(refMap, hasKey("HEAD"));
+ final Ref headRef = refMap.get("HEAD");
+ assertThat(headRef, instanceOf(SymbolicRef.class));
+ final SymbolicRef headSymRef = (SymbolicRef) headRef;
+ assertEquals("HEAD", headSymRef.getName());
+ assertSame(mainRef, headSymRef.getTarget());
+ }
+
+ @Test
+ public void testUpdateWithSymRefsReplaces() {
+ final Ref mainRef = new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE,
+ "refs/heads/main", ObjectId.fromString(
+ "0000000000000000000000000000000000000001"));
+
+ final Map<String, Ref> refMap = new HashMap<>();
+ refMap.put(mainRef.getName(), mainRef);
+ refMap.put("HEAD", new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE, "HEAD",
+ mainRef.getObjectId()));
+ refMap.put("refs/heads/other",
+ new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE, "refs/heads/other",
+ ObjectId.fromString(
+ "0000000000000000000000000000000000000002")));
+
+ final Map<String, String> symRefs = new HashMap<>();
+ symRefs.put("HEAD", "refs/heads/main");
+
+ BasePackConnection.updateWithSymRefs(refMap, symRefs);
+
+ assertThat(refMap, hasKey("HEAD"));
+ final Ref headRef = refMap.get("HEAD");
+ assertThat(headRef, instanceOf(SymbolicRef.class));
+ final SymbolicRef headSymRef = (SymbolicRef) headRef;
+ assertEquals("HEAD", headSymRef.getName());
+ assertSame(mainRef, headSymRef.getTarget());
+ }
+
+ @Test
+ public void testUpdateWithSymRefsWithIndirectsAdds() {
+ final Ref mainRef = new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE,
+ "refs/heads/main", ObjectId.fromString(
+ "0000000000000000000000000000000000000001"));
+
+ final Map<String, Ref> refMap = new HashMap<>();
+ refMap.put(mainRef.getName(), mainRef);
+ refMap.put("refs/heads/other",
+ new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE, "refs/heads/other",
+ ObjectId.fromString(
+ "0000000000000000000000000000000000000002")));
+
+ final Map<String, String> symRefs = new LinkedHashMap<>(); // Ordered
+ symRefs.put("refs/heads/sym3", "refs/heads/sym2"); // Forward reference
+ symRefs.put("refs/heads/sym1", "refs/heads/main");
+ symRefs.put("refs/heads/sym2", "refs/heads/sym1"); // Backward reference
+
+ BasePackConnection.updateWithSymRefs(refMap, symRefs);
+
+ assertThat(refMap, hasKey("refs/heads/sym1"));
+ final Ref sym1Ref = refMap.get("refs/heads/sym1");
+ assertThat(sym1Ref, instanceOf(SymbolicRef.class));
+ final SymbolicRef sym1SymRef = (SymbolicRef) sym1Ref;
+ assertEquals("refs/heads/sym1", sym1SymRef.getName());
+ assertSame(mainRef, sym1SymRef.getTarget());
+
+ assertThat(refMap, hasKey("refs/heads/sym2"));
+ final Ref sym2Ref = refMap.get("refs/heads/sym2");
+ assertThat(sym2Ref, instanceOf(SymbolicRef.class));
+ final SymbolicRef sym2SymRef = (SymbolicRef) sym2Ref;
+ assertEquals("refs/heads/sym2", sym2SymRef.getName());
+ assertSame(sym1SymRef, sym2SymRef.getTarget());
+
+ assertThat(refMap, hasKey("refs/heads/sym3"));
+ final Ref sym3Ref = refMap.get("refs/heads/sym3");
+ assertThat(sym3Ref, instanceOf(SymbolicRef.class));
+ final SymbolicRef sym3SymRef = (SymbolicRef) sym3Ref;
+ assertEquals("refs/heads/sym3", sym3SymRef.getName());
+ assertSame(sym2SymRef, sym3SymRef.getTarget());
+ }
+
+ @Test
+ public void testUpdateWithSymRefsWithIndirectsReplaces() {
+ final Ref mainRef = new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE,
+ "refs/heads/main", ObjectId.fromString(
+ "0000000000000000000000000000000000000001"));
+
+ final Map<String, Ref> refMap = new HashMap<>();
+ refMap.put(mainRef.getName(), mainRef);
+ refMap.put("refs/heads/sym1", new ObjectIdRef.Unpeeled(
+ Ref.Storage.LOOSE, "refs/heads/sym1", mainRef.getObjectId()));
+ refMap.put("refs/heads/sym2", new ObjectIdRef.Unpeeled(
+ Ref.Storage.LOOSE, "refs/heads/sym2", mainRef.getObjectId()));
+ refMap.put("refs/heads/sym3", new ObjectIdRef.Unpeeled(
+ Ref.Storage.LOOSE, "refs/heads/sym3", mainRef.getObjectId()));
+ refMap.put("refs/heads/other",
+ new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE, "refs/heads/other",
+ ObjectId.fromString(
+ "0000000000000000000000000000000000000002")));
+
+ final Map<String, String> symRefs = new LinkedHashMap<>(); // Ordered
+ symRefs.put("refs/heads/sym3", "refs/heads/sym2"); // Forward reference
+ symRefs.put("refs/heads/sym1", "refs/heads/main");
+ symRefs.put("refs/heads/sym2", "refs/heads/sym1"); // Backward reference
+
+ BasePackConnection.updateWithSymRefs(refMap, symRefs);
+
+ assertThat(refMap, hasKey("refs/heads/sym1"));
+ final Ref sym1Ref = refMap.get("refs/heads/sym1");
+ assertThat(sym1Ref, instanceOf(SymbolicRef.class));
+ final SymbolicRef sym1SymRef = (SymbolicRef) sym1Ref;
+ assertEquals("refs/heads/sym1", sym1SymRef.getName());
+ assertSame(mainRef, sym1SymRef.getTarget());
+
+ assertThat(refMap, hasKey("refs/heads/sym2"));
+ final Ref sym2Ref = refMap.get("refs/heads/sym2");
+ assertThat(sym2Ref, instanceOf(SymbolicRef.class));
+ final SymbolicRef sym2SymRef = (SymbolicRef) sym2Ref;
+ assertEquals("refs/heads/sym2", sym2SymRef.getName());
+ assertSame(sym1SymRef, sym2SymRef.getTarget());
+
+ assertThat(refMap, hasKey("refs/heads/sym3"));
+ final Ref sym3Ref = refMap.get("refs/heads/sym3");
+ assertThat(sym3Ref, instanceOf(SymbolicRef.class));
+ final SymbolicRef sym3SymRef = (SymbolicRef) sym3Ref;
+ assertEquals("refs/heads/sym3", sym3SymRef.getName());
+ assertSame(sym2SymRef, sym3SymRef.getTarget());
+ }
+
+ @Test
+ public void testUpdateWithSymRefsIgnoresSelfReference() {
+ final Ref mainRef = new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE,
+ "refs/heads/main", ObjectId.fromString(
+ "0000000000000000000000000000000000000001"));
+
+ final Map<String, Ref> refMap = new HashMap<>();
+ refMap.put(mainRef.getName(), mainRef);
+ refMap.put("refs/heads/other",
+ new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE, "refs/heads/other",
+ ObjectId.fromString(
+ "0000000000000000000000000000000000000002")));
+
+ final Map<String, String> symRefs = new LinkedHashMap<>();
+ symRefs.put("refs/heads/sym1", "refs/heads/sym1");
+
+ BasePackConnection.updateWithSymRefs(refMap, symRefs);
+
+ assertEquals(2, refMap.size());
+ assertThat(refMap, not(hasKey("refs/heads/sym1")));
+ }
+
+ @Test
+ public void testUpdateWithSymRefsIgnoreCircularReference() {
+ final Ref mainRef = new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE,
+ "refs/heads/main", ObjectId.fromString(
+ "0000000000000000000000000000000000000001"));
+
+ final Map<String, Ref> refMap = new HashMap<>();
+ refMap.put(mainRef.getName(), mainRef);
+ refMap.put("refs/heads/other",
+ new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE, "refs/heads/other",
+ ObjectId.fromString(
+ "0000000000000000000000000000000000000002")));
+
+ final Map<String, String> symRefs = new LinkedHashMap<>();
+ symRefs.put("refs/heads/sym2", "refs/heads/sym1");
+ symRefs.put("refs/heads/sym1", "refs/heads/sym2");
+
+ BasePackConnection.updateWithSymRefs(refMap, symRefs);
+
+ assertEquals(2, refMap.size());
+ assertThat(refMap, not(hasKey("refs/heads/sym1")));
+ assertThat(refMap, not(hasKey("refs/heads/sym2")));
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpConfigTest.java
index fcbec52a54..5336dd73c6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpConfigTest.java
@@ -13,7 +13,9 @@ package org.eclipse.jgit.transport;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.util.SystemReader;
import org.junit.Before;
import org.junit.Test;
@@ -25,6 +27,7 @@ public class HttpConfigTest {
private static final String DEFAULT = "[http]\n" + "\tpostBuffer = 1\n"
+ "\tsslVerify= true\n" + "\tfollowRedirects = true\n"
+ + "\textraHeader = x: y\n" + "\tuserAgent = Test/0.1\n"
+ "\tmaxRedirects = 5\n\n";
private Config config;
@@ -95,7 +98,8 @@ public class HttpConfigTest {
@Test
public void testMatchWithInvalidUriInConfig() throws Exception {
config.fromText(
- DEFAULT + "[http \"///\"]\n" + "\tpostBuffer = 1024\n");
+ DEFAULT + "[http \"///#expectedWarning\"]\n"
+ + "\tpostBuffer = 1024\n");
HttpConfig http = new HttpConfig(config,
new URIish("http://example.com/path/repo.git"));
assertEquals(1, http.getPostBuffer());
@@ -103,7 +107,8 @@ public class HttpConfigTest {
@Test
public void testMatchWithInvalidAndValidUriInConfig() throws Exception {
- config.fromText(DEFAULT + "[http \"///\"]\n" + "\tpostBuffer = 1024\n"
+ config.fromText(DEFAULT + "[http \"///#expectedWarning\"]\n"
+ + "\tpostBuffer = 1024\n"
+ "[http \"http://example.com\"]\n" + "\tpostBuffer = 2048\n");
HttpConfig http = new HttpConfig(config,
new URIish("http://example.com/path/repo.git"));
@@ -174,4 +179,93 @@ public class HttpConfigTest {
new URIish("http://user@example.com/path"));
assertEquals(1024, http.getPostBuffer());
}
+
+ @Test
+ public void testExtraHeaders() throws Exception {
+ config.fromText(DEFAULT + "[http \"http://example.com\"]\n"
+ + "\textraHeader=foo: bar\n");
+ HttpConfig http = new HttpConfig(config,
+ new URIish("http://example.com/"));
+ assertEquals(1, http.getExtraHeaders().size());
+ assertEquals("foo: bar", http.getExtraHeaders().get(0));
+ }
+
+ @Test
+ public void testExtraHeadersMultiple() throws Exception {
+ config.fromText(DEFAULT + "[http \"http://example.com\"]\n"
+ + "\textraHeader=foo: bar\n" //
+ + "\textraHeader=bar: foo\n");
+ HttpConfig http = new HttpConfig(config,
+ new URIish("http://example.com/"));
+ assertEquals(2, http.getExtraHeaders().size());
+ assertEquals("foo: bar", http.getExtraHeaders().get(0));
+ assertEquals("bar: foo", http.getExtraHeaders().get(1));
+ }
+
+ @Test
+ public void testExtraHeadersReset() throws Exception {
+ config.fromText(DEFAULT + "[http \"http://example.com\"]\n"
+ + "\textraHeader=foo: bar\n" //
+ + "\textraHeader=bar: foo\n" //
+ + "\textraHeader=\n");
+ HttpConfig http = new HttpConfig(config,
+ new URIish("http://example.com/"));
+ assertTrue(http.getExtraHeaders().isEmpty());
+ }
+
+ @Test
+ public void testExtraHeadersResetAndMore() throws Exception {
+ config.fromText(DEFAULT + "[http \"http://example.com\"]\n"
+ + "\textraHeader=foo: bar\n" //
+ + "\textraHeader=bar: foo\n" //
+ + "\textraHeader=\n" //
+ + "\textraHeader=baz: something\n");
+ HttpConfig http = new HttpConfig(config,
+ new URIish("http://example.com/"));
+ assertEquals(1, http.getExtraHeaders().size());
+ assertEquals("baz: something", http.getExtraHeaders().get(0));
+ }
+
+ @Test
+ public void testUserAgent() throws Exception {
+ config.fromText(DEFAULT + "[http \"http://example.com\"]\n"
+ + "\tuserAgent=DummyAgent/4.0\n");
+ HttpConfig http = new HttpConfig(config,
+ new URIish("http://example.com/"));
+ assertEquals("DummyAgent/4.0", http.getUserAgent());
+ }
+
+ @Test
+ public void testUserAgentEnvOverride() throws Exception {
+ String mockAgent = "jgit-test/5.10.0";
+ SystemReader originalReader = SystemReader.getInstance();
+ SystemReader.setInstance(new MockSystemReader() {
+
+ @Override
+ public String getenv(String variable) {
+ if ("GIT_HTTP_USER_AGENT".equals(variable)) {
+ return mockAgent;
+ }
+ return super.getenv(variable);
+ }
+ });
+ try {
+ config.fromText(DEFAULT + "[http \"http://example.com\"]\n"
+ + "\tuserAgent=DummyAgent/4.0\n");
+ HttpConfig http = new HttpConfig(config,
+ new URIish("http://example.com/"));
+ assertEquals(mockAgent, http.getUserAgent());
+ } finally {
+ SystemReader.setInstance(originalReader);
+ }
+ }
+
+ @Test
+ public void testUserAgentNonAscii() throws Exception {
+ config.fromText(DEFAULT + "[http \"http://example.com\"]\n"
+ + "\tuserAgent= d ümmy Agent -5.10\n");
+ HttpConfig http = new HttpConfig(config,
+ new URIish("http://example.com/"));
+ assertEquals("d.mmy.Agent.-5.10", http.getUserAgent());
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java
index 5d7f881ab9..7f03357e9c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java
@@ -12,8 +12,8 @@ package org.eclipse.jgit.transport;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
@@ -111,20 +111,25 @@ public class PacketLineInTest {
final String act = in.readString();
assertEquals("", act);
assertFalse(PacketLineIn.isEnd(act));
+ assertFalse(PacketLineIn.isDelimiter(act));
assertEOF();
}
@Test
public void testReadString_End() throws IOException {
init("0000");
- assertTrue(PacketLineIn.isEnd(in.readString()));
+ String act = in.readString();
+ assertTrue(PacketLineIn.isEnd(act));
+ assertFalse(PacketLineIn.isDelimiter(act));
assertEOF();
}
@Test
public void testReadString_Delim() throws IOException {
init("0001");
- assertTrue(PacketLineIn.isDelimiter(in.readString()));
+ String act = in.readString();
+ assertTrue(PacketLineIn.isDelimiter(act));
+ assertFalse(PacketLineIn.isEnd(act));
assertEOF();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java
index b84b6b2e0b..029b45e1e6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java
@@ -18,7 +18,9 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
+import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.internal.transport.http.NetscapeCookieFile;
@@ -155,4 +157,50 @@ public class TransportHttpTest extends SampleDataRepositoryTestCase {
cookieFile.exists());
}
}
+
+ private void assertHeaders(String expected, String... headersToAdd) {
+ HttpConnection fake = Mockito.mock(HttpConnection.class);
+ Map<String, String> headers = new LinkedHashMap<>();
+ Mockito.doAnswer(invocation -> {
+ Object[] args = invocation.getArguments();
+ headers.put(args[0].toString(), args[1].toString());
+ return null;
+ }).when(fake).setRequestProperty(ArgumentMatchers.anyString(),
+ ArgumentMatchers.anyString());
+ TransportHttp.addHeaders(fake, Arrays.asList(headersToAdd));
+ Assert.assertEquals(expected, headers.toString());
+ }
+
+ @Test
+ public void testAddHeaders() {
+ assertHeaders("{a=b, c=d}", "a: b", "c :d");
+ }
+
+ @Test
+ public void testAddHeaderEmptyValue() {
+ assertHeaders("{a-x=b, c=, d=e}", "a-x: b", "c:", "d:e");
+ }
+
+ @Test
+ public void testSkipHeaderWithEmptyKey() {
+ assertHeaders("{a=b, c=d}", "a: b", " : x", "c :d");
+ assertHeaders("{a=b, c=d}", "a: b", ": x", "c :d");
+ }
+
+ @Test
+ public void testSkipHeaderWithoutKey() {
+ assertHeaders("{a=b, c=d}", "a: b", "x", "c :d");
+ }
+
+ @Test
+ public void testSkipHeaderWithInvalidKey() {
+ assertHeaders("{a=b, c=d}", "a: b", "q/p: x", "c :d");
+ assertHeaders("{a=b, c=d}", "a: b", "ä: x", "c :d");
+ }
+
+ @Test
+ public void testSkipHeaderWithNonAsciiValue() {
+ assertHeaders("{a=b, c=d}", "a: b", "q/p: x", "c :d");
+ assertHeaders("{a=b, c=d}", "a: b", "x: ä", "c :d");
+ }
}
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 46ba3aa5d4..5045e9464e 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
@@ -362,23 +362,22 @@ public class UploadPackTest {
}
/*
- * Invokes UploadPack with protocol v2 and sends it the given lines,
+ * Invokes UploadPack with specified protocol version and sends it the given lines,
* and returns UploadPack's output stream.
*/
- private ByteArrayInputStream uploadPackV2Setup(
+ private ByteArrayInputStream uploadPackSetup(String version,
Consumer<UploadPack> postConstructionSetup, String... inputLines)
throws Exception {
ByteArrayInputStream send = linesAsInputStream(inputLines);
server.getConfig().setString(ConfigConstants.CONFIG_PROTOCOL_SECTION,
- null, ConfigConstants.CONFIG_KEY_VERSION,
- TransferConfig.ProtocolVersion.V2.version());
+ null, ConfigConstants.CONFIG_KEY_VERSION, version);
UploadPack up = new UploadPack(server);
if (postConstructionSetup != null) {
postConstructionSetup.accept(up);
}
- up.setExtraParameters(Sets.of("version=2"));
+ up.setExtraParameters(Sets.of("version=".concat(version)));
ByteArrayOutputStream recv = new ByteArrayOutputStream();
up.upload(send, recv, null);
@@ -406,6 +405,30 @@ public class UploadPackTest {
}
/*
+ * Invokes UploadPack with protocol v1 and sends it the given lines.
+ * Returns UploadPack's output stream, not including the capability
+ * advertisement by the server.
+ */
+ private ByteArrayInputStream uploadPackV1(
+ Consumer<UploadPack> postConstructionSetup,
+ String... inputLines)
+ throws Exception {
+ ByteArrayInputStream recvStream =
+ uploadPackSetup("1", postConstructionSetup, inputLines);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ // drain capabilities
+ while (!PacketLineIn.isEnd(pckIn.readString())) {
+ // do nothing
+ }
+ return recvStream;
+ }
+
+ private ByteArrayInputStream uploadPackV1(String... inputLines) throws Exception {
+ return uploadPackV1(null, inputLines);
+ }
+
+ /*
* Invokes UploadPack with protocol v2 and sends it the given lines.
* Returns UploadPack's output stream, not including the capability
* advertisement by the server.
@@ -414,8 +437,9 @@ public class UploadPackTest {
Consumer<UploadPack> postConstructionSetup,
String... inputLines)
throws Exception {
- ByteArrayInputStream recvStream =
- uploadPackV2Setup(postConstructionSetup, inputLines);
+ ByteArrayInputStream recvStream = uploadPackSetup(
+ TransferConfig.ProtocolVersion.V2.version(),
+ postConstructionSetup, inputLines);
PacketLineIn pckIn = new PacketLineIn(recvStream);
// drain capabilities
@@ -455,9 +479,11 @@ public class UploadPackTest {
@Test
public void testV2Capabilities() throws Exception {
TestV2Hook hook = new TestV2Hook();
- ByteArrayInputStream recvStream = uploadPackV2Setup(
- (UploadPack up) -> {up.setProtocolV2Hook(hook);},
- PacketLineIn.end());
+ ByteArrayInputStream recvStream = uploadPackSetup(
+ TransferConfig.ProtocolVersion.V2.version(),
+ (UploadPack up) -> {
+ up.setProtocolV2Hook(hook);
+ }, PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(hook.capabilitiesRequest, notNullValue());
assertThat(pckIn.readString(), is("version 2"));
@@ -477,8 +503,9 @@ public class UploadPackTest {
private void checkAdvertisedIfAllowed(String configSection, String configName,
String fetchCapability) throws Exception {
server.getConfig().setBoolean(configSection, null, configName, true);
- ByteArrayInputStream recvStream =
- uploadPackV2Setup(null, PacketLineIn.end());
+ ByteArrayInputStream recvStream = uploadPackSetup(
+ TransferConfig.ProtocolVersion.V2.version(), null,
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("version 2"));
@@ -501,8 +528,9 @@ public class UploadPackTest {
private void checkUnadvertisedIfUnallowed(String configSection,
String configName, String fetchCapability) throws Exception {
server.getConfig().setBoolean(configSection, null, configName, false);
- ByteArrayInputStream recvStream =
- uploadPackV2Setup(null, PacketLineIn.end());
+ ByteArrayInputStream recvStream = uploadPackSetup(
+ TransferConfig.ProtocolVersion.V2.version(), null,
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("version 2"));
@@ -553,8 +581,9 @@ public class UploadPackTest {
public void testV2CapabilitiesRefInWantNotAdvertisedIfAdvertisingForbidden() throws Exception {
server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", true);
server.getConfig().setBoolean("uploadpack", null, "advertiserefinwant", false);
- ByteArrayInputStream recvStream =
- uploadPackV2Setup(null, PacketLineIn.end());
+ ByteArrayInputStream recvStream = uploadPackSetup(
+ TransferConfig.ProtocolVersion.V2.version(), null,
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("version 2"));
@@ -718,7 +747,10 @@ public class UploadPackTest {
PacketLineIn.end() };
TestV2Hook testHook = new TestV2Hook();
- uploadPackV2Setup((UploadPack up) -> {up.setProtocolV2Hook(testHook);}, lines);
+ uploadPackSetup(TransferConfig.ProtocolVersion.V2.version(),
+ (UploadPack up) -> {
+ up.setProtocolV2Hook(testHook);
+ }, lines);
LsRefsV2Request req = testHook.lsRefsRequest;
assertEquals(2, req.getServerOptions().size());
@@ -1063,6 +1095,70 @@ public class UploadPackTest {
}
@Test
+ public void testUploadNewBytes() throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwx";
+
+ RevBlob parentBlob = remote.blob(commonInBlob + "a");
+ RevCommit parent = remote.commit(remote.tree(remote.file("foo", parentBlob)));
+ RevBlob childBlob = remote.blob(commonInBlob + "b");
+ RevCommit child = remote.commit(remote.tree(remote.file("foo", childBlob)), parent);
+ remote.update("branch1", child);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.delimiter(),
+ "want " + child.toObjectId().getName() + "\n",
+ "ofs-delta\n",
+ "done\n",
+ PacketLineIn.end());
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ ReceivedPackStatistics receivedStats = parsePack(recvStream);
+ assertTrue(receivedStats.getNumBytesDuplicated() == 0);
+ assertTrue(receivedStats.getNumObjectsDuplicated() == 0);
+ }
+
+ @Test
+ public void testUploadRedundantBytes() throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
+
+ RevBlob parentBlob = remote.blob(commonInBlob + "a");
+ RevCommit parent = remote.commit(remote.tree(remote.file("foo", parentBlob)));
+ RevBlob childBlob = remote.blob(commonInBlob + "b");
+ RevCommit child = remote.commit(remote.tree(remote.file("foo", childBlob)), parent);
+ remote.update("branch1", child);
+
+ try (TestRepository<InMemoryRepository> local = new TestRepository<>(
+ client)) {
+ RevBlob localParentBlob = local.blob(commonInBlob + "a");
+ RevCommit localParent = local
+ .commit(local.tree(local.file("foo", localParentBlob)));
+ RevBlob localChildBlob = local.blob(commonInBlob + "b");
+ RevCommit localChild = local.commit(
+ local.tree(local.file("foo", localChildBlob)), localParent);
+ local.update("branch1", localChild);
+ }
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.delimiter(),
+ "want " + child.toObjectId().getName() + "\n",
+ "ofs-delta\n",
+ "done\n",
+ PacketLineIn.end());
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ ReceivedPackStatistics receivedStats = parsePack(recvStream);
+
+ long sizeOfHeader = 12;
+ long sizeOfTrailer = 20;
+ long expectedSize = receivedStats.getNumBytesRead() - sizeOfHeader
+ - sizeOfTrailer;
+ assertTrue(receivedStats.getNumBytesDuplicated() == expectedSize);
+ assertTrue(receivedStats.getNumObjectsDuplicated() == 6);
+ }
+
+ @Test
public void testV2FetchOfsDelta() throws Exception {
String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
@@ -1474,7 +1570,10 @@ public class UploadPackTest {
PacketLineIn.end() };
TestV2Hook testHook = new TestV2Hook();
- uploadPackV2Setup((UploadPack up) -> {up.setProtocolV2Hook(testHook);}, lines);
+ uploadPackSetup(TransferConfig.ProtocolVersion.V2.version(),
+ (UploadPack up) -> {
+ up.setProtocolV2Hook(testHook);
+ }, lines);
FetchV2Request req = testHook.fetchRequest;
assertNotNull(req);
@@ -2329,6 +2428,93 @@ public class UploadPackTest {
assertEquals(1, ((RefCallsCountingRepository)server).numRefCalls());
}
+ @Test
+ public void testNotAdvertisedWantsV1Fetch() throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
+
+ RevBlob parentBlob = remote.blob(commonInBlob + "a");
+ RevCommit parent = remote
+ .commit(remote.tree(remote.file("foo", parentBlob)));
+ RevBlob childBlob = remote.blob(commonInBlob + "b");
+ RevCommit child = remote
+ .commit(remote.tree(remote.file("foo", childBlob)), parent);
+ remote.update("branch1", child);
+
+ uploadPackV1("want " + child.toObjectId().getName() + "\n",
+ PacketLineIn.end(),
+ "have " + parent.toObjectId().getName() + "\n",
+ "done\n", PacketLineIn.end());
+
+ assertEquals(0, stats.getNotAdvertisedWants());
+ }
+
+ @Test
+ public void testNotAdvertisedWantsV1FetchRequestPolicyReachableCommit() throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
+
+ RevBlob parentBlob = remote.blob(commonInBlob + "a");
+ RevCommit parent = remote
+ .commit(remote.tree(remote.file("foo", parentBlob)));
+ RevBlob childBlob = remote.blob(commonInBlob + "b");
+ RevCommit child = remote
+ .commit(remote.tree(remote.file("foo", childBlob)), parent);
+
+ remote.update("branch1", child);
+
+ uploadPackV1((UploadPack up) -> {up.setRequestPolicy(RequestPolicy.REACHABLE_COMMIT);},
+ "want " + parent.toObjectId().getName() + "\n",
+ PacketLineIn.end(),
+ "done\n", PacketLineIn.end());
+
+ assertEquals(1, stats.getNotAdvertisedWants());
+ }
+
+ @Test
+ public void testNotAdvertisedWantsV2FetchThinPack() throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
+
+ RevBlob parentBlob = remote.blob(commonInBlob + "a");
+ RevCommit parent = remote
+ .commit(remote.tree(remote.file("foo", parentBlob)));
+ RevBlob childBlob = remote.blob(commonInBlob + "b");
+ RevCommit child = remote
+ .commit(remote.tree(remote.file("foo", childBlob)), parent);
+ remote.update("branch1", child);
+
+ ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n",
+ PacketLineIn.delimiter(),
+ "want " + child.toObjectId().getName() + "\n",
+ "have " + parent.toObjectId().getName() + "\n", "thin-pack\n",
+ "done\n", PacketLineIn.end());
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("packfile"));
+
+ assertEquals(0, stats.getNotAdvertisedWants());
+ }
+
+ @Test
+ public void testNotAdvertisedWantsV2FetchRequestPolicyReachableCommit() throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
+
+ RevBlob parentBlob = remote.blob(commonInBlob + "a");
+ RevCommit parent = remote
+ .commit(remote.tree(remote.file("foo", parentBlob)));
+ RevBlob childBlob = remote.blob(commonInBlob + "b");
+ RevCommit child = remote
+ .commit(remote.tree(remote.file("foo", childBlob)), parent);
+
+ remote.update("branch1", child);
+
+ uploadPackV2((UploadPack up) -> {up.setRequestPolicy(RequestPolicy.REACHABLE_COMMIT);},
+ "command=fetch\n",
+ PacketLineIn.delimiter(),
+ "want " + parent.toObjectId().getName() + "\n", "thin-pack\n",
+ "done\n", PacketLineIn.end());
+
+ assertEquals(1, stats.getNotAdvertisedWants());
+ }
+
private class RefCallsCountingRepository extends InMemoryRepository {
private final InMemoryRepository.MemRefDatabase refdb;
private int numRefCalls;