Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/.settings/org.eclipse.pde.prefs34
-rw-r--r--org.eclipse.jgit.test/BUILD4
-rw-r--r--org.eclipse.jgit.test/META-INF/MANIFEST.MF107
-rw-r--r--org.eclipse.jgit.test/pom.xml4
-rw-r--r--org.eclipse.jgit.test/resources/org/eclipse/jgit/transport/ssh/id_ed25519_expensive_testpass8
-rw-r--r--org.eclipse.jgit.test/resources/org/eclipse/jgit/transport/ssh/id_ed25519_expensive_testpass.pub1
-rw-r--r--org.eclipse.jgit.test/src/org/eclipse/jgit/lib/Sets.java4
-rw-r--r--org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestBase.java4
-rw-r--r--org.eclipse.jgit.test/tests.bzl6
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-invalid.txt1
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple1.txt2
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple2.txt2
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-empty-and-comment-lines.txt8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java12
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java28
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java50
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java49
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java117
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java26
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java40
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java15
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/InMemoryRepositoryTest.java150
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java23
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java55
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java17
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java31
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java34
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java339
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java42
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java31
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RebaseTodoFileTest.java142
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java17
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java43
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmapCalculatorTest.java181
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmappedReachabilityCheckerTest.java69
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/PedestrianReachabilityCheckerTest.java57
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ReachabilityCheckerTestCase.java168
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PacketLineInTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java19
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java80
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java34
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushOptionsTest.java18
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java24
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefAdvertiserTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java35
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java189
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java734
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java37
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java78
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java35
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/http/HttpCookiesMatcher.java150
63 files changed, 2712 insertions, 722 deletions
diff --git a/org.eclipse.jgit.test/.settings/org.eclipse.pde.prefs b/org.eclipse.jgit.test/.settings/org.eclipse.pde.prefs
new file mode 100644
index 0000000000..2174e4fd5b
--- /dev/null
+++ b/org.eclipse.jgit.test/.settings/org.eclipse.pde.prefs
@@ -0,0 +1,34 @@
+compilers.f.unresolved-features=1
+compilers.f.unresolved-plugins=1
+compilers.incompatible-environment=1
+compilers.p.build=1
+compilers.p.build.bin.includes=1
+compilers.p.build.encodings=2
+compilers.p.build.java.compiler=2
+compilers.p.build.java.compliance=1
+compilers.p.build.missing.output=2
+compilers.p.build.output.library=1
+compilers.p.build.source.library=1
+compilers.p.build.src.includes=1
+compilers.p.deprecated=1
+compilers.p.discouraged-class=1
+compilers.p.internal=1
+compilers.p.missing-packages=2
+compilers.p.missing-version-export-package=2
+compilers.p.missing-version-import-package=2
+compilers.p.missing-version-require-bundle=2
+compilers.p.no-required-att=0
+compilers.p.no.automatic.module=1
+compilers.p.not-externalized-att=2
+compilers.p.service.component.without.lazyactivation=1
+compilers.p.unknown-attribute=1
+compilers.p.unknown-class=1
+compilers.p.unknown-element=1
+compilers.p.unknown-identifier=1
+compilers.p.unknown-resource=1
+compilers.p.unresolved-ex-points=0
+compilers.p.unresolved-import=0
+compilers.s.create-docs=false
+compilers.s.doc-folder=doc
+compilers.s.open-tags=1
+eclipse.preferences.version=1
diff --git a/org.eclipse.jgit.test/BUILD b/org.eclipse.jgit.test/BUILD
index ca5b42e48d..f90a28030d 100644
--- a/org.eclipse.jgit.test/BUILD
+++ b/org.eclipse.jgit.test/BUILD
@@ -19,6 +19,7 @@ HELPERS = glob(
"nls/MissingPropertyBundle.java",
"nls/NoPropertiesBundle.java",
"nls/NonTranslatedBundle.java",
+ "revwalk/ReachabilityCheckerTestCase.java",
"revwalk/RevQueueTestCase.java",
"revwalk/RevWalkTestCase.java",
"transport/ObjectIdMatcher.java",
@@ -26,6 +27,7 @@ HELPERS = glob(
"treewalk/filter/AlwaysCloneTreeFilter.java",
"test/resources/SampleDataRepositoryTestCase.java",
"util/CPUTimeStopWatch.java",
+ "util/http/HttpCookiesMatcher.java",
"util/io/Strings.java",
]]
@@ -68,7 +70,7 @@ java_library(
deps = [
"//lib:jsch",
"//lib:junit",
- "//lib:sshd-core",
+ "//lib:sshd-osgi",
"//lib:sshd-sftp",
"//org.eclipse.jgit:jgit",
"//org.eclipse.jgit.junit:junit",
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
index a1e94bfaa2..c6adef0bcf 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: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.test
Bundle-SymbolicName: org.eclipse.jgit.test
-Bundle-Version: 5.3.3.qualifier
+Bundle-Version: 5.4.1.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
Bundle-ActivationPolicy: lazy
@@ -17,57 +17,58 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
org.apache.commons.compress.compressors.bzip2;version="[1.15.0,2.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.bouncycastle.util.encoders;version="[1.60.0,2.0.0)",
- org.eclipse.jgit.annotations;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.api;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.api.errors;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.archive;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.attributes;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.awtui;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.blame;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.diff;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.dircache;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.errors;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.events;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.fnmatch;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.gitrepo;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.hooks;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.ignore;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.ignore.internal;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.internal;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.internal.fsck;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.internal.storage.dfs;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.internal.storage.file;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.internal.storage.io;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.internal.storage.pack;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.internal.storage.reftable;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.internal.storage.reftree;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.internal.transport.parser;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.junit;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.junit.ssh;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.junit.time;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.lfs;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.lib;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.merge;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.nls;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.notes;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.patch;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.pgm;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.pgm.internal;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.revplot;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.revwalk;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.revwalk.filter;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.storage.file;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.storage.pack;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.submodule;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.transport;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.transport.http;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.transport.resolver;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.treewalk;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.treewalk.filter;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.util;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.util.io;version="[5.3.3,5.4.0)",
- org.eclipse.jgit.util.sha1;version="[5.3.3,5.4.0)",
+ org.bouncycastle.util.encoders;version="[1.61.0,2.0.0)",
+ org.eclipse.jgit.annotations;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.api;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.api.errors;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.archive;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.attributes;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.awtui;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.blame;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.diff;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.dircache;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.errors;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.events;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.fnmatch;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.gitrepo;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.hooks;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.ignore;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.ignore.internal;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.internal;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.internal.fsck;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.internal.storage.dfs;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.internal.storage.io;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.internal.storage.pack;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.internal.storage.reftable;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.internal.storage.reftree;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.internal.transport.http;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.internal.transport.parser;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.junit;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.junit.ssh;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.junit.time;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.lfs;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.lib;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.merge;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.nls;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.notes;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.patch;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.pgm;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.pgm.internal;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.revplot;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.revwalk;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.revwalk.filter;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.storage.file;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.storage.pack;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.submodule;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.transport;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.transport.http;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.transport.resolver;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.treewalk;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.util;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.util.io;version="[5.4.1,5.5.0)",
+ org.eclipse.jgit.util.sha1;version="[5.4.1,5.5.0)",
org.junit;version="[4.12,5.0.0)",
org.junit.experimental.theories;version="[4.12,5.0.0)",
org.junit.rules;version="[4.12,5.0.0)",
@@ -82,4 +83,4 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
org.tukaani.xz;version="[1.6.0,2.0)"
Require-Bundle: org.hamcrest.core;bundle-version="[1.1.0,2.0.0)",
org.hamcrest.library;bundle-version="[1.1.0,2.0.0)"
-Export-Package: org.eclipse.jgit.transport.ssh;version="5.3.3";x-friends:="org.eclipse.jgit.ssh.apache.test"
+Export-Package: org.eclipse.jgit.transport.ssh;version="5.4.1";x-friends:="org.eclipse.jgit.ssh.apache.test"
diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml
index e6ba6f8e69..7d930ff117 100644
--- a/org.eclipse.jgit.test/pom.xml
+++ b/org.eclipse.jgit.test/pom.xml
@@ -52,7 +52,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit-parent</artifactId>
- <version>5.3.3-SNAPSHOT</version>
+ <version>5.4.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jgit.test</artifactId>
@@ -197,7 +197,7 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <argLine>@{argLine} -Xmx1024m -Dfile.encoding=UTF-8 -Djava.io.tmpdir=${project.build.directory}</argLine>
+ <argLine>@{argLine} -Xmx768m -Dfile.encoding=UTF-8 -Djava.io.tmpdir=${project.build.directory}</argLine>
<includes>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
diff --git a/org.eclipse.jgit.test/resources/org/eclipse/jgit/transport/ssh/id_ed25519_expensive_testpass b/org.eclipse.jgit.test/resources/org/eclipse/jgit/transport/ssh/id_ed25519_expensive_testpass
new file mode 100644
index 0000000000..904cf302c2
--- /dev/null
+++ b/org.eclipse.jgit.test/resources/org/eclipse/jgit/transport/ssh/id_ed25519_expensive_testpass
@@ -0,0 +1,8 @@
+-----BEGIN OPENSSH PRIVATE KEY-----
+b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABAsFN8vig
+Nw4/Ow6xbb7MAZAAABAAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAIEZXZRjuttLufaP8
+wFD/i4lYPnKk01z46Jwv/9U4mPioAAAAkHLErPaXeC179rzXMaSwClstzsKvJ/Gqh2cY8d
+cWzymXtKZcivWMKesRHbC+1qRx53ofx15IzT5Fmg6NuNk4sm2s+lH8x8HN3CPWBfjGIelP
+iQUR6M6Y91mPigpRC2HUJmJIaFNdrRqFF84a5+qyK//tdy1fv4gNMLi5yPdXiL/Ttw05FS
+LkFikjfvSGZSO/MA==
+-----END OPENSSH PRIVATE KEY-----
diff --git a/org.eclipse.jgit.test/resources/org/eclipse/jgit/transport/ssh/id_ed25519_expensive_testpass.pub b/org.eclipse.jgit.test/resources/org/eclipse/jgit/transport/ssh/id_ed25519_expensive_testpass.pub
new file mode 100644
index 0000000000..65038b5f4c
--- /dev/null
+++ b/org.eclipse.jgit.test/resources/org/eclipse/jgit/transport/ssh/id_ed25519_expensive_testpass.pub
@@ -0,0 +1 @@
+ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEZXZRjuttLufaP8wFD/i4lYPnKk01z46Jwv/9U4mPio test
diff --git a/org.eclipse.jgit.test/src/org/eclipse/jgit/lib/Sets.java b/org.eclipse.jgit.test/src/org/eclipse/jgit/lib/Sets.java
index 5a01eae9b5..e6100e225d 100644
--- a/org.eclipse.jgit.test/src/org/eclipse/jgit/lib/Sets.java
+++ b/org.eclipse.jgit.test/src/org/eclipse/jgit/lib/Sets.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.lib;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -50,8 +51,7 @@ public class Sets {
@SafeVarargs
public static <T> Set<T> of(T... elements) {
Set<T> ret = new HashSet<>();
- for (T element : elements)
- ret.add(element);
+ ret.addAll(Arrays.asList(elements));
return ret;
}
}
diff --git a/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestBase.java b/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestBase.java
index 2f367ba51f..b8c90b2a40 100644
--- a/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestBase.java
+++ b/org.eclipse.jgit.test/src/org/eclipse/jgit/transport/ssh/SshTestBase.java
@@ -89,7 +89,9 @@ public abstract class SshTestBase extends SshTestHarness {
"id_rsa_4096_testpass", //
"id_ecdsa_256_testpass", //
"id_ecdsa_384_testpass", //
- "id_ecdsa_521_testpass" };
+ "id_ecdsa_521_testpass", //
+ "id_ed25519_testpass", //
+ "id_ed25519_expensive_testpass" };
protected File defaultCloneDir;
diff --git a/org.eclipse.jgit.test/tests.bzl b/org.eclipse.jgit.test/tests.bzl
index d2f6d705b6..f27efccc23 100644
--- a/org.eclipse.jgit.test/tests.bzl
+++ b/org.eclipse.jgit.test/tests.bzl
@@ -46,7 +46,7 @@ def tests(tests):
additional_deps = [
"//lib:jsch",
"//lib:jzlib",
- "//lib:sshd-core",
+ "//lib:sshd-osgi",
"//lib:sshd-sftp",
":sshd-helpers",
]
@@ -54,6 +54,10 @@ def tests(tests):
additional_deps = [
"//lib:mockito",
]
+ if src.endswith("TransportHttpTest.java"):
+ additional_deps = [
+ "//lib:mockito",
+ ]
if src.endswith("ArchiveCommandTest.java"):
additional_deps = [
"//lib:commons-compress",
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-invalid.txt b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-invalid.txt
new file mode 100644
index 0000000000..bbc6a7329a
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-invalid.txt
@@ -0,0 +1 @@
+some-domain /some/path1 FALSE 0 key1 value1 \ No newline at end of file
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple1.txt b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple1.txt
new file mode 100644
index 0000000000..e06b38c712
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple1.txt
@@ -0,0 +1,2 @@
+some-domain1 TRUE /some/path1 FALSE 1893499200000 key1 valueFromSimple1
+some-domain1 TRUE /some/path1 FALSE 1893499200000 key2 valueFromSimple1 \ No newline at end of file
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple2.txt b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple2.txt
new file mode 100644
index 0000000000..4bf6723fda
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-simple2.txt
@@ -0,0 +1,2 @@
+some-domain1 TRUE /some/path1 FALSE 1893499200000 key1 valueFromSimple2
+some-domain1 TRUE /some/path1 FALSE 1893499200000 key3 valueFromSimple2 \ No newline at end of file
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-empty-and-comment-lines.txt b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-empty-and-comment-lines.txt
new file mode 100644
index 0000000000..a9b8a28153
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/internal/transport/http/cookies-with-empty-and-comment-lines.txt
@@ -0,0 +1,8 @@
+# first line is a comment
+# the next cookie is supposed to be removed, because it has expired already
+some-domain1 TRUE /some/path1 FALSE 0 key1 value1
+
+# expires date is 01/01/2030 @ 12:00am (UTC)
+#HttpOnly_.some-domain2 TRUE /some/path2 TRUE 1893499200000 key2 value2
+
+some-domain3 TRUE /some/path3 FALSE 1893499200000 key3 value3 \ No newline at end of file
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java
index 139f199f7a..c9852e8b83 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java
@@ -98,7 +98,7 @@ public class CleanCommandTest extends RepositoryTestCase {
StatusCommand command = git.status();
Status status = command.call();
Set<String> files = status.getUntracked();
- assertTrue(files.size() > 0);
+ assertFalse(files.isEmpty());
// run clean
Set<String> cleanedFiles = git.clean().call();
@@ -120,7 +120,7 @@ public class CleanCommandTest extends RepositoryTestCase {
StatusCommand command = git.status();
Status status = command.call();
Set<String> files = status.getUntracked();
- assertTrue(files.size() > 0);
+ assertFalse(files.isEmpty());
// run clean
Set<String> cleanedFiles = git.clean().setCleanDirectories(true).call();
@@ -128,7 +128,7 @@ public class CleanCommandTest extends RepositoryTestCase {
status = git.status().call();
files = status.getUntracked();
- assertTrue(files.size() == 0);
+ assertTrue(files.isEmpty());
assertTrue(cleanedFiles.contains("File2.txt"));
assertTrue(cleanedFiles.contains("File3.txt"));
assertTrue(!cleanedFiles.contains("sub-noclean/File1.txt"));
@@ -143,7 +143,7 @@ public class CleanCommandTest extends RepositoryTestCase {
StatusCommand command = git.status();
Status status = command.call();
Set<String> files = status.getUntracked();
- assertTrue(files.size() > 0);
+ assertFalse(files.isEmpty());
// run clean with setPaths
Set<String> paths = new TreeSet<>();
@@ -164,7 +164,7 @@ public class CleanCommandTest extends RepositoryTestCase {
StatusCommand command = git.status();
Status status = command.call();
Set<String> files = status.getUntracked();
- assertTrue(files.size() > 0);
+ assertFalse(files.isEmpty());
// run clean
Set<String> cleanedFiles = git.clean().setDryRun(true).call();
@@ -186,7 +186,7 @@ public class CleanCommandTest extends RepositoryTestCase {
StatusCommand command = git.status();
Status status = command.call();
Set<String> files = status.getUntracked();
- assertTrue(files.size() > 0);
+ assertFalse(files.isEmpty());
// run clean
Set<String> cleanedFiles = git.clean().setDryRun(true)
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 383436c51b..2270a6a8be 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
@@ -718,6 +718,34 @@ public class CloneCommandTest extends RepositoryTestCase {
}
+ @Test
+ public void testCloneWithPullMerge() throws Exception {
+ File directory = createTempDirectory("testCloneRepository1");
+ try (Git g = Git.init().setDirectory(directory).setBare(false).call()) {
+ g.remoteAdd().setName(Constants.DEFAULT_REMOTE_NAME)
+ .setUri(new URIish(fileUri())).call();
+ PullResult result = g.pull().setRebase(false).call();
+ assertTrue(result.isSuccessful());
+ assertEquals("refs/heads/master",
+ g.getRepository().getFullBranch());
+ checkFile(new File(directory, "Test.txt"), "Hello world");
+ }
+ }
+
+ @Test
+ public void testCloneWithPullRebase() throws Exception {
+ File directory = createTempDirectory("testCloneRepository1");
+ try (Git g = Git.init().setDirectory(directory).setBare(false).call()) {
+ g.remoteAdd().setName(Constants.DEFAULT_REMOTE_NAME)
+ .setUri(new URIish(fileUri())).call();
+ PullResult result = g.pull().setRebase(true).call();
+ assertTrue(result.isSuccessful());
+ assertEquals("refs/heads/master",
+ g.getRepository().getFullBranch());
+ checkFile(new File(directory, "Test.txt"), "Hello world");
+ }
+ }
+
private String fileUri() {
return "file://" + git.getRepository().getWorkTree().getAbsolutePath();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
index e4b7ed7ba7..3bde0eb33f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
@@ -487,7 +487,7 @@ public class CommitCommandTest extends RepositoryTestCase {
}
private static String reflogComments(List<ReflogEntry> entries) {
- StringBuffer b = new StringBuffer();
+ StringBuilder b = new StringBuilder();
for (ReflogEntry e : entries) {
b.append(e.getComment()).append(";");
}
@@ -663,6 +663,54 @@ public class CommitCommandTest extends RepositoryTestCase {
}
}
+ @Test
+ public void testDeletionConflictWithAutoCrlf() throws Exception {
+ try (Git git = new Git(db)) {
+ // Commit a file with CR/LF into the index
+ FileBasedConfig config = db.getConfig();
+ config.setString("core", null, "autocrlf", "false");
+ config.save();
+ File file = writeTrashFile("file.txt", "foo\r\n");
+ git.add().addFilepattern("file.txt").call();
+ git.commit().setMessage("Initial").call();
+ // Switch to side branch
+ git.checkout().setCreateBranch(true).setName("side").call();
+ assertTrue(file.delete());
+ git.rm().addFilepattern("file.txt").call();
+ git.commit().setMessage("Side").call();
+ // Switch on autocrlf=true
+ config.setString("core", null, "autocrlf", "true");
+ config.save();
+ // Switch back to master and commit a conflict
+ git.checkout().setName("master").call();
+ writeTrashFile("file.txt", "foob\r\n");
+ git.add().addFilepattern("file.txt").call();
+ assertEquals("[file.txt, mode:100644, content:foob\r\n]",
+ indexState(CONTENT));
+ writeTrashFile("g", "file2.txt", "anything");
+ git.add().addFilepattern("g/file2.txt");
+ RevCommit master = git.commit().setMessage("Second").call();
+ // Switch to side branch again so that the deletion is "ours"
+ git.checkout().setName("side").call();
+ // Cherry pick master: produces a delete-modify conflict.
+ CherryPickResult pick = git.cherryPick().include(master).call();
+ assertEquals("Expected a cherry-pick conflict",
+ CherryPickStatus.CONFLICTING, pick.getStatus());
+ // XXX: g/file2.txt should actually be staged already, but isn't.
+ git.add().addFilepattern("g/file2.txt").call();
+ // Resolve the conflict by taking the master version
+ writeTrashFile("file.txt", "foob\r\n");
+ git.add().addFilepattern("file.txt").call();
+ git.commit().setMessage("Cherry").call();
+ // We expect this to be committed with a single LF since there is no
+ // "ours" stage.
+ assertEquals(
+ "[file.txt, mode:100644, content:foob\n]"
+ + "[g/file2.txt, mode:100644, content:anything]",
+ indexState(CONTENT));
+ }
+ }
+
private void testConflictWithAutoCrlf(String baseLf, String lf)
throws Exception {
try (Git git = new Git(db)) {
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 807079eb23..df9ae6a0fb 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
@@ -109,7 +109,7 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertNameStartsWith(c4, "3e563c5");
assertNull(describe(c1));
- assertNull(describe(c1, true));
+ assertNull(describe(c1, true, false));
assertNull(describe(c1, "a*", "b*", "c*"));
assertNull(describe(c2, "bob*"));
assertNull(describe(c2, "?ob*"));
@@ -120,7 +120,7 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertEquals("alice-t1", describe(c2, "a*", "b*", "c*"));
assertEquals("bob-t2", describe(c3));
- assertEquals("bob-t2-0-g44579eb", describe(c3, true));
+ assertEquals("bob-t2-0-g44579eb", describe(c3, true, false));
assertEquals("alice-t1-1-g44579eb", describe(c3, "alice*"));
assertEquals("alice-t1-1-g44579eb", describe(c3, "a??c?-t*"));
assertEquals("bob-t2", describe(c3, "bob*"));
@@ -129,7 +129,7 @@ public class DescribeCommandTest extends RepositoryTestCase {
// the value verified with git-describe(1)
assertEquals("bob-t2-1-g3e563c5", describe(c4));
- assertEquals("bob-t2-1-g3e563c5", describe(c4, true));
+ assertEquals("bob-t2-1-g3e563c5", describe(c4, true, false));
assertEquals("alice-t1-2-g3e563c5", describe(c4, "alice*"));
assertEquals("bob-t2-1-g3e563c5", describe(c4, "bob*"));
assertEquals("bob-t2-1-g3e563c5", describe(c4, "a*", "b*", "c*"));
@@ -137,6 +137,10 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertEquals(null, describe(c2));
assertEquals(null, describe(c3));
assertEquals(null, describe(c4));
+
+ assertEquals("3747db3", describe(c2, false, true));
+ assertEquals("44579eb", describe(c3, false, true));
+ assertEquals("3e563c5", describe(c4, false, true));
}
// test default target
@@ -169,6 +173,10 @@ public class DescribeCommandTest extends RepositoryTestCase {
if (!useAnnotatedTags && !describeUseAllTags) {
assertEquals(null, describe(c1));
assertEquals(null, describe(c2));
+
+ assertEquals("fd70040", describe(c1, false, true));
+ assertEquals("b89dead", describe(c2, false, true));
+
return;
}
@@ -203,7 +211,6 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertNotNull(describe(c1, "v1.1*", "v1.0*"));
assertNotNull(describe(c2, "v1.0*", "v1.1*"));
assertNotNull(describe(c2, "v1.1*", "v1.0*"));
-
}
}
@@ -236,9 +243,11 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertEquals("2 commits: c4 and c3", "t-2-g119892b", describe(c4));
} else {
assertEquals(null, describe(c4));
+
+ assertEquals("119892b", describe(c4, false, true));
}
assertNull(describe(c3));
- assertNull(describe(c3, true));
+ assertNull(describe(c3, true, false));
}
private void branch(String name, ObjectId base) throws GitAPIException {
@@ -280,6 +289,9 @@ public class DescribeCommandTest extends RepositoryTestCase {
} else {
assertEquals(null, describe(c4));
assertEquals(null, describe(c3));
+
+ assertEquals("119892b", describe(c4, false, true));
+ assertEquals("0244e7f", describe(c3, false, true));
}
}
@@ -369,6 +381,8 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertEquals("t1-3-gbb389a4", describe(c4));
} else {
assertEquals(null, describe(c4));
+
+ assertEquals("bb389a4", describe(c4, false, true));
}
}
@@ -402,6 +416,25 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertEquals("t2-4-gbb389a4", describe(c4));
} else {
assertEquals(null, describe(c4));
+
+ assertEquals("bb389a4", describe(c4, false, true));
+ }
+ }
+
+ @Test
+ public void globMatchWithSlashes() throws Exception {
+ ObjectId c1 = modify("aaa");
+ tag("a/b/version");
+ ObjectId c2 = modify("bbb");
+ tag("a/b/version2");
+ if (useAnnotatedTags || describeUseAllTags) {
+ assertEquals("a/b/version", describe(c1, "*/version*"));
+ assertEquals("a/b/version2", describe(c2, "*/version*"));
+ } else {
+ assertNull(describe(c1));
+ assertNull(describe(c1, "*/version*"));
+ assertNull(describe(c2));
+ assertNull(describe(c2, "*/version*"));
}
}
@@ -434,14 +467,14 @@ public class DescribeCommandTest extends RepositoryTestCase {
}
}
- private String describe(ObjectId c1, boolean longDesc)
+ private String describe(ObjectId c1, boolean longDesc, boolean always)
throws GitAPIException, IOException {
return git.describe().setTarget(c1).setTags(describeUseAllTags)
- .setLong(longDesc).call();
+ .setLong(longDesc).setAlways(always).call();
}
private String describe(ObjectId c1) throws GitAPIException, IOException {
- return describe(c1, false);
+ return describe(c1, false, false);
}
private String describe(ObjectId c1, String... patterns) throws Exception {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
index 9461c42500..2fd378842f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
@@ -346,14 +346,11 @@ public class PullCommandTest extends RepositoryTestCase {
@Test
/** global rebase config should be respected */
public void testPullWithRebasePreserve1Config() throws Exception {
- Callable<PullResult> setup = new Callable<PullResult>() {
- @Override
- public PullResult call() throws Exception {
- StoredConfig config = dbTarget.getConfig();
- config.setString("pull", null, "rebase", "preserve");
- config.save();
- return target.pull().call();
- }
+ Callable<PullResult> setup = () -> {
+ StoredConfig config = dbTarget.getConfig();
+ config.setString("pull", null, "rebase", "preserve");
+ config.save();
+ return target.pull().call();
};
doTestPullWithRebase(setup, TestPullMode.REBASE_PREASERVE);
}
@@ -361,15 +358,12 @@ public class PullCommandTest extends RepositoryTestCase {
@Test
/** the branch-local config should win over the global config */
public void testPullWithRebasePreserveConfig2() throws Exception {
- Callable<PullResult> setup = new Callable<PullResult>() {
- @Override
- public PullResult call() throws Exception {
- StoredConfig config = dbTarget.getConfig();
- config.setString("pull", null, "rebase", "false");
- config.setString("branch", "master", "rebase", "preserve");
- config.save();
- return target.pull().call();
- }
+ Callable<PullResult> setup = () -> {
+ StoredConfig config = dbTarget.getConfig();
+ config.setString("pull", null, "rebase", "false");
+ config.setString("branch", "master", "rebase", "preserve");
+ config.save();
+ return target.pull().call();
};
doTestPullWithRebase(setup, TestPullMode.REBASE_PREASERVE);
}
@@ -377,14 +371,11 @@ public class PullCommandTest extends RepositoryTestCase {
@Test
/** the branch-local config should be respected */
public void testPullWithRebasePreserveConfig3() throws Exception {
- Callable<PullResult> setup = new Callable<PullResult>() {
- @Override
- public PullResult call() throws Exception {
- StoredConfig config = dbTarget.getConfig();
- config.setString("branch", "master", "rebase", "preserve");
- config.save();
- return target.pull().call();
- }
+ Callable<PullResult> setup = () -> {
+ StoredConfig config = dbTarget.getConfig();
+ config.setString("branch", "master", "rebase", "preserve");
+ config.save();
+ return target.pull().call();
};
doTestPullWithRebase(setup, TestPullMode.REBASE_PREASERVE);
}
@@ -392,14 +383,11 @@ public class PullCommandTest extends RepositoryTestCase {
@Test
/** global rebase config should be respected */
public void testPullWithRebaseConfig1() throws Exception {
- Callable<PullResult> setup = new Callable<PullResult>() {
- @Override
- public PullResult call() throws Exception {
- StoredConfig config = dbTarget.getConfig();
- config.setString("pull", null, "rebase", "true");
- config.save();
- return target.pull().call();
- }
+ Callable<PullResult> setup = () -> {
+ StoredConfig config = dbTarget.getConfig();
+ config.setString("pull", null, "rebase", "true");
+ config.save();
+ return target.pull().call();
};
doTestPullWithRebase(setup, TestPullMode.REBASE);
}
@@ -407,15 +395,12 @@ public class PullCommandTest extends RepositoryTestCase {
@Test
/** the branch-local config should win over the global config */
public void testPullWithRebaseConfig2() throws Exception {
- Callable<PullResult> setup = new Callable<PullResult>() {
- @Override
- public PullResult call() throws Exception {
- StoredConfig config = dbTarget.getConfig();
- config.setString("pull", null, "rebase", "preserve");
- config.setString("branch", "master", "rebase", "true");
- config.save();
- return target.pull().call();
- }
+ Callable<PullResult> setup = () -> {
+ StoredConfig config = dbTarget.getConfig();
+ config.setString("pull", null, "rebase", "preserve");
+ config.setString("branch", "master", "rebase", "true");
+ config.save();
+ return target.pull().call();
};
doTestPullWithRebase(setup, TestPullMode.REBASE);
}
@@ -423,14 +408,11 @@ public class PullCommandTest extends RepositoryTestCase {
@Test
/** the branch-local config should be respected */
public void testPullWithRebaseConfig3() throws Exception {
- Callable<PullResult> setup = new Callable<PullResult>() {
- @Override
- public PullResult call() throws Exception {
- StoredConfig config = dbTarget.getConfig();
- config.setString("branch", "master", "rebase", "true");
- config.save();
- return target.pull().call();
- }
+ Callable<PullResult> setup = () -> {
+ StoredConfig config = dbTarget.getConfig();
+ config.setString("branch", "master", "rebase", "true");
+ config.save();
+ return target.pull().call();
};
doTestPullWithRebase(setup, TestPullMode.REBASE);
}
@@ -438,27 +420,19 @@ public class PullCommandTest extends RepositoryTestCase {
@Test
/** without config it should merge */
public void testPullWithoutConfig() throws Exception {
- Callable<PullResult> setup = new Callable<PullResult>() {
- @Override
- public PullResult call() throws Exception {
- return target.pull().call();
- }
- };
+ Callable<PullResult> setup = target.pull()::call;
doTestPullWithRebase(setup, TestPullMode.MERGE);
}
@Test
/** the branch local config should win over the global config */
public void testPullWithMergeConfig() throws Exception {
- Callable<PullResult> setup = new Callable<PullResult>() {
- @Override
- public PullResult call() throws Exception {
- StoredConfig config = dbTarget.getConfig();
- config.setString("pull", null, "rebase", "true");
- config.setString("branch", "master", "rebase", "false");
- config.save();
- return target.pull().call();
- }
+ Callable<PullResult> setup = () -> {
+ StoredConfig config = dbTarget.getConfig();
+ config.setString("pull", null, "rebase", "true");
+ config.setString("branch", "master", "rebase", "false");
+ config.save();
+ return target.pull().call();
};
doTestPullWithRebase(setup, TestPullMode.MERGE);
}
@@ -466,14 +440,11 @@ public class PullCommandTest extends RepositoryTestCase {
@Test
/** the branch local config should win over the global config */
public void testPullWithMergeConfig2() throws Exception {
- Callable<PullResult> setup = new Callable<PullResult>() {
- @Override
- public PullResult call() throws Exception {
- StoredConfig config = dbTarget.getConfig();
- config.setString("pull", null, "rebase", "false");
- config.save();
- return target.pull().call();
- }
+ Callable<PullResult> setup = () -> {
+ StoredConfig config = dbTarget.getConfig();
+ config.setString("pull", null, "rebase", "false");
+ config.save();
+ return target.pull().call();
};
doTestPullWithRebase(setup, TestPullMode.MERGE);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java
index 1d9cd78140..d6aead4a52 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/TreeWalkAttributeTest.java
@@ -49,6 +49,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -854,8 +855,7 @@ public class TreeWalkAttributeTest extends RepositoryTestCase {
static Set<Attribute> asSet(Attribute... attrs) {
HashSet<Attribute> result = new HashSet<>();
- for (Attribute attr : attrs)
- result.add(attr);
+ result.addAll(Arrays.asList(attrs));
return result;
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
index 014406eb98..972dc60156 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
@@ -205,8 +205,9 @@ public class DirCacheBasicTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
assertFalse(dc.hasUnmergedPaths());
@@ -229,8 +230,9 @@ public class DirCacheBasicTest extends RepositoryTestCase {
ents[2].setFileMode(FileMode.REGULAR_FILE);
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
assertTrue(dc.hasUnmergedPaths());
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
index 3598f3a4a1..6020a748aa 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
@@ -71,8 +71,9 @@ public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
}
{
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java
index 50753ae1bd..cdf86f00a9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java
@@ -211,12 +211,8 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
boolean receivedEvent = false;
DirCache dc = db.lockDirCache();
- IndexChangedListener listener = new IndexChangedListener() {
-
- @Override
- public void onIndexChanged(IndexChangedEvent event) {
- throw new ReceivedEventMarkerException();
- }
+ IndexChangedListener listener = (IndexChangedEvent event) -> {
+ throw new ReceivedEventMarkerException();
};
ListenerList l = db.getListenerList();
@@ -239,12 +235,8 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
// do the same again, as this doesn't change index compared to first
// round we should get no event this time
dc = db.lockDirCache();
- listener = new IndexChangedListener() {
-
- @Override
- public void onIndexChanged(IndexChangedEvent event) {
- throw new ReceivedEventMarkerException();
- }
+ listener = (IndexChangedEvent event) -> {
+ throw new ReceivedEventMarkerException();
};
l = db.getListenerList();
@@ -302,8 +294,9 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
assertEquals(paths.length, dc.getEntryCount());
@@ -352,8 +345,9 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
}
{
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
}
assertEquals(paths.length, dc.getEntryCount());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java
index 3b8c6ee7b4..7fc28018f6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheFindTest.java
@@ -66,8 +66,9 @@ public class DirCacheFindTest extends RepositoryTestCase {
final int aLast = 3;
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
assertEquals(paths.length, dc.getEntryCount());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
index 82565fceec..bc99aeef2f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
@@ -94,8 +94,9 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
final DirCacheIterator i = new DirCacheIterator(dc);
@@ -121,8 +122,9 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
final DirCacheIterator i = new DirCacheIterator(dc);
@@ -154,8 +156,9 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
final String[] expPaths = { "a-", "a", "a0b" };
@@ -200,8 +203,9 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
final DirCacheIterator i = new DirCacheIterator(dc);
@@ -236,8 +240,9 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
try (TreeWalk tw = new TreeWalk(db)) {
@@ -271,8 +276,9 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
DirCacheIterator dci = new DirCacheIterator(dc);
@@ -365,8 +371,9 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
DirCacheIterator dci = new DirCacheIterator(dc);
@@ -398,8 +405,9 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
try (TreeWalk tw = new TreeWalk(db)) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java
index f662e2660c..513db75323 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheTreeTest.java
@@ -102,8 +102,9 @@ public class DirCacheTreeTest extends RepositoryTestCase {
final int aLast = 3;
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
assertNull(dc.getCacheTree(false));
@@ -142,8 +143,9 @@ public class DirCacheTreeTest extends RepositoryTestCase {
final int acLast = 3;
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.finish();
assertNull(dc.getCacheTree(false));
@@ -198,8 +200,9 @@ public class DirCacheTreeTest extends RepositoryTestCase {
}
final DirCacheBuilder b = dc.builder();
- for (int i = 0; i < ents.length; i++)
- b.add(ents[i]);
+ for (DirCacheEntry ent : ents) {
+ b.add(ent);
+ }
b.commit();
DirCache read = db.readDirCache();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java
index 3624100671..b6f312dfec 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/events/ConfigChangeEventTest.java
@@ -54,12 +54,9 @@ public class ConfigChangeEventTest extends RepositoryTestCase {
@Test
public void testFileRepository_ChangeEventsOnlyOnSave() throws Exception {
final ConfigChangedEvent[] events = new ConfigChangedEvent[1];
- db.getListenerList().addConfigChangedListener(
- new ConfigChangedListener() {
- @Override
- public void onConfigChanged(ConfigChangedEvent event) {
- events[0] = event;
- }
+ db.getListenerList()
+ .addConfigChangedListener((ConfigChangedEvent event) -> {
+ events[0] = event;
});
FileBasedConfig config = db.getConfig();
assertNull(events[0]);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
index bfa30d5b4b..5a5ae1d7a3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
@@ -976,7 +976,7 @@ public class DfsGarbageCollectorTest {
rw.markStart(rw.parseCommit(ref.getObjectId()));
}
for (RevCommit next; (next = rw.next()) != null;) {
- if (AnyObjectId.equals(next, id)) {
+ if (AnyObjectId.isEqual(next, id)) {
return true;
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/InMemoryRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/InMemoryRepositoryTest.java
new file mode 100644
index 0000000000..bab6110ce6
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/InMemoryRepositoryTest.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2019, Google LLC.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.internal.storage.dfs;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.eclipse.jgit.junit.TestRepository;
+import org.eclipse.jgit.lib.ObjectIdRef;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.Ref.Storage;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevTag;
+import org.junit.Test;
+
+public class InMemoryRepositoryTest {
+
+ @Test
+ public void keepUpdateIndexPeelingTag() throws Exception {
+ InMemoryRepository repo = new InMemoryRepository(
+ new DfsRepositoryDescription());
+ try (TestRepository<InMemoryRepository> git = new TestRepository<>(
+ repo)) {
+ RevCommit commit = git.branch("master").commit()
+ .message("first commit").create();
+ RevTag tag = git.tag("v0.1", commit);
+ git.update("refs/tags/v0.1", tag);
+
+ Ref unpeeledTag = new ObjectIdRef.Unpeeled(Storage.LOOSE,
+ "refs/tags/v0.1", tag.getId(), 1000);
+
+ Ref peeledTag = repo.getRefDatabase().peel(unpeeledTag);
+ assertTrue(peeledTag instanceof ObjectIdRef.PeeledTag);
+ assertEquals(1000, peeledTag.getUpdateIndex());
+ }
+ }
+
+ @Test
+ public void keepUpdateIndexPeelingNonTag() throws Exception {
+ InMemoryRepository repo = new InMemoryRepository(
+ new DfsRepositoryDescription());
+ try (TestRepository<InMemoryRepository> git = new TestRepository<>(
+ repo)) {
+ RevCommit commit = git.branch("master").commit()
+ .message("first commit").create();
+
+ Ref unpeeledRef = new ObjectIdRef.Unpeeled(Storage.LOOSE,
+ "refs/heads/master", commit.getId(), 1000);
+ Ref peeledRef = repo.getRefDatabase().peel(unpeeledRef);
+ assertTrue(peeledRef instanceof ObjectIdRef.PeeledNonTag);
+ assertEquals(1000, peeledRef.getUpdateIndex());
+ }
+ }
+
+ @Test
+ public void sha1ToTip_ref() throws Exception {
+ InMemoryRepository repo = new InMemoryRepository(
+ new DfsRepositoryDescription());
+ try (TestRepository<InMemoryRepository> git = new TestRepository<>(
+ repo)) {
+ RevCommit commit = git.branch("master").commit()
+ .message("first commit").create();
+
+ Set<Ref> tipsWithSha1 = repo.getRefDatabase()
+ .getTipsWithSha1(commit.getId());
+ assertEquals(1, tipsWithSha1.size());
+ Ref ref = tipsWithSha1.iterator().next();
+ assertEquals(ref.getName(), "refs/heads/master");
+ assertEquals(commit.getId(), ref.getObjectId());
+ }
+ }
+
+ @Test
+ public void sha1ToTip_annotatedTag() throws Exception {
+ InMemoryRepository repo = new InMemoryRepository(
+ new DfsRepositoryDescription());
+ try (TestRepository<InMemoryRepository> git = new TestRepository<>(
+ repo)) {
+ RevCommit commit = git.commit()
+ .message("first commit").create();
+ RevTag tagObj = git.tag("v0.1", commit);
+ git.update("refs/tags/v0.1", tagObj);
+ Set<Ref> tipsWithSha1 = repo.getRefDatabase()
+ .getTipsWithSha1(commit.getId());
+ assertEquals(1, tipsWithSha1.size());
+ Ref ref = tipsWithSha1.iterator().next();
+ assertEquals(ref.getName(), "refs/tags/v0.1");
+ assertEquals(commit.getId(), ref.getPeeledObjectId());
+ }
+ }
+
+ @Test
+ public void sha1ToTip_tag() throws Exception {
+ InMemoryRepository repo = new InMemoryRepository(
+ new DfsRepositoryDescription());
+ try (TestRepository<InMemoryRepository> git = new TestRepository<>(
+ repo)) {
+ RevCommit commit = git.commit().message("first commit").create();
+ git.update("refs/tags/v0.2", commit);
+ Set<Ref> tipsWithSha1 = repo.getRefDatabase()
+ .getTipsWithSha1(commit.getId());
+ assertEquals(1, tipsWithSha1.size());
+ Ref ref = tipsWithSha1.iterator().next();
+ assertEquals(ref.getName(), "refs/tags/v0.2");
+ assertEquals(commit.getId(), ref.getObjectId());
+ }
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java
index 3c4b8cf4bc..501b788f89 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BatchRefUpdateTest.java
@@ -938,6 +938,7 @@ public class BatchRefUpdateTest extends LocalDiskRepositoryTestCase {
REJECTED_MISSING_OBJECT(ReceiveCommand.Result.REJECTED_MISSING_OBJECT),
TRANSACTION_ABORTED(ReceiveCommand::isTransactionAborted);
+ @SuppressWarnings("ImmutableEnumChecker")
final Predicate<? super ReceiveCommand> p;
private Result(Predicate<? super ReceiveCommand> p) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java
index 05f7c65fa8..9e7d41a693 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java
@@ -239,20 +239,15 @@ public class GcConcurrentTest extends GcTestCase {
SampleDataRepositoryTestCase.copyCGitTestPacks(repo);
ExecutorService executor = Executors.newSingleThreadExecutor();
final CountDownLatch latch = new CountDownLatch(1);
- Future<Collection<PackFile>> result = executor
- .submit(new Callable<Collection<PackFile>>() {
-
- @Override
- public Collection<PackFile> call() throws Exception {
- long start = System.currentTimeMillis();
- System.out.println("starting gc");
- latch.countDown();
- Collection<PackFile> r = gc.gc();
- System.out.println("gc took "
- + (System.currentTimeMillis() - start) + " ms");
- return r;
- }
- });
+ Future<Collection<PackFile>> result = executor.submit(() -> {
+ long start = System.currentTimeMillis();
+ System.out.println("starting gc");
+ latch.countDown();
+ Collection<PackFile> r = gc.gc();
+ System.out.println(
+ "gc took " + (System.currentTimeMillis() - start) + " ms");
+ return r;
+ });
try {
latch.await();
Thread.sleep(5);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java
index c43bdbd298..54708da03c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java
@@ -155,41 +155,34 @@ public class GcPackRefsTest extends GcTestCase {
final CyclicBarrier packRefsDone = new CyclicBarrier(2);
ExecutorService pool = Executors.newFixedThreadPool(2);
try {
- Future<Result> result = pool.submit(new Callable<Result>() {
-
- @Override
- public Result call() throws Exception {
- RefUpdate update = new RefDirectoryUpdate(
- (RefDirectory) repo.getRefDatabase(),
- repo.exactRef("refs/tags/t")) {
- @Override
- public boolean isForceUpdate() {
- try {
- refUpdateLockedRef.await();
- packRefsDone.await();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- } catch (BrokenBarrierException e) {
- Thread.currentThread().interrupt();
- }
- return super.isForceUpdate();
+ Future<Result> result = pool.submit(() -> {
+ RefUpdate update = new RefDirectoryUpdate(
+ (RefDirectory) repo.getRefDatabase(),
+ repo.exactRef("refs/tags/t")) {
+ @Override
+ public boolean isForceUpdate() {
+ try {
+ refUpdateLockedRef.await();
+ packRefsDone.await();
+ } catch (InterruptedException
+ | BrokenBarrierException e) {
+ Thread.currentThread().interrupt();
}
- };
- update.setForceUpdate(true);
- update.setNewObjectId(b);
- return update.update();
- }
+ return super.isForceUpdate();
+ }
+ };
+ update.setForceUpdate(true);
+ update.setNewObjectId(b);
+ return update.update();
});
- pool.submit(new Callable<Void>() {
- @Override
- public Void call() throws Exception {
- refUpdateLockedRef.await();
- gc.packRefs();
- packRefsDone.await();
- return null;
- }
+ Future<Result> result2 = pool.submit(() -> {
+ refUpdateLockedRef.await();
+ gc.packRefs();
+ packRefsDone.await();
+ return null;
});
+ assertNull(result2.get());
assertSame(result.get(), Result.FORCED);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
index 9d47c7e3bc..97c56385bd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
@@ -47,7 +47,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.File;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.MessageFormat;
@@ -169,12 +168,8 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
// 2500ms
Thread.sleep(2600);
- File[] ret = packsFolder.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".pack");
- }
- });
+ File[] ret = packsFolder.listFiles(
+ (File dir, String name) -> name.endsWith(".pack"));
assertTrue(ret != null && ret.length == 1);
FS fs = db.getFS();
Assume.assumeTrue(fs.lastModifiedInstant(tmpFile)
@@ -224,12 +219,8 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
private Collection<Callable<ObjectId>> blobInsertersForTheSameFanOutDir(
final ObjectDirectory dir) {
- Callable<ObjectId> callable = new Callable<ObjectId>() {
- @Override
- public ObjectId call() throws Exception {
- return dir.newInserter().insert(Constants.OBJ_BLOB, new byte[0]);
- }
- };
+ Callable<ObjectId> callable = () -> dir.newInserter()
+ .insert(Constants.OBJ_BLOB, new byte[0]);
return Collections.nCopies(4, callable);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
index ca4486256b..5d0a7e2a0b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
@@ -60,7 +60,6 @@ import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -881,12 +880,8 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
for (MutableEntry me : pack) {
entries.add(me.cloneEntry());
}
- Collections.sort(entries, new Comparator<PackIndex.MutableEntry>() {
- @Override
- public int compare(MutableEntry o1, MutableEntry o2) {
- return Long.signum(o1.getOffset() - o2.getOffset());
- }
- });
+ Collections.sort(entries, (MutableEntry o1, MutableEntry o2) -> Long
+ .signum(o1.getOffset() - o2.getOffset()));
int i = 0;
for (MutableEntry me : entries) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
index 2357edf6cb..d8e16858e5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
@@ -71,7 +71,6 @@ import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jgit.errors.LockFailedException;
import org.eclipse.jgit.events.ListenerHandle;
import org.eclipse.jgit.events.RefsChangedEvent;
-import org.eclipse.jgit.events.RefsChangedListener;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.junit.Repeat;
import org.eclipse.jgit.junit.TestRepository;
@@ -573,12 +572,8 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
final int[] count = new int[1];
ListenerHandle listener = Repository.getGlobalListenerList()
- .addRefsChangedListener(new RefsChangedListener() {
-
- @Override
- public void onRefsChanged(RefsChangedEvent event) {
- count[0]++;
- }
+ .addRefsChangedListener((RefsChangedEvent event) -> {
+ count[0]++;
});
refs = refdir.getRefs(RefDatabase.ALL);
@@ -1320,19 +1315,15 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
final AtomicReference<StackOverflowError> error = new AtomicReference<>();
final AtomicReference<IOException> exception = new AtomicReference<>();
final AtomicInteger changeCount = new AtomicInteger();
- newRepo.getListenerList().addRefsChangedListener(
- new RefsChangedListener() {
-
- @Override
- public void onRefsChanged(RefsChangedEvent event) {
- try {
- refDb.getRefsByPrefix("ref");
- changeCount.incrementAndGet();
- } catch (StackOverflowError soe) {
- error.set(soe);
- } catch (IOException ioe) {
- exception.set(ioe);
- }
+ newRepo.getListenerList()
+ .addRefsChangedListener((RefsChangedEvent event) -> {
+ try {
+ refDb.getRefsByPrefix("ref");
+ changeCount.incrementAndGet();
+ } catch (StackOverflowError soe) {
+ error.set(soe);
+ } catch (IOException ioe) {
+ exception.set(ioe);
}
});
refDb.getRefsByPrefix("ref");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java
index 8ef21e6da7..c3f5baa67b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java
@@ -633,35 +633,23 @@ public class RefTreeDatabaseTest {
private void symref(String name, String dst)
throws IOException {
- commit(new Function() {
- @Override
- public boolean apply(ObjectReader reader, RefTree tree)
- throws IOException {
- Ref old = tree.exactRef(reader, name);
- Command n = new Command(
- old,
- new SymbolicRef(
- name,
- new ObjectIdRef.Unpeeled(Ref.Storage.NEW, dst, null)));
- return tree.apply(Collections.singleton(n));
- }
+ commit((ObjectReader reader, RefTree tree) -> {
+ Ref old = tree.exactRef(reader, name);
+ Command n = new Command(old, new SymbolicRef(name,
+ new ObjectIdRef.Unpeeled(Ref.Storage.NEW, dst, null)));
+ return tree.apply(Collections.singleton(n));
});
}
private void update(String name, ObjectId id)
throws IOException {
- commit(new Function() {
- @Override
- public boolean apply(ObjectReader reader, RefTree tree)
- throws IOException {
- Ref old = tree.exactRef(reader, name);
- Command n;
- try (RevWalk rw = new RevWalk(repo)) {
- n = new Command(old,
- Command.toRef(rw, id, null, name, true));
- }
- return tree.apply(Collections.singleton(n));
+ commit((ObjectReader reader, RefTree tree) -> {
+ Ref old = tree.exactRef(reader, name);
+ Command n;
+ try (RevWalk rw = new RevWalk(repo)) {
+ n = new Command(old, Command.toRef(rw, id, null, name, true));
}
+ return tree.apply(Collections.singleton(n));
});
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java
new file mode 100644
index 0000000000..0a3f89e238
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/http/NetscapeCookieFileTest.java
@@ -0,0 +1,339 @@
+/*
+ * Copyright (C) 2018, Konrad Windszus <konrad_w@gmx.de>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.internal.transport.http;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.net.HttpCookie;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.eclipse.jgit.internal.storage.file.LockFile;
+import org.eclipse.jgit.internal.transport.http.NetscapeCookieFile;
+import org.eclipse.jgit.util.http.HttpCookiesMatcher;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class NetscapeCookieFileTest {
+
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
+
+ private Path tmpFile;
+
+ private URL baseUrl;
+
+ /**
+ * This is the expiration date that is used in the test cookie files
+ */
+ private static long JAN_01_2030_NOON = Instant
+ .parse("2030-01-01T12:00:00.000Z").toEpochMilli();
+
+ @Before
+ public void setUp() throws IOException {
+ // this will not only return a new file name but also create new empty
+ // file!
+ tmpFile = folder.newFile().toPath();
+ baseUrl = new URL("http://domain.com/my/path");
+ }
+
+ @Test
+ public void testMergeCookies() {
+ Set<HttpCookie> cookieSet1 = new LinkedHashSet<>();
+ HttpCookie cookie = new HttpCookie("key1", "valueFromSet1");
+ cookieSet1.add(cookie);
+ cookie = new HttpCookie("key2", "valueFromSet1");
+ cookieSet1.add(cookie);
+
+ Set<HttpCookie> cookieSet2 = new LinkedHashSet<>();
+ cookie = new HttpCookie("key1", "valueFromSet2");
+ cookieSet2.add(cookie);
+ cookie = new HttpCookie("key3", "valueFromSet2");
+ cookieSet2.add(cookie);
+
+ Set<HttpCookie> cookiesExpectedMergedSet = new LinkedHashSet<>();
+ cookie = new HttpCookie("key1", "valueFromSet1");
+ cookiesExpectedMergedSet.add(cookie);
+ cookie = new HttpCookie("key2", "valueFromSet1");
+ cookiesExpectedMergedSet.add(cookie);
+ cookie = new HttpCookie("key3", "valueFromSet2");
+ cookiesExpectedMergedSet.add(cookie);
+
+ Assert.assertThat(
+ NetscapeCookieFile.mergeCookies(cookieSet1, cookieSet2),
+ HttpCookiesMatcher.containsInOrder(cookiesExpectedMergedSet));
+
+ Assert.assertThat(NetscapeCookieFile.mergeCookies(cookieSet1, null),
+ HttpCookiesMatcher.containsInOrder(cookieSet1));
+ }
+
+ @Test
+ public void testWriteToNewFile() throws IOException {
+ Set<HttpCookie> cookies = new LinkedHashSet<>();
+ cookies.add(new HttpCookie("key1", "value"));
+ // first cookie is a session cookie (and should be ignored)
+
+ HttpCookie cookie = new HttpCookie("key2", "value");
+ cookie.setSecure(true);
+ cookie.setDomain("mydomain.com");
+ cookie.setPath("/");
+ cookie.setMaxAge(1000);
+ cookies.add(cookie);
+ Date creationDate = new Date();
+ try (Writer writer = Files.newBufferedWriter(tmpFile,
+ StandardCharsets.US_ASCII)) {
+ NetscapeCookieFile.write(writer, cookies, baseUrl, creationDate);
+ }
+
+ String expectedExpiration = String
+ .valueOf(creationDate.getTime() + (cookie.getMaxAge() * 1000));
+
+ Assert.assertThat(
+ Files.readAllLines(tmpFile, StandardCharsets.US_ASCII),
+ CoreMatchers
+ .equalTo(Arrays.asList("mydomain.com\tTRUE\t/\tTRUE\t"
+ + expectedExpiration + "\tkey2\tvalue")));
+ }
+
+ @Test
+ public void testWriteToExistingFile() throws IOException {
+ try (InputStream input = this.getClass()
+ .getResourceAsStream("cookies-simple1.txt")) {
+ Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING);
+ }
+
+ Set<HttpCookie> cookies = new LinkedHashSet<>();
+ HttpCookie cookie = new HttpCookie("key2", "value2");
+ cookie.setMaxAge(1000);
+ cookies.add(cookie);
+ Date creationDate = new Date();
+ try (Writer writer = Files.newBufferedWriter(tmpFile,
+ StandardCharsets.US_ASCII)) {
+ NetscapeCookieFile.write(writer, cookies, baseUrl, creationDate);
+ }
+ String expectedExpiration = String
+ .valueOf(creationDate.getTime() + (cookie.getMaxAge() * 1000));
+
+ Assert.assertThat(
+ Files.readAllLines(tmpFile, StandardCharsets.US_ASCII),
+ CoreMatchers.equalTo(
+ Arrays.asList("domain.com\tTRUE\t/my/path\tFALSE\t"
+ + expectedExpiration + "\tkey2\tvalue2")));
+ }
+
+ @Test(expected = IOException.class)
+ public void testWriteWhileSomeoneIsHoldingTheLock()
+ throws IllegalArgumentException, IOException, InterruptedException {
+ try (InputStream input = this.getClass()
+ .getResourceAsStream("cookies-simple1.txt")) {
+ Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING);
+ }
+ NetscapeCookieFile cookieFile = new NetscapeCookieFile(tmpFile);
+ // now imitate another process/thread holding the lock file
+ LockFile lockFile = new LockFile(tmpFile.toFile());
+ try {
+ Assert.assertTrue("Could not acquire lock", lockFile.lock());
+ cookieFile.write(baseUrl);
+ } finally {
+ lockFile.unlock();
+ }
+ }
+
+ @Test
+ public void testWriteAfterAnotherJgitProcessModifiedTheFile()
+ throws IOException, InterruptedException {
+ try (InputStream input = this.getClass()
+ .getResourceAsStream("cookies-simple1.txt")) {
+ Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING);
+ }
+ NetscapeCookieFile cookieFile = new NetscapeCookieFile(tmpFile);
+ cookieFile.getCookies(true);
+ // now modify file externally
+ try (InputStream input = this.getClass()
+ .getResourceAsStream("cookies-simple2.txt")) {
+ Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING);
+ }
+ // now try to write
+ cookieFile.write(baseUrl);
+
+ // validate that the external changes are there as well
+ // due to rounding errors (conversion from ms to sec to ms)
+ // the expiration date might not be exact
+ List<String> lines = Files.readAllLines(tmpFile,
+ StandardCharsets.US_ASCII);
+
+ Assert.assertEquals("Expected 3 lines", 3, lines.size());
+ assertStringMatchesPatternWithInexactNumber(lines.get(0),
+ "some-domain1\tTRUE\t/some/path1\tFALSE\t(\\d*)\tkey1\tvalueFromSimple2",
+ JAN_01_2030_NOON, 1000);
+ assertStringMatchesPatternWithInexactNumber(lines.get(1),
+ "some-domain1\tTRUE\t/some/path1\tFALSE\t(\\d*)\tkey3\tvalueFromSimple2",
+ JAN_01_2030_NOON, 1000);
+ assertStringMatchesPatternWithInexactNumber(lines.get(2),
+ "some-domain1\tTRUE\t/some/path1\tFALSE\t(\\d*)\tkey2\tvalueFromSimple1",
+ JAN_01_2030_NOON, 1000);
+ }
+
+ @SuppressWarnings("boxing")
+ private static final void assertStringMatchesPatternWithInexactNumber(
+ String string, String pattern, long expectedNumericValue,
+ long delta) {
+ java.util.regex.Matcher matcher = Pattern.compile(pattern)
+ .matcher(string);
+ Assert.assertTrue("Given string '" + string + "' does not match '"
+ + pattern + "'", matcher.matches());
+ // extract numeric value
+ Long actualNumericValue = Long.decode(matcher.group(1));
+
+ Assert.assertTrue(
+ "Value is supposed to be close to " + expectedNumericValue
+ + " but is " + actualNumericValue + ".",
+ Math.abs(expectedNumericValue - actualNumericValue) <= delta);
+ }
+
+ @Test
+ public void testWriteAndReadCycle() throws IOException {
+ Set<HttpCookie> cookies = new LinkedHashSet<>();
+
+ HttpCookie cookie = new HttpCookie("key1", "value1");
+ cookie.setPath("/some/path1");
+ cookie.setDomain("some-domain1");
+ cookie.setMaxAge(1000);
+ cookies.add(cookie);
+ cookie = new HttpCookie("key2", "value2");
+ cookie.setSecure(true);
+ cookie.setPath("/some/path2");
+ cookie.setDomain("some-domain2");
+ cookie.setMaxAge(1000);
+ cookie.setHttpOnly(true);
+ cookies.add(cookie);
+
+ Date creationDate = new Date();
+
+ try (Writer writer = Files.newBufferedWriter(tmpFile,
+ StandardCharsets.US_ASCII)) {
+ NetscapeCookieFile.write(writer, cookies, baseUrl, creationDate);
+ }
+ Set<HttpCookie> actualCookies = new NetscapeCookieFile(tmpFile,
+ creationDate).getCookies(true);
+ Assert.assertThat(actualCookies,
+ HttpCookiesMatcher.containsInOrder(cookies));
+ }
+
+ @Test
+ public void testReadAndWriteCycle() throws IOException {
+ try (InputStream input = this.getClass()
+ .getResourceAsStream("cookies-simple1.txt")) {
+ Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING);
+ }
+ // round up to the next second (to prevent rounding errors)
+ Date creationDate = new Date(
+ (System.currentTimeMillis() / 1000) * 1000);
+ Set<HttpCookie> cookies = new NetscapeCookieFile(tmpFile, creationDate)
+ .getCookies(true);
+ Path tmpFile2 = folder.newFile().toPath();
+ try (Writer writer = Files.newBufferedWriter(tmpFile2,
+ StandardCharsets.US_ASCII)) {
+ NetscapeCookieFile.write(writer, cookies, baseUrl, creationDate);
+ }
+ // compare original file with newly written one, they should not differ
+ Assert.assertEquals(Files.readAllLines(tmpFile),
+ Files.readAllLines(tmpFile2));
+ }
+
+ @Test
+ public void testReadWithEmptyAndCommentLines() throws IOException {
+ try (InputStream input = this.getClass().getResourceAsStream(
+ "cookies-with-empty-and-comment-lines.txt")) {
+ Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING);
+ }
+
+ Date creationDate = new Date();
+ Set<HttpCookie> cookies = new LinkedHashSet<>();
+
+ HttpCookie cookie = new HttpCookie("key2", "value2");
+ cookie.setDomain("some-domain2");
+ cookie.setPath("/some/path2");
+ cookie.setMaxAge((JAN_01_2030_NOON - creationDate.getTime()) / 1000);
+ cookie.setSecure(true);
+ cookie.setHttpOnly(true);
+ cookies.add(cookie);
+
+ cookie = new HttpCookie("key3", "value3");
+ cookie.setDomain("some-domain3");
+ cookie.setPath("/some/path3");
+ cookie.setMaxAge((JAN_01_2030_NOON - creationDate.getTime()) / 1000);
+ cookies.add(cookie);
+
+ Set<HttpCookie> actualCookies = new NetscapeCookieFile(tmpFile, creationDate)
+ .getCookies(true);
+ Assert.assertThat(actualCookies,
+ HttpCookiesMatcher.containsInOrder(cookies));
+ }
+
+ @Test
+ public void testReadInvalidFile() throws IOException {
+ try (InputStream input = this.getClass()
+ .getResourceAsStream("cookies-invalid.txt")) {
+ Files.copy(input, tmpFile, StandardCopyOption.REPLACE_EXISTING);
+ }
+
+ new NetscapeCookieFile(tmpFile)
+ .getCookies(true);
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index 22dc471552..e839545250 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
@@ -1462,6 +1462,48 @@ public class ConfigTest {
assertEquals("xt", parseEscapedSubsection("\"x\\t\""));
}
+ @Test
+ public void testInvalidGroupHeader() throws ConfigInvalidException {
+ expectedEx.expect(ConfigInvalidException.class);
+ expectedEx.expectMessage(JGitText.get().badGroupHeader);
+ parse("[foo \"bar\" ]\nfoo=bar\n");
+ }
+
+ @Test
+ public void testCrLf() throws ConfigInvalidException {
+ assertEquals("true", parseEscapedValue("true\r\n"));
+ }
+
+ @Test
+ public void testLfContinuation() throws ConfigInvalidException {
+ assertEquals("true", parseEscapedValue("tr\\\nue"));
+ }
+
+ @Test
+ public void testCrCharContinuation() throws ConfigInvalidException {
+ expectedEx.expect(ConfigInvalidException.class);
+ expectedEx.expectMessage("Bad escape: \\u000d");
+ parseEscapedValue("tr\\\rue");
+ }
+
+ @Test
+ public void testCrEOFContinuation() throws ConfigInvalidException {
+ expectedEx.expect(ConfigInvalidException.class);
+ expectedEx.expectMessage("Bad escape: \\u000d");
+ parseEscapedValue("tr\\\r");
+ }
+
+ @Test
+ public void testCrLfContinuation() throws ConfigInvalidException {
+ assertEquals("true", parseEscapedValue("tr\\\r\nue"));
+ }
+
+ @Test
+ public void testWhitespaceContinuation() throws ConfigInvalidException {
+ assertEquals("tr ue", parseEscapedValue("tr \\\n ue"));
+ assertEquals("tr ue", parseEscapedValue("tr \\\r\n ue"));
+ }
+
private static void assertValueRoundTrip(String value)
throws ConfigInvalidException {
assertValueRoundTrip(value, value);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
index 531c918e9b..e7a5b286dd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
@@ -1678,7 +1678,6 @@ public class ObjectCheckerTest {
rejectName('>');
rejectName(':');
rejectName('"');
- rejectName('/');
rejectName('\\');
rejectName('|');
rejectName('?');
@@ -1693,7 +1692,8 @@ public class ObjectCheckerTest {
checkOneName("te" + c + "st");
fail("incorrectly accepted with " + c);
} catch (CorruptObjectException e) {
- assertEquals("name contains '" + c + "'", e.getMessage());
+
+ assertEquals("char '" + c + "' not allowed in Windows filename", e.getMessage());
}
}
@@ -1703,7 +1703,19 @@ public class ObjectCheckerTest {
checkOneName("te" + ((char) c) + "st");
fail("incorrectly accepted with 0x" + h);
} catch (CorruptObjectException e) {
- assertEquals("name contains byte 0x" + h, e.getMessage());
+ assertEquals("byte 0x" + h + " not allowed in Windows filename", e.getMessage());
+ }
+ }
+
+
+ @Test
+ public void testRejectInvalidCharacter() {
+ try {
+ checkOneName("te/st");
+ fail("incorrectly accepted with /");
+ } catch (CorruptObjectException e) {
+
+ assertEquals("name contains '/'", e.getMessage());
}
}
@@ -1763,16 +1775,13 @@ public class ObjectCheckerTest {
}
private static ObjectIdSet set(ObjectId... ids) {
- return new ObjectIdSet() {
- @Override
- public boolean contains(AnyObjectId objectId) {
- for (ObjectId id : ids) {
- if (id.equals(objectId)) {
- return true;
- }
+ return (AnyObjectId objectId) -> {
+ for (ObjectId id : ids) {
+ if (id.equals(objectId)) {
+ return true;
}
- return false;
}
+ return false;
};
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RebaseTodoFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RebaseTodoFileTest.java
new file mode 100644
index 0000000000..5cfc75ca93
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RebaseTodoFileTest.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2019, Thomas Wolf <thomas.wolf@paranor.ch>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.lib;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.junit.Test;
+
+public class RebaseTodoFileTest extends RepositoryTestCase {
+
+ private static final String TEST_TODO = "test.todo";
+
+ private void createTodoList(String... lines) throws IOException {
+ Path p = Paths.get(db.getDirectory().getAbsolutePath(), TEST_TODO);
+ Files.write(p, Arrays.asList(lines));
+ }
+
+ @Test
+ public void testReadTodoFile() throws Exception {
+ String[] expected = { "reword " + ObjectId.zeroId().name() + " Foo",
+ "# A comment in the the todo list",
+ "pick " + ObjectId.zeroId().name() + " Foo fie",
+ "squash " + ObjectId.zeroId().name() + " F",
+ "fixup " + ObjectId.zeroId().name(),
+ "edit " + ObjectId.zeroId().name() + " f",
+ "edit " + ObjectId.zeroId().name() + ' ' };
+ createTodoList(expected);
+ RebaseTodoFile todo = new RebaseTodoFile(db);
+ List<RebaseTodoLine> lines = todo.readRebaseTodo(TEST_TODO, true);
+ assertEquals("Expected 7 lines", 7, lines.size());
+ int i = 0;
+ for (RebaseTodoLine line : lines) {
+ switch (i) {
+ case 0:
+ assertEquals("Expected REWORD", RebaseTodoLine.Action.REWORD,
+ line.getAction());
+ assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
+ line.getCommit());
+ assertEquals("Unexpected Message", "Foo",
+ line.getShortMessage());
+ break;
+ case 1:
+ assertEquals("Expected COMMENT", RebaseTodoLine.Action.COMMENT,
+ line.getAction());
+ assertEquals("Unexpected Message",
+ "# A comment in the the todo list",
+ line.getComment());
+ break;
+ case 2:
+ assertEquals("Expected PICK", RebaseTodoLine.Action.PICK,
+ line.getAction());
+ assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
+ line.getCommit());
+ assertEquals("Unexpected Message", "Foo fie",
+ line.getShortMessage());
+ break;
+ case 3:
+ assertEquals("Expected SQUASH", RebaseTodoLine.Action.SQUASH,
+ line.getAction());
+ assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
+ line.getCommit());
+ assertEquals("Unexpected Message", "F", line.getShortMessage());
+ break;
+ case 4:
+ assertEquals("Expected FIXUP", RebaseTodoLine.Action.FIXUP,
+ line.getAction());
+ assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
+ line.getCommit());
+ assertEquals("Unexpected Message", "", line.getShortMessage());
+ break;
+ case 5:
+ assertEquals("Expected EDIT", RebaseTodoLine.Action.EDIT,
+ line.getAction());
+ assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
+ line.getCommit());
+ assertEquals("Unexpected Message", "f", line.getShortMessage());
+ break;
+ case 6:
+ assertEquals("Expected EDIT", RebaseTodoLine.Action.EDIT,
+ line.getAction());
+ assertEquals("Unexpected ID", ObjectId.zeroId().abbreviate(40),
+ line.getCommit());
+ assertEquals("Unexpected Message", "", line.getShortMessage());
+ break;
+ default:
+ fail("Too many lines");
+ return;
+ }
+ i++;
+ }
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
index 7d2c4a2784..b53d5b9448 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
@@ -58,8 +58,10 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.Collection;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import java.util.TreeSet;
import org.eclipse.jgit.lib.Ref.Storage;
@@ -313,7 +315,7 @@ public class RefTest extends SampleDataRepositoryTestCase {
assertEquals(dst.isPeeled(), ref.isPeeled());
}
- private static void checkContainsRef(List<Ref> haystack, Ref needle) {
+ private static void checkContainsRef(Collection<Ref> haystack, Ref needle) {
for (Ref ref : haystack) {
if (ref.getName().equals(needle.getName()) &&
ref.getObjectId().equals(needle.getObjectId())) {
@@ -347,4 +349,17 @@ public class RefTest extends SampleDataRepositoryTestCase {
checkContainsRef(refs, db.exactRef("refs/heads/prefix/a"));
checkContainsRef(refs, db.exactRef("refs/tags/A"));
}
+
+ @Test
+ public void testResolveTipSha1() throws IOException {
+ ObjectId masterId = db.resolve("refs/heads/master");
+ Set<Ref> resolved = db.getRefDatabase().getTipsWithSha1(masterId);
+
+ assertEquals(2, resolved.size());
+ checkContainsRef(resolved, db.exactRef("refs/heads/master"));
+ checkContainsRef(resolved, db.exactRef("HEAD"));
+
+ assertEquals(db.getRefDatabase()
+ .getTipsWithSha1(ObjectId.zeroId()).size(), 0);
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
index df1a52dc09..f2f277c6ea 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
@@ -45,7 +45,6 @@
package org.eclipse.jgit.lib;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -63,7 +62,8 @@ public class ReflogConfigTest extends RepositoryTestCase {
// check that there are no entries in the reflog and turn off writing
// reflogs
- assertEquals(0, db.getReflogReader(Constants.HEAD).getReverseEntries().size());
+ assertTrue(db.getReflogReader(Constants.HEAD).getReverseEntries()
+ .isEmpty());
final FileBasedConfig cfg = db.getConfig();
cfg.setBoolean("core", null, "logallrefupdates", false);
cfg.save();
@@ -72,9 +72,8 @@ public class ReflogConfigTest extends RepositoryTestCase {
// written
commit("A Commit\n", commitTime, tz);
commitTime += 60 * 1000;
- assertTrue(
- "Reflog for HEAD still contain no entry",
- db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 0);
+ assertTrue("Reflog for HEAD still contain no entry", db
+ .getReflogReader(Constants.HEAD).getReverseEntries().isEmpty());
// set the logAllRefUpdates parameter to true and check it
cfg.setBoolean("core", null, "logallrefupdates", true);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java
index 545a188a98..682982226e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java
@@ -61,29 +61,26 @@ public class ThreadSafeProgressMonitorTest {
final MockProgressMonitor mock = new MockProgressMonitor();
final ThreadSafeProgressMonitor pm = new ThreadSafeProgressMonitor(mock);
- runOnThread(new Runnable() {
- @Override
- public void run() {
- try {
- pm.start(1);
- fail("start did not fail on background thread");
- } catch (IllegalStateException notMainThread) {
- // Expected result
- }
-
- try {
- pm.beginTask("title", 1);
- fail("beginTask did not fail on background thread");
- } catch (IllegalStateException notMainThread) {
- // Expected result
- }
-
- try {
- pm.endTask();
- fail("endTask did not fail on background thread");
- } catch (IllegalStateException notMainThread) {
- // Expected result
- }
+ runOnThread(() -> {
+ try {
+ pm.start(1);
+ fail("start did not fail on background thread");
+ } catch (IllegalStateException notMainThread) {
+ // Expected result
+ }
+
+ try {
+ pm.beginTask("title", 1);
+ fail("beginTask did not fail on background thread");
+ } catch (IllegalStateException notMainThread) {
+ // Expected result
+ }
+
+ try {
+ pm.endTask();
+ fail("endTask did not fail on background thread");
+ } catch (IllegalStateException notMainThread) {
+ // Expected result
}
});
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
index 2ae9c11a7d..62495fb023 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
@@ -842,9 +842,9 @@ public class MergerTest extends RepositoryTestCase {
* Throws an exception if reading beyond limit.
*/
static class BigReadForbiddenStream extends ObjectStream.Filter {
- int limit;
+ long limit;
- BigReadForbiddenStream(ObjectStream orig, int limit) {
+ BigReadForbiddenStream(ObjectStream orig, long limit) {
super(orig.getType(), orig.getSize(), orig);
this.limit = limit;
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmapCalculatorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmapCalculatorTest.java
new file mode 100644
index 0000000000..c5d4d4238d
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmapCalculatorTest.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2019, Google LLC.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.revwalk;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.internal.storage.file.GC;
+import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
+import org.eclipse.jgit.junit.TestRepository;
+import org.eclipse.jgit.lib.BitmapIndex.BitmapBuilder;
+import org.eclipse.jgit.lib.NullProgressMonitor;
+import org.eclipse.jgit.lib.ProgressMonitor;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BitmapCalculatorTest extends LocalDiskRepositoryTestCase {
+ TestRepository<FileRepository> repo;
+
+ /** {@inheritDoc} */
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ FileRepository db = createWorkRepository();
+ repo = new TestRepository<>(db);
+ }
+
+ @Test
+ public void addOnlyCommits() throws Exception {
+ RevBlob abBlob = repo.blob("a_b_content");
+ RevCommit root = repo.commit().add("a/b", abBlob).create();
+ repo.update("refs/heads/master", root);
+
+ // GC creates bitmap index with ALL objects
+ GC gc = new GC(repo.getRepository());
+ gc.setAuto(false);
+ gc.gc();
+
+ // These objects are not in the bitmap index.
+ RevBlob acBlob = repo.blob("a_c_content");
+ RevCommit head = repo.commit().parent(root).add("a/c", acBlob).create();
+ repo.update("refs/heads/master", head);
+
+ BitmapCalculator bitmapWalker = new BitmapCalculator(repo.getRevWalk());
+ BitmapBuilder bitmap = bitmapWalker
+ .getBitmap(head, NullProgressMonitor.INSTANCE);
+
+ assertTrue(bitmap.contains(root.getId()));
+ assertTrue(bitmap.contains(root.getTree().getId()));
+ assertTrue(bitmap.contains(abBlob.getId()));
+
+ // BitmapCalculator added only the commit, no other objects.
+ assertTrue(bitmap.contains(head.getId()));
+ assertFalse(bitmap.contains(head.getTree().getId()));
+ assertFalse(bitmap.contains(acBlob.getId()));
+ }
+
+ @Test
+ public void walkUntilBitmap() throws Exception {
+ RevCommit root = repo.commit().create();
+ repo.update("refs/heads/master", root);
+
+ // GC creates bitmap index with ALL objects
+ GC gc = new GC(repo.getRepository());
+ gc.setAuto(false);
+ gc.gc();
+
+ // These objects are not in the bitmap index.
+ RevCommit commit1 = repo.commit(root);
+ RevCommit commit2 = repo.commit(commit1);
+ repo.update("refs/heads/master", commit2);
+
+ CounterProgressMonitor monitor = new CounterProgressMonitor();
+ BitmapCalculator bitmapWalker = new BitmapCalculator(repo.getRevWalk());
+ BitmapBuilder bitmap = bitmapWalker.getBitmap(commit2, monitor);
+
+ assertTrue(bitmap.contains(root));
+ assertTrue(bitmap.contains(commit1));
+ assertTrue(bitmap.contains(commit2));
+ assertEquals(2, monitor.getUpdates());
+ }
+
+ @Test
+ public void noNeedToWalk() throws Exception {
+ RevCommit root = repo.commit().create();
+ RevCommit commit1 = repo.commit(root);
+ RevCommit commit2 = repo.commit(commit1);
+ repo.update("refs/heads/master", commit2);
+
+ // GC creates bitmap index with ALL objects
+ GC gc = new GC(repo.getRepository());
+ gc.setAuto(false);
+ gc.gc();
+
+ CounterProgressMonitor monitor = new CounterProgressMonitor();
+ BitmapCalculator bitmapWalker = new BitmapCalculator(repo.getRevWalk());
+ BitmapBuilder bitmap = bitmapWalker.getBitmap(commit2, monitor);
+
+ assertTrue(bitmap.contains(root));
+ assertTrue(bitmap.contains(commit1));
+ assertTrue(bitmap.contains(commit2));
+ assertEquals(0, monitor.getUpdates());
+ }
+
+ private static class CounterProgressMonitor implements ProgressMonitor {
+
+ private int counter;
+
+ @Override
+ public void start(int totalTasks) {
+ // Nothing to do in tests
+ }
+
+ @Override
+ public void beginTask(String title, int totalWork) {
+ // Nothing to to in tests
+ }
+
+ @Override
+ public void update(int completed) {
+ counter += 1;
+ }
+
+ @Override
+ public void endTask() {
+ // Nothing to do in tests
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return false;
+ }
+
+ int getUpdates() {
+ return counter;
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmappedReachabilityCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmappedReachabilityCheckerTest.java
new file mode 100644
index 0000000000..5d3adf5eab
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/BitmappedReachabilityCheckerTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2019, Google LLC
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.revwalk;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.internal.storage.file.GC;
+import org.eclipse.jgit.junit.TestRepository;
+
+public class BitmappedReachabilityCheckerTest
+ extends ReachabilityCheckerTestCase {
+
+ @Override
+ protected ReachabilityChecker getChecker(
+ TestRepository<FileRepository> repository) throws Exception {
+ // GC generates the bitmaps
+ GC gc = new GC(repo.getRepository());
+ gc.setAuto(false);
+ gc.gc();
+
+ // This is null when the test didn't create any branch
+ assertNotNull("Probably the test didn't define any ref",
+ repo.getRevWalk().getObjectReader().getBitmapIndex());
+
+ return new BitmappedReachabilityChecker(repository.getRevWalk());
+ }
+
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/PedestrianReachabilityCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/PedestrianReachabilityCheckerTest.java
new file mode 100644
index 0000000000..8d3e78c1fe
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/PedestrianReachabilityCheckerTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2019, Google LLC.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.revwalk;
+
+import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.junit.TestRepository;
+
+public class PedestrianReachabilityCheckerTest
+ extends ReachabilityCheckerTestCase {
+
+ @Override
+ protected ReachabilityChecker getChecker(
+ TestRepository<FileRepository> repository) {
+ return new PedestrianReachabilityChecker(true, repository.getRevWalk());
+ }
+
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ReachabilityCheckerTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ReachabilityCheckerTestCase.java
new file mode 100644
index 0000000000..dd73e35727
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ReachabilityCheckerTestCase.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2019, Google LLC.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.revwalk;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
+import org.eclipse.jgit.junit.TestRepository;
+import org.junit.Before;
+import org.junit.Test;
+
+public abstract class ReachabilityCheckerTestCase
+ extends LocalDiskRepositoryTestCase {
+
+ protected abstract ReachabilityChecker getChecker(
+ TestRepository<FileRepository> repository) throws Exception;
+
+ TestRepository<FileRepository> repo;
+
+ /** {@inheritDoc} */
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ FileRepository db = createWorkRepository();
+ repo = new TestRepository<>(db);
+ }
+
+ @Test
+ public void reachable() throws Exception {
+ RevCommit a = repo.commit().create();
+ RevCommit b1 = repo.commit(a);
+ RevCommit b2 = repo.commit(b1);
+ RevCommit c1 = repo.commit(a);
+ RevCommit c2 = repo.commit(c1);
+ repo.update("refs/heads/checker", b2);
+
+ ReachabilityChecker checker = getChecker(repo);
+
+ assertReachable("reachable from one tip",
+ checker.areAllReachable(Arrays.asList(a), Arrays.asList(c2)));
+ assertReachable("reachable from another tip",
+ checker.areAllReachable(Arrays.asList(a), Arrays.asList(b2)));
+ assertReachable("reachable from itself",
+ checker.areAllReachable(Arrays.asList(a), Arrays.asList(b2)));
+ }
+
+ @Test
+ public void reachable_merge() throws Exception {
+ RevCommit a = repo.commit().create();
+ RevCommit b1 = repo.commit(a);
+ RevCommit b2 = repo.commit(b1);
+ RevCommit c1 = repo.commit(a);
+ RevCommit c2 = repo.commit(c1);
+ RevCommit merge = repo.commit(c2, b2);
+ repo.update("refs/heads/checker", merge);
+
+ ReachabilityChecker checker = getChecker(repo);
+
+ assertReachable("reachable through one branch",
+ checker.areAllReachable(Arrays.asList(b1),
+ Arrays.asList(merge)));
+ assertReachable("reachable through another branch",
+ checker.areAllReachable(Arrays.asList(c1),
+ Arrays.asList(merge)));
+ assertReachable("reachable, before the branching",
+ checker.areAllReachable(Arrays.asList(a),
+ Arrays.asList(merge)));
+ }
+
+ @Test
+ public void unreachable_isLaterCommit() throws Exception {
+ RevCommit a = repo.commit().create();
+ RevCommit b1 = repo.commit(a);
+ RevCommit b2 = repo.commit(b1);
+ repo.update("refs/heads/checker", b2);
+
+ ReachabilityChecker checker = getChecker(repo);
+
+ assertUnreachable("unreachable from the future",
+ checker.areAllReachable(Arrays.asList(b2), Arrays.asList(b1)));
+ }
+
+ @Test
+ public void unreachable_differentBranch() throws Exception {
+ RevCommit a = repo.commit().create();
+ RevCommit b1 = repo.commit(a);
+ RevCommit b2 = repo.commit(b1);
+ RevCommit c1 = repo.commit(a);
+ repo.update("refs/heads/checker", b2);
+
+ ReachabilityChecker checker = getChecker(repo);
+
+ assertUnreachable("unreachable from different branch",
+ checker.areAllReachable(Arrays.asList(c1), Arrays.asList(b2)));
+ }
+
+ @Test
+ public void reachable_longChain() throws Exception {
+ RevCommit root = repo.commit().create();
+ RevCommit head = root;
+ for (int i = 0; i < 10000; i++) {
+ head = repo.commit(head);
+ }
+ repo.update("refs/heads/master", head);
+
+ ReachabilityChecker checker = getChecker(repo);
+
+ assertReachable("reachable with long chain in the middle", checker
+ .areAllReachable(Arrays.asList(root), Arrays.asList(head)));
+ }
+
+ private static void assertReachable(String msg,
+ Optional<RevCommit> result) {
+ assertFalse(msg, result.isPresent());
+ }
+
+ private static void assertUnreachable(String msg,
+ Optional<RevCommit> result) {
+ assertTrue(msg, result.isPresent());
+ }
+
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java
index 4969305de0..e3972207f7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java
@@ -89,8 +89,8 @@ public class RevObjectTest extends RevWalkTestCase {
assertEquals(a1.hashCode(), a2.hashCode());
assertEquals(b1.hashCode(), b2.hashCode());
- assertTrue(AnyObjectId.equals(a1, a2));
- assertTrue(AnyObjectId.equals(b1, b2));
+ assertTrue(AnyObjectId.isEqual(a1, a2));
+ assertTrue(AnyObjectId.isEqual(b1, b2));
}
@Test
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 8b1d860059..f512d2849b 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
@@ -44,7 +44,8 @@
package org.eclipse.jgit.transport;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
@@ -142,21 +143,21 @@ public class PacketLineInTest {
init("0004");
final String act = in.readString();
assertEquals("", act);
- assertNotSame(PacketLineIn.END, act);
+ assertFalse(PacketLineIn.isEnd(act));
assertEOF();
}
@Test
public void testReadString_End() throws IOException {
init("0000");
- assertSame(PacketLineIn.END, in.readString());
+ assertTrue(PacketLineIn.isEnd(in.readString()));
assertEOF();
}
@Test
public void testReadString_Delim() throws IOException {
init("0001");
- assertSame(PacketLineIn.DELIM, in.readString());
+ assertTrue(PacketLineIn.isDelimiter(in.readString()));
assertEOF();
}
@@ -183,14 +184,14 @@ public class PacketLineInTest {
init("0004");
final String act = in.readStringRaw();
assertEquals("", act);
- assertNotSame(PacketLineIn.END, act);
+ assertFalse(PacketLineIn.isEnd(act));
assertEOF();
}
@Test
public void testReadStringRaw_End() throws IOException {
init("0000");
- assertSame(PacketLineIn.END, in.readStringRaw());
+ assertTrue(PacketLineIn.isEnd(in.readString()));
assertEOF();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java
index 2c98c84ae5..6e8327c792 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java
@@ -64,9 +64,9 @@ public class ProtocolV0ParserTest {
ByteArrayOutputStream send = new ByteArrayOutputStream();
PacketLineOut pckOut = new PacketLineOut(send);
for (String line : inputLines) {
- if (line == PacketLineIn.END) {
+ if (PacketLineIn.isEnd(line)) {
pckOut.end();
- } else if (line == PacketLineIn.DELIM) {
+ } else if (PacketLineIn.isDelimiter(line)) {
pckOut.writeDelim();
} else {
pckOut.writeString(line);
@@ -90,7 +90,7 @@ public class ProtocolV0ParserTest {
"4624442d68ee402a94364191085b77137618633e", "thin-pack",
"no-progress", "include-tag", "ofs-delta", "\n"),
"want f900c8326a43303685c46b279b9f70411bff1a4b\n",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV0Parser parser = new ProtocolV0Parser(defaultConfig());
FetchV0Request request = parser.recvWants(pckIn);
assertTrue(request.getClientCapabilities()
@@ -114,7 +114,7 @@ public class ProtocolV0ParserTest {
"4624442d68ee402a94364191085b77137618633e", "thin-pack",
"agent=JGit.test/0.0.1", "\n"),
"want f900c8326a43303685c46b279b9f70411bff1a4b\n",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV0Parser parser = new ProtocolV0Parser(defaultConfig());
FetchV0Request request = parser.recvWants(pckIn);
assertTrue(request.getClientCapabilities()
@@ -136,7 +136,7 @@ public class ProtocolV0ParserTest {
PacketLineIn pckIn = formatAsPacketLine(
"want 4624442d68ee402a94364191085b77137618633e\n",
"want f900c8326a43303685c46b279b9f70411bff1a4b\n",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV0Parser parser = new ProtocolV0Parser(defaultConfig());
FetchV0Request request = parser.recvWants(pckIn);
assertTrue(request.getClientCapabilities().isEmpty());
@@ -151,7 +151,7 @@ public class ProtocolV0ParserTest {
PacketLineIn pckIn = formatAsPacketLine(
"want 4624442d68ee402a94364191085b77137618633e\n",
"want f900c8326a43303685c46b279b9f70411bff1a4b\n", "deepen 3\n",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV0Parser parser = new ProtocolV0Parser(defaultConfig());
FetchV0Request request = parser.recvWants(pckIn);
assertTrue(request.getClientCapabilities().isEmpty());
@@ -168,7 +168,7 @@ public class ProtocolV0ParserTest {
"want 4624442d68ee402a94364191085b77137618633e\n",
"want f900c8326a43303685c46b279b9f70411bff1a4b\n",
"shallow 4b643d0ef739a1b494e7d6926d8d8ed80d35edf4\n",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV0Parser parser = new ProtocolV0Parser(defaultConfig());
FetchV0Request request = parser.recvWants(pckIn);
assertTrue(request.getClientCapabilities().isEmpty());
@@ -186,14 +186,15 @@ public class ProtocolV0ParserTest {
"want 4624442d68ee402a94364191085b77137618633e\n",
"want f900c8326a43303685c46b279b9f70411bff1a4b\n",
"filter blob:limit=13000\n",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV0Parser parser = new ProtocolV0Parser(defaultConfig());
FetchV0Request request = parser.recvWants(pckIn);
assertTrue(request.getClientCapabilities().isEmpty());
assertThat(request.getWantIds(),
hasOnlyObjectIds("4624442d68ee402a94364191085b77137618633e",
"f900c8326a43303685c46b279b9f70411bff1a4b"));
- assertEquals(13000, request.getFilterBlobLimit());
+ assertEquals(13000, request.getFilterSpec().getBlobLimit());
+ assertEquals(-1, request.getFilterSpec().getTreeDepthLimit());
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
index dafa81ecd0..0d70cd6121 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
@@ -123,9 +123,9 @@ public class ProtocolV2ParserTest {
ByteArrayOutputStream send = new ByteArrayOutputStream();
PacketLineOut pckOut = new PacketLineOut(send);
for (String line : inputLines) {
- if (line == PacketLineIn.END) {
+ if (PacketLineIn.isEnd(line)) {
pckOut.end();
- } else if (line == PacketLineIn.DELIM) {
+ } else if (PacketLineIn.isDelimiter(line)) {
pckOut.writeDelim();
} else {
pckOut.writeString(line);
@@ -136,19 +136,19 @@ public class ProtocolV2ParserTest {
}
/*
- * Succesful fetch with the basic core commands of the protocol.
+ * Successful fetch with the basic core commands of the protocol.
*/
@Test
public void testFetchBasicArguments()
throws PackProtocolException, IOException {
PacketLineIn pckIn = formatAsPacketLine(
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"thin-pack", "no-progress", "include-tag", "ofs-delta",
"want 4624442d68ee402a94364191085b77137618633e",
"want f900c8326a43303685c46b279b9f70411bff1a4b",
"have 554f6e41067b9e3e565b6988a8294fac1cb78f4b",
"have abc760ab9ad72f08209943251b36cb886a578f87", "done",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.getDefault());
FetchV2Request request = parser.parseFetchRequest(pckIn);
@@ -173,12 +173,12 @@ public class ProtocolV2ParserTest {
@Test
public void testFetchWithShallow_deepen() throws IOException {
PacketLineIn pckIn = formatAsPacketLine(
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"deepen 15",
"deepen-relative",
"shallow 28274d02c489f4c7e68153056e9061a46f62d7a0",
"shallow 145e683b229dcab9d0e2ccb01b386f9ecc17d29d",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.getDefault());
FetchV2Request request = parser.parseFetchRequest(pckIn);
@@ -193,11 +193,11 @@ public class ProtocolV2ParserTest {
@Test
public void testFetchWithShallow_deepenNot() throws IOException {
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
"shallow 28274d02c489f4c7e68153056e9061a46f62d7a0",
"shallow 145e683b229dcab9d0e2ccb01b386f9ecc17d29d",
"deepen-not a08595f76159b09d57553e37a5123f1091bb13e7",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.getDefault());
FetchV2Request request = parser.parseFetchRequest(pckIn);
@@ -210,11 +210,11 @@ public class ProtocolV2ParserTest {
@Test
public void testFetchWithShallow_deepenSince() throws IOException {
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
"shallow 28274d02c489f4c7e68153056e9061a46f62d7a0",
"shallow 145e683b229dcab9d0e2ccb01b386f9ecc17d29d",
"deepen-since 123123123",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.getDefault());
FetchV2Request request = parser.parseFetchRequest(pckIn);
@@ -226,32 +226,46 @@ public class ProtocolV2ParserTest {
@Test
public void testFetchWithNoneFilter() throws IOException {
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
"filter blob:none",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.start().allowFilter().done());
FetchV2Request request = parser.parseFetchRequest(pckIn);
- assertEquals(0, request.getFilterBlobLimit());
+ assertEquals(0, request.getFilterSpec().getBlobLimit());
+ assertEquals(-1, request.getFilterSpec().getTreeDepthLimit());
}
@Test
public void testFetchWithBlobSizeFilter() throws IOException {
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
"filter blob:limit=15",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.start().allowFilter().done());
FetchV2Request request = parser.parseFetchRequest(pckIn);
- assertEquals(15, request.getFilterBlobLimit());
+ assertEquals(15, request.getFilterSpec().getBlobLimit());
+ assertEquals(-1, request.getFilterSpec().getTreeDepthLimit());
+ }
+
+ @Test
+ public void testFetchWithTreeDepthFilter() throws IOException {
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
+ "filter tree:3",
+ PacketLineIn.end());
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.start().allowFilter().done());
+ FetchV2Request request = parser.parseFetchRequest(pckIn);
+ assertEquals(-1, request.getFilterSpec().getBlobLimit());
+ assertEquals(3, request.getFilterSpec().getTreeDepthLimit());
}
@Test
public void testFetchMustNotHaveMultipleFilters() throws IOException {
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
"filter blob:none",
"filter blob:limit=12",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.start().allowFilter().done());
@@ -261,8 +275,8 @@ public class ProtocolV2ParserTest {
@Test
public void testFetchFilterWithoutAllowFilter() throws IOException {
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
- "filter blob:limit=12", PacketLineIn.END);
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
+ "filter blob:limit=12", PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.getDefault());
@@ -277,10 +291,10 @@ public class ProtocolV2ParserTest {
testRepo.update("branchA", one);
testRepo.update("branchB", two);
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
"want e4980cdc48cfa1301493ca94eb70523f6788b819",
"want-ref refs/heads/branchA",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.start().allowRefInWant().done());
@@ -295,10 +309,10 @@ public class ProtocolV2ParserTest {
@Test
public void testFetchWithRefInWantUnknownRef() throws Exception {
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
"want e4980cdc48cfa1301493ca94eb70523f6788b819",
"want-ref refs/heads/branchC",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.start().allowRefInWant().done());
@@ -314,8 +328,8 @@ public class ProtocolV2ParserTest {
@Test
public void testLsRefsMinimalReq() throws IOException {
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
- PacketLineIn.END);
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.getDefault());
@@ -327,8 +341,8 @@ public class ProtocolV2ParserTest {
@Test
public void testLsRefsSymrefs() throws IOException {
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, "symrefs",
- PacketLineIn.END);
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(), "symrefs",
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.getDefault());
@@ -342,9 +356,9 @@ public class ProtocolV2ParserTest {
@Test
public void testLsRefsPeel() throws IOException {
PacketLineIn pckIn = formatAsPacketLine(
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"peel",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.getDefault());
@@ -356,9 +370,9 @@ public class ProtocolV2ParserTest {
@Test
public void testLsRefsRefPrefixes() throws IOException {
- PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.delimiter(),
"ref-prefix refs/for", "ref-prefix refs/heads",
- PacketLineIn.END);
+ PacketLineIn.end());
ProtocolV2Parser parser = new ProtocolV2Parser(
ConfigBuilder.getDefault());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
index cea432e34c..89d02d7527 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
@@ -67,9 +67,6 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.transport.resolver.ReceivePackFactory;
-import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
-import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -91,27 +88,16 @@ public class PushConnectionTest {
server = newRepo("server");
client = newRepo("client");
processedRefs = new ArrayList<>();
- testProtocol = new TestProtocol<>(
- null,
- new ReceivePackFactory<Object>() {
- @Override
- public ReceivePack create(Object req, Repository db)
- throws ServiceNotEnabledException,
- ServiceNotAuthorizedException {
- ReceivePack rp = new ReceivePack(db);
- rp.setPreReceiveHook(
- new PreReceiveHook() {
- @Override
- public void onPreReceive(ReceivePack receivePack,
- Collection<ReceiveCommand> cmds) {
- for (ReceiveCommand cmd : cmds) {
- processedRefs.add(cmd.getRefName());
- }
- }
- });
- return rp;
- }
- });
+ testProtocol = new TestProtocol<>(null, (Object req, Repository db) -> {
+ ReceivePack rp = new ReceivePack(db);
+ rp.setPreReceiveHook((ReceivePack receivePack,
+ Collection<ReceiveCommand> cmds) -> {
+ for (ReceiveCommand cmd : cmds) {
+ processedRefs.add(cmd.getRefName());
+ }
+ });
+ return rp;
+ });
uri = testProtocol.register(ctx, server);
try (ObjectInserter ins = server.newObjectInserter()) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushOptionsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushOptionsTest.java
index f26201d56d..fd1c3bf8b8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushOptionsTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushOptionsTest.java
@@ -69,9 +69,6 @@ import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.transport.resolver.ReceivePackFactory;
-import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
-import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -95,16 +92,11 @@ public class PushOptionsTest extends RepositoryTestCase {
client = newRepo("client");
testProtocol = new TestProtocol<>(null,
- new ReceivePackFactory<Object>() {
- @Override
- public ReceivePack create(Object req, Repository git)
- throws ServiceNotEnabledException,
- ServiceNotAuthorizedException {
- receivePack = new ReceivePack(git);
- receivePack.setAllowPushOptions(true);
- receivePack.setAtomic(true);
- return receivePack;
- }
+ (Object req, Repository git) -> {
+ receivePack = new ReceivePack(git);
+ receivePack.setAllowPushOptions(true);
+ receivePack.setAtomic(true);
+ return receivePack;
});
uri = testProtocol.register(ctx, server);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
index 50c8a29543..5d208eea73 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
@@ -306,11 +306,11 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
int nul = master.indexOf('\0');
assertTrue("has capability list", nul > 0);
assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul));
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
assertEquals("unpack error Missing commit " + P.name(), r.readString());
assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString());
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
}
private static void receive(final ReceivePack rp,
@@ -366,13 +366,13 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
int nul = master.indexOf('\0');
assertTrue("has capability list", nul > 0);
assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul));
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
assertEquals("unpack error Missing blob " + b.name(),
r.readString());
assertEquals("ng refs/heads/s n/a (unpacker error)",
r.readString());
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
}
}
@@ -419,13 +419,13 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
int nul = master.indexOf('\0');
assertTrue("has capability list", nul > 0);
assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul));
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
assertEquals("unpack error Missing blob " + b.name(),
r.readString());
assertEquals("ng refs/heads/s n/a (unpacker error)",
r.readString());
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
}
}
@@ -473,13 +473,13 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
int nul = master.indexOf('\0');
assertTrue("has capability list", nul > 0);
assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul));
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
assertEquals("unpack error Missing blob " + n.name(),
r.readString());
assertEquals("ng refs/heads/s n/a (unpacker error)",
r.readString());
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
}
}
@@ -504,13 +504,13 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
int nul = master.indexOf('\0');
assertTrue("has capability list", nul > 0);
assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul));
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
String errorLine = r.readString();
assertTrue(errorLine.startsWith("unpack error"));
assertTrue(errorLine.contains("Invalid submodule URL '-"));
assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString());
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
}
private TemporaryBuffer.Heap setupSourceRepoInvalidGitmodules()
@@ -589,13 +589,13 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
int nul = master.indexOf('\0');
assertTrue("has capability list", nul > 0);
assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul));
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
assertEquals("unpack error Missing tree " + t.name(),
r.readString());
assertEquals("ng refs/heads/s n/a (unpacker error)",
r.readString());
- assertSame(PacketLineIn.END, r.readString());
+ assertTrue(PacketLineIn.isEnd(r.readString()));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefAdvertiserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefAdvertiserTest.java
index ce69adf9c1..ccb548d919 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefAdvertiserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefAdvertiserTest.java
@@ -45,7 +45,7 @@ package org.eclipse.jgit.transport;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -95,7 +95,7 @@ public class RefAdvertiserTest {
assertEquals(id(3).name() + " refs/Iñtërnâtiônàlizætiøn☃💩\n", s);
s = pckIn.readStringRaw();
- assertSame(PacketLineIn.END, s);
+ assertTrue(PacketLineIn.isEnd(s));
}
private static ObjectId id(int i) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java
index 1c4d0cfe24..f4c55aa50a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java
@@ -92,11 +92,8 @@ public class TestProtocolTest {
@Override
public UploadPack create(User req, Repository db) {
UploadPack up = new UploadPack(db);
- up.setPostUploadHook(new PostUploadHook() {
- @Override
- public void onPostUpload(PackStatistics stats) {
- havesCount = stats.getHaves();
- }
+ up.setPostUploadHook((PackStatistics stats) -> {
+ havesCount = stats.getHaves();
});
return up;
}
@@ -217,16 +214,12 @@ public class TestProtocolTest {
ObjectId master = remote.branch("master").commit().create();
final AtomicInteger rejected = new AtomicInteger();
- TestProtocol<User> proto = registerProto(new UploadPackFactory<User>() {
- @Override
- public UploadPack create(User req, Repository db)
- throws ServiceNotAuthorizedException {
- if (!"user2".equals(req.name)) {
- rejected.incrementAndGet();
- throw new ServiceNotAuthorizedException();
- }
- return new UploadPack(db);
+ TestProtocol<User> proto = registerProto((User req, Repository db) -> {
+ if (!"user2".equals(req.name)) {
+ rejected.incrementAndGet();
+ throw new ServiceNotAuthorizedException();
}
+ return new UploadPack(db);
}, new DefaultReceive());
// Same repository, different users.
@@ -262,16 +255,12 @@ public class TestProtocolTest {
final AtomicInteger rejected = new AtomicInteger();
TestProtocol<User> proto = registerProto(new DefaultUpload(),
- new ReceivePackFactory<User>() {
- @Override
- public ReceivePack create(User req, Repository db)
- throws ServiceNotAuthorizedException {
- if (!"user2".equals(req.name)) {
- rejected.incrementAndGet();
- throw new ServiceNotAuthorizedException();
- }
- return new ReceivePack(db);
+ (User req, Repository db) -> {
+ if (!"user2".equals(req.name)) {
+ rejected.incrementAndGet();
+ throw new ServiceNotAuthorizedException();
}
+ return new ReceivePack(db);
});
// Same repository, different users.
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
new file mode 100644
index 0000000000..ee0e0af8c4
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportHttpTest.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2018, Konrad Windszus <konrad_w@gmx.de>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.transport;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.HttpCookie;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.eclipse.jgit.internal.transport.http.NetscapeCookieFile;
+import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
+import org.eclipse.jgit.transport.http.HttpConnection;
+import org.eclipse.jgit.util.http.HttpCookiesMatcher;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatchers;
+import org.mockito.Mockito;
+
+public class TransportHttpTest extends SampleDataRepositoryTestCase {
+ private URIish uri;
+ private File cookieFile;
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ uri = new URIish("https://everyones.loves.git/u/2");
+
+ final Config config = db.getConfig();
+ config.setBoolean("http", null, "saveCookies", true);
+ cookieFile = createTempFile();
+ config.setString("http", null, "cookieFile",
+ cookieFile.getAbsolutePath());
+ }
+
+ @Test
+ public void testMatchesCookieDomain() {
+ Assert.assertTrue(TransportHttp.matchesCookieDomain("example.com",
+ "example.com"));
+ Assert.assertTrue(TransportHttp.matchesCookieDomain("Example.Com",
+ "example.cOM"));
+ Assert.assertTrue(TransportHttp.matchesCookieDomain(
+ "some.subdomain.example.com", "example.com"));
+ Assert.assertFalse(TransportHttp
+ .matchesCookieDomain("someotherexample.com", "example.com"));
+ Assert.assertFalse(TransportHttp.matchesCookieDomain("example.com",
+ "example1.com"));
+ Assert.assertFalse(TransportHttp
+ .matchesCookieDomain("sub.sub.example.com", ".example.com"));
+ Assert.assertTrue(TransportHttp.matchesCookieDomain("host.example.com",
+ "example.com"));
+ Assert.assertTrue(TransportHttp.matchesCookieDomain(
+ "something.example.com", "something.example.com"));
+ Assert.assertTrue(TransportHttp.matchesCookieDomain(
+ "host.something.example.com", "something.example.com"));
+ }
+
+ @Test
+ public void testMatchesCookiePath() {
+ Assert.assertTrue(
+ TransportHttp.matchesCookiePath("/some/path", "/some/path"));
+ Assert.assertTrue(TransportHttp.matchesCookiePath("/some/path/child",
+ "/some/path"));
+ Assert.assertTrue(TransportHttp.matchesCookiePath("/some/path/child",
+ "/some/path/"));
+ Assert.assertFalse(TransportHttp.matchesCookiePath("/some/pathother",
+ "/some/path"));
+ Assert.assertFalse(
+ TransportHttp.matchesCookiePath("otherpath", "/some/path"));
+ }
+
+ @Test
+ public void testProcessResponseCookies() throws IOException {
+ HttpConnection connection = Mockito.mock(HttpConnection.class);
+ Mockito.when(
+ connection.getHeaderFields(ArgumentMatchers.eq("Set-Cookie")))
+ .thenReturn(Arrays.asList(
+ "id=a3fWa; Expires=Fri, 01 Jan 2100 11:00:00 GMT; Secure; HttpOnly",
+ "sessionid=38afes7a8; HttpOnly; Path=/"));
+ Mockito.when(
+ connection.getHeaderFields(ArgumentMatchers.eq("Set-Cookie2")))
+ .thenReturn(Collections
+ .singletonList("cookie2=some value; Max-Age=1234; Path=/"));
+
+ try (TransportHttp transportHttp = new TransportHttp(db, uri)) {
+ Date creationDate = new Date();
+ transportHttp.processResponseCookies(connection);
+
+ // evaluate written cookie file
+ Set<HttpCookie> expectedCookies = new LinkedHashSet<>();
+
+ HttpCookie cookie = new HttpCookie("id", "a3fWa");
+ cookie.setDomain("everyones.loves.git");
+ cookie.setPath("/u/2/");
+
+ cookie.setMaxAge(
+ (Instant.parse("2100-01-01T11:00:00.000Z").toEpochMilli()
+ - creationDate.getTime()) / 1000);
+ cookie.setSecure(true);
+ cookie.setHttpOnly(true);
+ expectedCookies.add(cookie);
+
+ cookie = new HttpCookie("cookie2", "some value");
+ cookie.setDomain("everyones.loves.git");
+ cookie.setPath("/");
+ cookie.setMaxAge(1234);
+ expectedCookies.add(cookie);
+
+ Assert.assertThat(
+ new NetscapeCookieFile(cookieFile.toPath())
+ .getCookies(true),
+ HttpCookiesMatcher.containsInOrder(expectedCookies, 5));
+ }
+ }
+
+ @Test
+ public void testProcessResponseCookiesNotPersistingWithSaveCookiesFalse()
+ throws IOException {
+ HttpConnection connection = Mockito.mock(HttpConnection.class);
+ Mockito.when(
+ connection.getHeaderFields(ArgumentMatchers.eq("Set-Cookie")))
+ .thenReturn(Arrays.asList(
+ "id=a3fWa; Expires=Thu, 21 Oct 2100 11:00:00 GMT; Secure; HttpOnly",
+ "sessionid=38afes7a8; HttpOnly; Path=/"));
+ Mockito.when(
+ connection.getHeaderFields(ArgumentMatchers.eq("Set-Cookie2")))
+ .thenReturn(Collections.singletonList(
+ "cookie2=some value; Max-Age=1234; Path=/"));
+
+ // tweak config
+ final Config config = db.getConfig();
+ config.setBoolean("http", null, "saveCookies", false);
+
+ try (TransportHttp transportHttp = new TransportHttp(db, uri)) {
+ transportHttp.processResponseCookies(connection);
+
+ // evaluate written cookie file
+ Assert.assertFalse("Cookie file was not supposed to be written!",
+ cookieFile.exists());
+ }
+ }
+}
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 1cbe8a4312..260130b2bd 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
@@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
-import static org.hamcrest.Matchers.theInstance;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -16,11 +15,16 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.dircache.DirCacheBuilder;
+import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector;
@@ -28,6 +32,8 @@ import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.NullProgressMonitor;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
@@ -38,10 +44,8 @@ import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevTree;
+import org.eclipse.jgit.storage.pack.PackStatistics;
import org.eclipse.jgit.transport.UploadPack.RequestPolicy;
-import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
-import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
-import org.eclipse.jgit.transport.resolver.UploadPackFactory;
import org.eclipse.jgit.util.io.NullOutputStream;
import org.hamcrest.Matchers;
import org.junit.After;
@@ -69,6 +73,8 @@ public class UploadPackTest {
private TestRepository<InMemoryRepository> remote;
+ private PackStatistics stats;
+
@Before
public void setUp() throws Exception {
server = newRepo("server");
@@ -92,17 +98,11 @@ public class UploadPackTest {
}
private static TestProtocol<Object> generateReachableCommitUploadPackProtocol() {
- return new TestProtocol<>(
- new UploadPackFactory<Object>() {
- @Override
- public UploadPack create(Object req, Repository db)
- throws ServiceNotEnabledException,
- ServiceNotAuthorizedException {
- UploadPack up = new UploadPack(db);
- up.setRequestPolicy(RequestPolicy.REACHABLE_COMMIT);
- return up;
- }
- }, null);
+ return new TestProtocol<>((Object req, Repository db) -> {
+ UploadPack up = new UploadPack(db);
+ up.setRequestPolicy(RequestPolicy.REACHABLE_COMMIT);
+ return up;
+ }, null);
}
@Test
@@ -112,20 +112,14 @@ public class UploadPackTest {
RevCommit tip = remote.commit().message("2").parent(commit1).create();
remote.update("master", tip);
- testProtocol = new TestProtocol<>(
- new UploadPackFactory<Object>() {
- @Override
- public UploadPack create(Object req, Repository db)
- throws ServiceNotEnabledException,
- ServiceNotAuthorizedException {
- UploadPack up = new UploadPack(db);
- up.setRequestPolicy(RequestPolicy.REACHABLE_COMMIT);
- // assume client has a shallow commit
- up.getRevWalk().assumeShallow(
- Collections.singleton(commit1.getId()));
- return up;
- }
- }, null);
+ testProtocol = new TestProtocol<>((Object req, Repository db) -> {
+ UploadPack up = new UploadPack(db);
+ up.setRequestPolicy(RequestPolicy.REACHABLE_COMMIT);
+ // assume client has a shallow commit
+ up.getRevWalk()
+ .assumeShallow(Collections.singleton(commit1.getId()));
+ return up;
+ }, null);
uri = testProtocol.register(ctx, server);
assertFalse(client.getObjectDatabase().has(commit0.toObjectId()));
@@ -212,19 +206,14 @@ public class UploadPackTest {
server2.getConfig().setBoolean("uploadpack", null, "allowfilter",
true);
- testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
- @Override
- public UploadPack create(Object req, Repository db)
- throws ServiceNotEnabledException,
- ServiceNotAuthorizedException {
- UploadPack up = new UploadPack(db);
- return up;
- }
+ testProtocol = new TestProtocol<>((Object req, Repository db) -> {
+ UploadPack up = new UploadPack(db);
+ return up;
}, null);
uri = testProtocol.register(ctx, server2);
try (Transport tn = testProtocol.open(uri, client, "server2")) {
- tn.setFilterBlobLimit(0);
+ tn.setFilterSpec(FilterSpec.withBlobLimit(0));
tn.fetch(NullProgressMonitor.INSTANCE,
Collections.singletonList(new RefSpec(commit.name())));
assertTrue(client.getObjectDatabase().has(tree.toObjectId()));
@@ -250,19 +239,14 @@ public class UploadPackTest {
server2.getConfig().setBoolean("uploadpack", null, "allowfilter",
true);
- testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
- @Override
- public UploadPack create(Object req, Repository db)
- throws ServiceNotEnabledException,
- ServiceNotAuthorizedException {
- UploadPack up = new UploadPack(db);
- return up;
- }
+ testProtocol = new TestProtocol<>((Object req, Repository db) -> {
+ UploadPack up = new UploadPack(db);
+ return up;
}, null);
uri = testProtocol.register(ctx, server2);
try (Transport tn = testProtocol.open(uri, client, "server2")) {
- tn.setFilterBlobLimit(0);
+ tn.setFilterSpec(FilterSpec.withBlobLimit(0));
tn.fetch(NullProgressMonitor.INSTANCE, Arrays.asList(
new RefSpec(commit.name()), new RefSpec(blob1.name())));
assertTrue(client.getObjectDatabase().has(tree.toObjectId()));
@@ -287,19 +271,14 @@ public class UploadPackTest {
server2.getConfig().setBoolean("uploadpack", null, "allowfilter",
true);
- testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
- @Override
- public UploadPack create(Object req, Repository db)
- throws ServiceNotEnabledException,
- ServiceNotAuthorizedException {
- UploadPack up = new UploadPack(db);
- return up;
- }
+ testProtocol = new TestProtocol<>((Object req, Repository db) -> {
+ UploadPack up = new UploadPack(db);
+ return up;
}, null);
uri = testProtocol.register(ctx, server2);
try (Transport tn = testProtocol.open(uri, client, "server2")) {
- tn.setFilterBlobLimit(5);
+ tn.setFilterSpec(FilterSpec.withBlobLimit(5));
tn.fetch(NullProgressMonitor.INSTANCE,
Collections.singletonList(new RefSpec(commit.name())));
assertFalse(
@@ -330,19 +309,14 @@ public class UploadPackTest {
new DfsGarbageCollector(server2).pack(null);
server2.scanForRepoChanges();
- testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
- @Override
- public UploadPack create(Object req, Repository db)
- throws ServiceNotEnabledException,
- ServiceNotAuthorizedException {
- UploadPack up = new UploadPack(db);
- return up;
- }
+ testProtocol = new TestProtocol<>((Object req, Repository db) -> {
+ UploadPack up = new UploadPack(db);
+ return up;
}, null);
uri = testProtocol.register(ctx, server2);
try (Transport tn = testProtocol.open(uri, client, "server2")) {
- tn.setFilterBlobLimit(0);
+ tn.setFilterSpec(FilterSpec.withBlobLimit(0));
tn.fetch(NullProgressMonitor.INSTANCE, Arrays.asList(
new RefSpec(commit.name()), new RefSpec(blob1.name())));
assertTrue(client.getObjectDatabase().has(blob1.toObjectId()));
@@ -370,19 +344,14 @@ public class UploadPackTest {
new DfsGarbageCollector(server2).pack(null);
server2.scanForRepoChanges();
- testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
- @Override
- public UploadPack create(Object req, Repository db)
- throws ServiceNotEnabledException,
- ServiceNotAuthorizedException {
- UploadPack up = new UploadPack(db);
- return up;
- }
+ testProtocol = new TestProtocol<>((Object req, Repository db) -> {
+ UploadPack up = new UploadPack(db);
+ return up;
}, null);
uri = testProtocol.register(ctx, server2);
try (Transport tn = testProtocol.open(uri, client, "server2")) {
- tn.setFilterBlobLimit(5);
+ tn.setFilterSpec(FilterSpec.withBlobLimit(5));
tn.fetch(NullProgressMonitor.INSTANCE,
Collections.singletonList(new RefSpec(commit.name())));
assertFalse(
@@ -406,19 +375,14 @@ public class UploadPackTest {
server2.getConfig().setBoolean("uploadpack", null, "allowfilter",
false);
- testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
- @Override
- public UploadPack create(Object req, Repository db)
- throws ServiceNotEnabledException,
- ServiceNotAuthorizedException {
- UploadPack up = new UploadPack(db);
- return up;
- }
+ testProtocol = new TestProtocol<>((Object req, Repository db) -> {
+ UploadPack up = new UploadPack(db);
+ return up;
}, null);
uri = testProtocol.register(ctx, server2);
try (Transport tn = testProtocol.open(uri, client, "server2")) {
- tn.setFilterBlobLimit(0);
+ tn.setFilterSpec(FilterSpec.withBlobLimit(0));
thrown.expect(TransportException.class);
thrown.expectMessage(
@@ -453,6 +417,7 @@ public class UploadPackTest {
ByteArrayOutputStream recv = new ByteArrayOutputStream();
up.upload(send, recv, null);
+ stats = up.getStatistics();
return new ByteArrayInputStream(recv.toByteArray());
}
@@ -462,9 +427,9 @@ public class UploadPackTest {
try (ByteArrayOutputStream send = new ByteArrayOutputStream()) {
PacketLineOut pckOut = new PacketLineOut(send);
for (String line : inputLines) {
- if (line == PacketLineIn.END) {
+ if (PacketLineIn.isEnd(line)) {
pckOut.end();
- } else if (line == PacketLineIn.DELIM) {
+ } else if (PacketLineIn.isDelimiter(line)) {
pckOut.writeDelim();
} else {
pckOut.writeString(line);
@@ -487,7 +452,7 @@ public class UploadPackTest {
PacketLineIn pckIn = new PacketLineIn(recvStream);
// drain capabilities
- while (pckIn.readString() != PacketLineIn.END) {
+ while (!PacketLineIn.isEnd(pckIn.readString())) {
// do nothing
}
return recvStream;
@@ -524,7 +489,7 @@ public class UploadPackTest {
public void testV2Capabilities() throws Exception {
TestV2Hook hook = new TestV2Hook();
ByteArrayInputStream recvStream =
- uploadPackV2Setup(null, null, hook, PacketLineIn.END);
+ uploadPackV2Setup(null, null, hook, PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(hook.capabilitiesRequest, notNullValue());
assertThat(pckIn.readString(), is("version 2"));
@@ -538,14 +503,14 @@ public class UploadPackTest {
// and additional capabilities to be added to existing
// commands without requiring test changes.
hasItems("ls-refs", "fetch=shallow", "server-option"));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
public void testV2CapabilitiesAllowFilter() throws Exception {
server.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
ByteArrayInputStream recvStream =
- uploadPackV2Setup(null, null, null, PacketLineIn.END);
+ uploadPackV2Setup(null, null, null, PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("version 2"));
@@ -555,14 +520,14 @@ public class UploadPackTest {
// TODO(jonathantanmy) This check overspecifies the
// order of the capabilities of "fetch".
hasItems("ls-refs", "fetch=filter shallow", "server-option"));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
public void testV2CapabilitiesRefInWant() throws Exception {
server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", true);
ByteArrayInputStream recvStream =
- uploadPackV2Setup(null, null, null, PacketLineIn.END);
+ uploadPackV2Setup(null, null, null, PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("version 2"));
@@ -573,14 +538,14 @@ public class UploadPackTest {
// order of the capabilities of "fetch".
hasItems("ls-refs", "fetch=ref-in-want shallow",
"server-option"));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
public void testV2CapabilitiesRefInWantNotAdvertisedIfUnallowed() throws Exception {
server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", false);
ByteArrayInputStream recvStream =
- uploadPackV2Setup(null, null, null, PacketLineIn.END);
+ uploadPackV2Setup(null, null, null, PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("version 2"));
@@ -588,7 +553,7 @@ public class UploadPackTest {
Arrays.asList(pckIn.readString(), pckIn.readString(),
pckIn.readString()),
hasItems("ls-refs", "fetch=shallow", "server-option"));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
@@ -596,7 +561,7 @@ public class UploadPackTest {
server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", true);
server.getConfig().setBoolean("uploadpack", null, "advertiserefinwant", false);
ByteArrayInputStream recvStream =
- uploadPackV2Setup(null, null, null, PacketLineIn.END);
+ uploadPackV2Setup(null, null, null, PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("version 2"));
@@ -604,12 +569,12 @@ public class UploadPackTest {
Arrays.asList(pckIn.readString(), pckIn.readString(),
pckIn.readString()),
hasItems("ls-refs", "fetch=shallow", "server-option"));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
public void testV2EmptyRequest() throws Exception {
- ByteArrayInputStream recvStream = uploadPackV2(PacketLineIn.END);
+ ByteArrayInputStream recvStream = uploadPackV2(PacketLineIn.end());
// Verify that there is nothing more after the capability
// advertisement.
assertEquals(0, recvStream.available());
@@ -625,14 +590,14 @@ public class UploadPackTest {
TestV2Hook hook = new TestV2Hook();
ByteArrayInputStream recvStream = uploadPackV2(null, null, hook,
- "command=ls-refs\n", PacketLineIn.END);
+ "command=ls-refs\n", PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(hook.lsRefsRequest, notNullValue());
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD"));
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
assertThat(pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag"));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
@@ -643,13 +608,14 @@ public class UploadPackTest {
RevTag tag = remote.tag("tag", tip);
remote.update("refs/tags/tag", tag);
- ByteArrayInputStream recvStream = uploadPackV2("command=ls-refs\n", PacketLineIn.DELIM, "symrefs", PacketLineIn.END);
+ ByteArrayInputStream recvStream = uploadPackV2("command=ls-refs\n",
+ PacketLineIn.delimiter(), "symrefs", PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD symref-target:refs/heads/master"));
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
assertThat(pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag"));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
@@ -660,7 +626,8 @@ public class UploadPackTest {
RevTag tag = remote.tag("tag", tip);
remote.update("refs/tags/tag", tag);
- ByteArrayInputStream recvStream = uploadPackV2("command=ls-refs\n", PacketLineIn.DELIM, "peel", PacketLineIn.END);
+ ByteArrayInputStream recvStream = uploadPackV2("command=ls-refs\n",
+ PacketLineIn.delimiter(), "peel", PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD"));
@@ -669,7 +636,7 @@ public class UploadPackTest {
pckIn.readString(),
is(tag.toObjectId().getName() + " refs/tags/tag peeled:"
+ tip.toObjectId().getName()));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
@@ -681,8 +648,9 @@ public class UploadPackTest {
remote.update("refs/tags/tag", tag);
ByteArrayInputStream recvStream = uploadPackV2(
- "command=ls-refs\n", PacketLineIn.DELIM, "symrefs", "peel", PacketLineIn.END,
- "command=ls-refs\n", PacketLineIn.DELIM, PacketLineIn.END);
+ "command=ls-refs\n", PacketLineIn.delimiter(), "symrefs",
+ "peel", PacketLineIn.end(), "command=ls-refs\n",
+ PacketLineIn.delimiter(), PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD symref-target:refs/heads/master"));
@@ -691,11 +659,11 @@ public class UploadPackTest {
pckIn.readString(),
is(tag.toObjectId().getName() + " refs/tags/tag peeled:"
+ tip.toObjectId().getName()));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD"));
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
assertThat(pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag"));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
@@ -707,15 +675,15 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=ls-refs\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"ref-prefix refs/heads/maste",
"ref-prefix refs/heads/other",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/other"));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
@@ -726,15 +694,15 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=ls-refs\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"ref-prefix refs/heads/maste",
"ref-prefix r",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/other"));
- assertTrue(pckIn.readString() == PacketLineIn.END);
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
@@ -743,17 +711,17 @@ public class UploadPackTest {
thrown.expectMessage("unexpected invalid-argument");
uploadPackV2(
"command=ls-refs\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"invalid-argument\n",
- PacketLineIn.END);
+ PacketLineIn.end());
}
@Test
public void testV2LsRefsServerOptions() throws Exception {
String[] lines = { "command=ls-refs\n",
"server-option=one\n", "server-option=two\n",
- PacketLineIn.DELIM,
- PacketLineIn.END };
+ PacketLineIn.delimiter(),
+ PacketLineIn.end() };
TestV2Hook testHook = new TestV2Hook();
uploadPackV2Setup(null, null, testHook, lines);
@@ -797,9 +765,9 @@ public class UploadPackTest {
null,
null,
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + advertized.name() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
// This doesn't
thrown.expect(TransportException.class);
@@ -810,9 +778,9 @@ public class UploadPackTest {
null,
null,
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + unadvertized.name() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
}
@Test
@@ -828,9 +796,9 @@ public class UploadPackTest {
null,
null,
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + reachable.name() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
// This doesn't
thrown.expect(TransportException.class);
@@ -841,9 +809,9 @@ public class UploadPackTest {
null,
null,
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + unreachable.name() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
}
@Test
@@ -858,9 +826,9 @@ public class UploadPackTest {
new RejectAllRefFilter(),
null,
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + tip.name() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
// This doesn't
thrown.expect(TransportException.class);
@@ -871,9 +839,9 @@ public class UploadPackTest {
new RejectAllRefFilter(),
null,
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + parentOfTip.name() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
}
@Test
@@ -889,9 +857,9 @@ public class UploadPackTest {
new RejectAllRefFilter(),
null,
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + parentOfTip.name() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
// This doesn't
thrown.expect(TransportException.class);
@@ -902,9 +870,9 @@ public class UploadPackTest {
new RejectAllRefFilter(),
null,
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + unreachable.name() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
}
@Test
@@ -917,9 +885,9 @@ public class UploadPackTest {
null,
null,
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + unreachable.name() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
}
@Test
@@ -933,16 +901,16 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + fooChild.toObjectId().getName() + "\n",
"want " + barChild.toObjectId().getName() + "\n",
"have " + fooParent.toObjectId().getName() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("acknowledgments"));
assertThat(pckIn.readString(), is("ACK " + fooParent.toObjectId().getName()));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.END));
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
@@ -956,12 +924,12 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + fooChild.toObjectId().getName() + "\n",
"want " + barChild.toObjectId().getName() + "\n",
"have " + fooParent.toObjectId().getName() + "\n",
"have " + barParent.toObjectId().getName() + "\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("acknowledgments"));
@@ -971,7 +939,7 @@ public class UploadPackTest {
"ACK " + fooParent.toObjectId().getName(),
"ACK " + barParent.toObjectId().getName()));
assertThat(pckIn.readString(), is("ready"));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
assertFalse(client.getObjectDatabase().has(fooParent.toObjectId()));
@@ -991,12 +959,12 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + fooChild.toObjectId().getName() + "\n",
"want " + barChild.toObjectId().getName() + "\n",
"have " + fooParent.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
@@ -1020,12 +988,12 @@ public class UploadPackTest {
// Pretend that we have parent to get a thin pack based on it.
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + child.toObjectId().getName() + "\n",
"have " + parent.toObjectId().getName() + "\n",
"thin-pack\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
@@ -1046,10 +1014,10 @@ public class UploadPackTest {
StringWriter sw = new StringWriter();
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + commit.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream, new TextProgressMonitor(sw));
@@ -1059,11 +1027,11 @@ public class UploadPackTest {
sw = new StringWriter();
recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + commit.toObjectId().getName() + "\n",
"no-progress\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream, new TextProgressMonitor(sw));
@@ -1080,10 +1048,10 @@ public class UploadPackTest {
// Without include-tag.
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + commit.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1092,11 +1060,11 @@ public class UploadPackTest {
// With tag.
recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + commit.toObjectId().getName() + "\n",
"include-tag\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1116,27 +1084,27 @@ public class UploadPackTest {
// Without ofs-delta.
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + child.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
- ReceivedPackStatistics stats = parsePack(recvStream);
- assertTrue(stats.getNumOfsDelta() == 0);
+ ReceivedPackStatistics receivedStats = parsePack(recvStream);
+ assertTrue(receivedStats.getNumOfsDelta() == 0);
// With ofs-delta.
recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + child.toObjectId().getName() + "\n",
"ofs-delta\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
- stats = parsePack(recvStream);
- assertTrue(stats.getNumOfsDelta() != 0);
+ receivedStats = parsePack(recvStream);
+ assertTrue(receivedStats.getNumOfsDelta() != 0);
}
@Test
@@ -1150,11 +1118,11 @@ public class UploadPackTest {
// commonParent, so it doesn't send it.
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + barChild.toObjectId().getName() + "\n",
"have " + fooChild.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1165,12 +1133,12 @@ public class UploadPackTest {
// commonParent, so it sends it.
recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + barChild.toObjectId().getName() + "\n",
"have " + fooChild.toObjectId().getName() + "\n",
"shallow " + fooChild.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1186,15 +1154,15 @@ public class UploadPackTest {
// "deepen 1" sends only the child.
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + child.toObjectId().getName() + "\n",
"deepen 1\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("shallow-info"));
assertThat(pckIn.readString(), is("shallow " + child.toObjectId().getName()));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
assertTrue(client.getObjectDatabase().has(child.toObjectId()));
@@ -1203,10 +1171,10 @@ public class UploadPackTest {
// Without that, the parent is sent too.
recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + child.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1221,10 +1189,10 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + child.toObjectId().getName() + "\n",
"deepen 1\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
// Verify that only the correct section is sent. "shallow-info"
@@ -1232,7 +1200,7 @@ public class UploadPackTest {
// sent only if a packfile is sent.
assertThat(pckIn.readString(), is("acknowledgments"));
assertThat(pckIn.readString(), is("NAK"));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.END));
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
}
@Test
@@ -1253,13 +1221,13 @@ public class UploadPackTest {
// Report that we only have "boundary" as a shallow boundary.
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"shallow " + boundary.toObjectId().getName() + "\n",
"deepen-since 1510000\n",
"want " + merge.toObjectId().getName() + "\n",
"have " + boundary.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("shallow-info"));
@@ -1271,7 +1239,7 @@ public class UploadPackTest {
// later than the given deepen-since time.
assertThat(pckIn.readString(), is("unshallow " + boundary.toObjectId().getName()));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1304,12 +1272,12 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"deepen-since 1510000\n",
"want " + child1.toObjectId().getName() + "\n",
"want " + child2.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("shallow-info"));
@@ -1320,7 +1288,7 @@ public class UploadPackTest {
"shallow " + child1.toObjectId().getName(),
"shallow " + child2.toObjectId().getName()));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1343,11 +1311,11 @@ public class UploadPackTest {
thrown.expectMessage("No commits selected for shallow request");
uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"deepen-since 1510000\n",
"want " + tooOld.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
}
@Test
@@ -1366,13 +1334,13 @@ public class UploadPackTest {
// wants "merge" while excluding "side".
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"shallow " + three.toObjectId().getName() + "\n",
"deepen-not side\n",
"want " + merge.toObjectId().getName() + "\n",
"have " + three.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("shallow-info"));
@@ -1387,7 +1355,7 @@ public class UploadPackTest {
// "three" is unshallow because its parent "two" is now available.
assertThat(pckIn.readString(), is("unshallow " + three.toObjectId().getName()));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1419,11 +1387,11 @@ public class UploadPackTest {
thrown.expectMessage("No commits selected for shallow request");
uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"deepen-not four\n",
"want " + two.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
}
@Test
@@ -1439,15 +1407,15 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"deepen-not twotag\n",
"want " + four.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("shallow-info"));
assertThat(pckIn.readString(), is("shallow " + three.toObjectId().getName()));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
assertFalse(client.getObjectDatabase().has(one.toObjectId()));
@@ -1473,12 +1441,12 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"deepen-not base\n",
"want " + child1.toObjectId().getName() + "\n",
"want " + child2.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("shallow-info"));
@@ -1489,7 +1457,7 @@ public class UploadPackTest {
"shallow " + child1.toObjectId().getName(),
"shallow " + child2.toObjectId().getName()));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1505,16 +1473,16 @@ public class UploadPackTest {
thrown.expectMessage("unexpected invalid-argument");
uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"invalid-argument\n",
- PacketLineIn.END);
+ PacketLineIn.end());
}
@Test
public void testV2FetchServerOptions() throws Exception {
String[] lines = { "command=fetch\n", "server-option=one\n",
- "server-option=two\n", PacketLineIn.DELIM,
- PacketLineIn.END };
+ "server-option=two\n", PacketLineIn.delimiter(),
+ PacketLineIn.end() };
TestV2Hook testHook = new TestV2Hook();
uploadPackV2Setup(null, null, testHook, lines);
@@ -1538,11 +1506,11 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + commit.toObjectId().getName() + "\n",
"filter blob:limit=5\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1551,6 +1519,324 @@ public class UploadPackTest {
assertTrue(client.getObjectDatabase().has(small.toObjectId()));
}
+ abstract class TreeBuilder {
+ abstract void addElements(DirCacheBuilder dcBuilder) throws Exception;
+
+ RevTree build() throws Exception {
+ DirCache dc = DirCache.newInCore();
+ DirCacheBuilder dcBuilder = dc.builder();
+ addElements(dcBuilder);
+ dcBuilder.finish();
+ ObjectId id;
+ try (ObjectInserter ins =
+ remote.getRepository().newObjectInserter()) {
+ id = dc.writeTree(ins);
+ ins.flush();
+ }
+ return remote.getRevWalk().parseTree(id);
+ }
+ }
+
+ class DeepTreePreparator {
+ RevBlob blobLowDepth = remote.blob("lo");
+ RevBlob blobHighDepth = remote.blob("hi");
+
+ RevTree subtree = remote.tree(remote.file("1", blobHighDepth));
+ RevTree rootTree = (new TreeBuilder() {
+ @Override
+ void addElements(DirCacheBuilder dcBuilder) throws Exception {
+ dcBuilder.add(remote.file("1", blobLowDepth));
+ dcBuilder.addTree(new byte[] {'2'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree);
+ }
+ }).build();
+ RevCommit commit = remote.commit(rootTree);
+
+ DeepTreePreparator() throws Exception {}
+ }
+
+ private void uploadV2WithTreeDepthFilter(
+ long depth, ObjectId... wants) throws Exception {
+ server.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ List<String> input = new ArrayList<>();
+ input.add("command=fetch\n");
+ input.add(PacketLineIn.delimiter());
+ for (ObjectId want : wants) {
+ input.add("want " + want.getName() + "\n");
+ }
+ input.add("filter tree:" + depth + "\n");
+ input.add("done\n");
+ input.add(PacketLineIn.end());
+ ByteArrayInputStream recvStream =
+ uploadPackV2(RequestPolicy.ANY, /*refFilter=*/null,
+ /*hook=*/null, input.toArray(new String[0]));
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ }
+
+ @Test
+ public void testV2FetchFilterTreeDepth0() throws Exception {
+ DeepTreePreparator preparator = new DeepTreePreparator();
+ remote.update("master", preparator.commit);
+
+ uploadV2WithTreeDepthFilter(0, preparator.commit.toObjectId());
+
+ assertFalse(client.getObjectDatabase()
+ .has(preparator.rootTree.toObjectId()));
+ assertFalse(client.getObjectDatabase()
+ .has(preparator.subtree.toObjectId()));
+ assertFalse(client.getObjectDatabase()
+ .has(preparator.blobLowDepth.toObjectId()));
+ assertFalse(client.getObjectDatabase()
+ .has(preparator.blobHighDepth.toObjectId()));
+ assertEquals(1, stats.getTreesTraversed());
+ }
+
+ @Test
+ public void testV2FetchFilterTreeDepth1_serverHasBitmap() throws Exception {
+ DeepTreePreparator preparator = new DeepTreePreparator();
+ remote.update("master", preparator.commit);
+
+ // The bitmap should be ignored since we need to track the depth while
+ // traversing the trees.
+ generateBitmaps(server);
+
+ uploadV2WithTreeDepthFilter(1, preparator.commit.toObjectId());
+
+ assertTrue(client.getObjectDatabase()
+ .has(preparator.rootTree.toObjectId()));
+ assertFalse(client.getObjectDatabase()
+ .has(preparator.subtree.toObjectId()));
+ assertFalse(client.getObjectDatabase()
+ .has(preparator.blobLowDepth.toObjectId()));
+ assertFalse(client.getObjectDatabase()
+ .has(preparator.blobHighDepth.toObjectId()));
+ assertEquals(1, stats.getTreesTraversed());
+ }
+
+ @Test
+ public void testV2FetchFilterTreeDepth2() throws Exception {
+ DeepTreePreparator preparator = new DeepTreePreparator();
+ remote.update("master", preparator.commit);
+
+ uploadV2WithTreeDepthFilter(2, preparator.commit.toObjectId());
+
+ assertTrue(client.getObjectDatabase()
+ .has(preparator.rootTree.toObjectId()));
+ assertTrue(client.getObjectDatabase()
+ .has(preparator.subtree.toObjectId()));
+ assertTrue(client.getObjectDatabase()
+ .has(preparator.blobLowDepth.toObjectId()));
+ assertFalse(client.getObjectDatabase()
+ .has(preparator.blobHighDepth.toObjectId()));
+ assertEquals(2, stats.getTreesTraversed());
+ }
+
+ /**
+ * Creates a commit with the following files:
+ * <pre>
+ * a/x/b/foo
+ * x/b/foo
+ * </pre>
+ * which has an identical tree in two locations: once at / and once at /a
+ */
+ class RepeatedSubtreePreparator {
+ RevBlob foo = remote.blob("foo");
+ RevTree subtree3 = remote.tree(remote.file("foo", foo));
+ RevTree subtree2 = (new TreeBuilder() {
+ @Override
+ void addElements(DirCacheBuilder dcBuilder) throws Exception {
+ dcBuilder.addTree(new byte[] {'b'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree3);
+ }
+ }).build();
+ RevTree subtree1 = (new TreeBuilder() {
+ @Override
+ void addElements(DirCacheBuilder dcBuilder) throws Exception {
+ dcBuilder.addTree(new byte[] {'x'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree2);
+ }
+ }).build();
+ RevTree rootTree = (new TreeBuilder() {
+ @Override
+ void addElements(DirCacheBuilder dcBuilder) throws Exception {
+ dcBuilder.addTree(new byte[] {'a'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree1);
+ dcBuilder.addTree(new byte[] {'x'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree2);
+ }
+ }).build();
+ RevCommit commit = remote.commit(rootTree);
+
+ RepeatedSubtreePreparator() throws Exception {}
+ }
+
+ @Test
+ public void testV2FetchFilterTreeDepth_iterateOverTreeAtTwoLevels()
+ throws Exception {
+ // Test tree:<depth> where a tree is iterated to twice - once where a
+ // subentry is too deep to be included, and again where the blob inside
+ // it is shallow enough to be included.
+ RepeatedSubtreePreparator preparator = new RepeatedSubtreePreparator();
+ remote.update("master", preparator.commit);
+
+ uploadV2WithTreeDepthFilter(4, preparator.commit.toObjectId());
+
+ assertTrue(client.getObjectDatabase()
+ .has(preparator.foo.toObjectId()));
+ }
+
+ /**
+ * Creates a commit with the following files:
+ * <pre>
+ * a/x/b/foo
+ * b/u/c/baz
+ * y/x/b/foo
+ * z/v/c/baz
+ * </pre>
+ * which has two pairs of identical trees:
+ * <ul>
+ * <li>one at /a and /y
+ * <li>one at /b/u and /z/v
+ * </ul>
+ * Note that this class defines unique 8 trees (rootTree and subtree1-7)
+ * which means PackStatistics should report having visited 8 trees.
+ */
+ class RepeatedSubtreeAtSameLevelPreparator {
+ RevBlob foo = remote.blob("foo");
+
+ /** foo */
+ RevTree subtree1 = remote.tree(remote.file("foo", foo));
+
+ /** b/foo */
+ RevTree subtree2 = (new TreeBuilder() {
+ @Override
+ void addElements(DirCacheBuilder dcBuilder) throws Exception {
+ dcBuilder.addTree(new byte[] {'b'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree1);
+ }
+ }).build();
+
+ /** x/b/foo */
+ RevTree subtree3 = (new TreeBuilder() {
+ @Override
+ void addElements(DirCacheBuilder dcBuilder) throws Exception {
+ dcBuilder.addTree(new byte[] {'x'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree2);
+ }
+ }).build();
+
+ RevBlob baz = remote.blob("baz");
+
+ /** baz */
+ RevTree subtree4 = remote.tree(remote.file("baz", baz));
+
+ /** c/baz */
+ RevTree subtree5 = (new TreeBuilder() {
+ @Override
+ void addElements(DirCacheBuilder dcBuilder) throws Exception {
+ dcBuilder.addTree(new byte[] {'c'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree4);
+ }
+ }).build();
+
+ /** u/c/baz */
+ RevTree subtree6 = (new TreeBuilder() {
+ @Override
+ void addElements(DirCacheBuilder dcBuilder) throws Exception {
+ dcBuilder.addTree(new byte[] {'u'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree5);
+ }
+ }).build();
+
+ /** v/c/baz */
+ RevTree subtree7 = (new TreeBuilder() {
+ @Override
+ void addElements(DirCacheBuilder dcBuilder) throws Exception {
+ dcBuilder.addTree(new byte[] {'v'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree5);
+ }
+ }).build();
+
+ RevTree rootTree = (new TreeBuilder() {
+ @Override
+ void addElements(DirCacheBuilder dcBuilder) throws Exception {
+ dcBuilder.addTree(new byte[] {'a'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree3);
+ dcBuilder.addTree(new byte[] {'b'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree6);
+ dcBuilder.addTree(new byte[] {'y'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree3);
+ dcBuilder.addTree(new byte[] {'z'}, DirCacheEntry.STAGE_0,
+ remote.getRevWalk().getObjectReader(), subtree7);
+ }
+ }).build();
+ RevCommit commit = remote.commit(rootTree);
+
+ RepeatedSubtreeAtSameLevelPreparator() throws Exception {}
+ }
+
+ @Test
+ public void testV2FetchFilterTreeDepth_repeatTreeAtSameLevelIncludeFile()
+ throws Exception {
+ RepeatedSubtreeAtSameLevelPreparator preparator =
+ new RepeatedSubtreeAtSameLevelPreparator();
+ remote.update("master", preparator.commit);
+
+ uploadV2WithTreeDepthFilter(5, preparator.commit.toObjectId());
+
+ assertTrue(client.getObjectDatabase()
+ .has(preparator.foo.toObjectId()));
+ assertTrue(client.getObjectDatabase()
+ .has(preparator.baz.toObjectId()));
+ assertEquals(8, stats.getTreesTraversed());
+ }
+
+ @Test
+ public void testV2FetchFilterTreeDepth_repeatTreeAtSameLevelExcludeFile()
+ throws Exception {
+ RepeatedSubtreeAtSameLevelPreparator preparator =
+ new RepeatedSubtreeAtSameLevelPreparator();
+ remote.update("master", preparator.commit);
+
+ uploadV2WithTreeDepthFilter(4, preparator.commit.toObjectId());
+
+ assertFalse(client.getObjectDatabase()
+ .has(preparator.foo.toObjectId()));
+ assertFalse(client.getObjectDatabase()
+ .has(preparator.baz.toObjectId()));
+ assertEquals(8, stats.getTreesTraversed());
+ }
+
+ @Test
+ public void testWantFilteredObject() throws Exception {
+ RepeatedSubtreePreparator preparator = new RepeatedSubtreePreparator();
+ remote.update("master", preparator.commit);
+
+ // Specify wanted blob objects that are deep enough to be filtered. We
+ // should still upload them.
+ uploadV2WithTreeDepthFilter(
+ 3,
+ preparator.commit.toObjectId(),
+ preparator.foo.toObjectId());
+ assertTrue(client.getObjectDatabase()
+ .has(preparator.foo.toObjectId()));
+
+ client = newRepo("client");
+ // Specify a wanted tree object that is deep enough to be filtered. We
+ // should still upload it.
+ uploadV2WithTreeDepthFilter(
+ 2,
+ preparator.commit.toObjectId(),
+ preparator.subtree3.toObjectId());
+ assertTrue(client.getObjectDatabase()
+ .has(preparator.foo.toObjectId()));
+ assertTrue(client.getObjectDatabase()
+ .has(preparator.subtree3.toObjectId()));
+ }
+
@Test
public void testV2FetchFilterWhenNotAllowed() throws Exception {
RevCommit commit = remote.commit().message("0").create();
@@ -1562,11 +1848,11 @@ public class UploadPackTest {
thrown.expectMessage("unexpected filter blob:limit=5");
uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want " + commit.toObjectId().getName() + "\n",
"filter blob:limit=5\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
}
@Test
@@ -1577,10 +1863,10 @@ public class UploadPackTest {
try {
uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want-ref refs/heads/one\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
} catch (PackProtocolException e) {
assertThat(
e.getMessage(),
@@ -1603,11 +1889,11 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want-ref refs/heads/one\n",
"want-ref refs/heads/two\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("wanted-refs"));
assertThat(
@@ -1615,7 +1901,7 @@ public class UploadPackTest {
hasItems(
one.toObjectId().getName() + " refs/heads/one",
two.toObjectId().getName() + " refs/heads/two"));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1634,11 +1920,11 @@ public class UploadPackTest {
try {
uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want-ref refs/heads/one\n",
"want-ref refs/heads/nonExistentRef\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
} catch (PackProtocolException e) {
assertThat(
e.getMessage(),
@@ -1661,17 +1947,17 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want-ref refs/heads/one\n",
"want " + two.toObjectId().getName() + "\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("wanted-refs"));
assertThat(
pckIn.readString(),
is(one.toObjectId().getName() + " refs/heads/one"));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1689,11 +1975,11 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want-ref refs/heads/one\n",
"have " + one.toObjectId().getName(),
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
// The client still needs to know the hash of the object that
@@ -1703,7 +1989,7 @@ public class UploadPackTest {
assertThat(
pckIn.readString(),
is(one.toObjectId().getName() + " refs/heads/one"));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
// ... but the client does not need the object itself.
assertThat(pckIn.readString(), is("packfile"));
@@ -1721,20 +2007,20 @@ public class UploadPackTest {
ByteArrayInputStream recvStream = uploadPackV2(
"command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want-ref refs/heads/branch1\n",
"deepen 1\n",
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
// shallow-info appears first, then wanted-refs.
assertThat(pckIn.readString(), is("shallow-info"));
assertThat(pckIn.readString(), is("shallow " + child.toObjectId().getName()));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("wanted-refs"));
assertThat(pckIn.readString(), is(child.toObjectId().getName() + " refs/heads/branch1"));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
assertTrue(client.getObjectDatabase().has(child.toObjectId()));
@@ -1752,13 +2038,13 @@ public class UploadPackTest {
true);
ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n",
- PacketLineIn.DELIM,
+ PacketLineIn.delimiter(),
"want-ref refs/heads/three\n",
"deepen 3",
"shallow 0123012301230123012301230123012301230123",
"shallow " + two.getName() + '\n',
"done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("shallow-info"));
@@ -1766,11 +2052,11 @@ public class UploadPackTest {
is("shallow " + one.toObjectId().getName()));
assertThat(pckIn.readString(),
is("unshallow " + two.toObjectId().getName()));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("wanted-refs"));
assertThat(pckIn.readString(),
is(three.toObjectId().getName() + " refs/heads/three"));
- assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
assertThat(pckIn.readString(), is("packfile"));
parsePack(recvStream);
@@ -1787,7 +2073,7 @@ public class UploadPackTest {
UploadPack up = new UploadPack(server);
ByteArrayInputStream send = linesAsInputStream(
"want " + one.getName() + " agent=JGit-test/1.2.3\n",
- PacketLineIn.END,
+ PacketLineIn.end(),
"have 11cedf1b796d44207da702f7d420684022fc0f09\n", "done\n");
ByteArrayOutputStream recv = new ByteArrayOutputStream();
@@ -1808,9 +2094,9 @@ public class UploadPackTest {
ByteArrayInputStream send = linesAsInputStream(
"command=fetch\n", "agent=JGit-test/1.2.4\n",
- PacketLineIn.DELIM, "want " + one.getName() + "\n",
+ PacketLineIn.delimiter(), "want " + one.getName() + "\n",
"have 11cedf1b796d44207da702f7d420684022fc0f09\n", "done\n",
- PacketLineIn.END);
+ PacketLineIn.end());
ByteArrayOutputStream recv = new ByteArrayOutputStream();
up.upload(send, recv, null);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
index 754341dfea..a3ce4ae94f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
@@ -584,26 +584,23 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
}
}
- private final FileTreeIterator.FileModeStrategy NO_GITLINKS_STRATEGY =
- new FileTreeIterator.FileModeStrategy() {
- @Override
- public FileMode getMode(File f, FS.Attributes attributes) {
- if (attributes.isSymbolicLink()) {
- return FileMode.SYMLINK;
- } else if (attributes.isDirectory()) {
- // NOTE: in the production DefaultFileModeStrategy, there is
- // a check here for a subdirectory called '.git', and if it
- // exists, we create a GITLINK instead of recursing into the
- // tree. In this custom strategy, we ignore nested git dirs
- // and treat all directories the same.
- return FileMode.TREE;
- } else if (attributes.isExecutable()) {
- return FileMode.EXECUTABLE_FILE;
- } else {
- return FileMode.REGULAR_FILE;
- }
- }
- };
+ private final FileTreeIterator.FileModeStrategy NO_GITLINKS_STRATEGY = (
+ File f, FS.Attributes attributes) -> {
+ if (attributes.isSymbolicLink()) {
+ return FileMode.SYMLINK;
+ } else if (attributes.isDirectory()) {
+ // NOTE: in the production DefaultFileModeStrategy, there is
+ // a check here for a subdirectory called '.git', and if it
+ // exists, we create a GITLINK instead of recursing into the
+ // tree. In this custom strategy, we ignore nested git dirs
+ // and treat all directories the same.
+ return FileMode.TREE;
+ } else if (attributes.isExecutable()) {
+ return FileMode.EXECUTABLE_FILE;
+ } else {
+ return FileMode.REGULAR_FILE;
+ }
+ };
private Repository createNestedRepo() throws IOException {
File gitdir = createUniqueTestGitDir(false);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java
index c0f4965668..9ee9613f79 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java
@@ -137,7 +137,6 @@ public class FileUtilsTest {
}
@Test
-
public void testDeleteRecursiveEmpty() throws IOException {
File f1 = new File(trash, "test/test/a");
File f2 = new File(trash, "test/a");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java
new file mode 100644
index 0000000000..da59533aeb
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/LRUMapTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2018, Konrad Windszus <konrad_w@gmx.de>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.util;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.hamcrest.collection.IsIterableContainingInOrder;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class LRUMapTest {
+
+ @SuppressWarnings("boxing")
+ @Test
+ public void testLRUEntriesAreEvicted() {
+ Map<Integer, Integer> map = new LRUMap<>(3, 3);
+ for (int i = 0; i < 3; i++) {
+ map.put(i, i);
+ }
+ // access the last ones
+ map.get(2);
+ map.get(0);
+
+ // put another one which exceeds the limit (entry with key "1" is
+ // evicted)
+ map.put(3, 3);
+
+ Map<Integer, Integer> expectedMap = new LinkedHashMap<>();
+ expectedMap.put(2, 2);
+ expectedMap.put(0, 0);
+ expectedMap.put(3, 3);
+
+ Assert.assertThat(map.entrySet(),
+ IsIterableContainingInOrder
+ .contains(expectedMap.entrySet().toArray()));
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java
index d124d7365c..9981bd6514 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RefListTest.java
@@ -128,6 +128,41 @@ public class RefListTest {
}
@Test
+ public void testBuilder_AddThenDedupe() {
+ RefList.Builder<Ref> builder = new RefList.Builder<>(1);
+ builder.add(REF_B);
+ builder.add(REF_A);
+ builder.add(REF_A);
+ builder.add(REF_B);
+ builder.add(REF_c);
+
+ builder.sort();
+ builder.dedupe((a, b) -> b);
+ RefList<Ref> list = builder.toRefList();
+
+ assertEquals(3, list.size());
+ assertSame(REF_A, list.get(0));
+ assertSame(REF_B, list.get(1));
+ assertSame(REF_c, list.get(2));
+ }
+
+ @Test
+ public void testBuilder_AddThenDedupe_Border() {
+ RefList.Builder<Ref> builder = new RefList.Builder<>(1);
+ builder.sort();
+ builder.dedupe((a, b) -> b);
+ RefList<Ref> list = builder.toRefList();
+ assertTrue(list.isEmpty());
+
+ builder = new RefList.Builder<>(1);
+ builder.add(REF_A);
+ builder.sort();
+ builder.dedupe((a, b) -> b);
+ list = builder.toRefList();
+ assertEquals(1, list.size());
+ }
+
+ @Test
public void testBuilder_AddAll() {
RefList.Builder<Ref> builder = new RefList.Builder<>(1);
Ref[] src = { REF_A, REF_B, REF_c, REF_A };
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/http/HttpCookiesMatcher.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/http/HttpCookiesMatcher.java
new file mode 100644
index 0000000000..8c5b127de2
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/http/HttpCookiesMatcher.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2018, Konrad Windszus <konrad_w@gmx.de>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.util.http;
+
+import java.net.HttpCookie;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.hamcrest.collection.IsIterableContainingInOrder;
+
+public final class HttpCookiesMatcher {
+ public static Matcher<Iterable<? extends HttpCookie>> containsInOrder(
+ Iterable<HttpCookie> expectedCookies) {
+ return containsInOrder(expectedCookies, 0);
+ }
+
+ public static Matcher<Iterable<? extends HttpCookie>> containsInOrder(
+ Iterable<HttpCookie> expectedCookies, int allowedMaxAgeDelta) {
+ final List<Matcher<? super HttpCookie>> cookieMatchers = new LinkedList<>();
+ for (HttpCookie cookie : expectedCookies) {
+ cookieMatchers
+ .add(new HttpCookieMatcher(cookie, allowedMaxAgeDelta));
+ }
+ return new IsIterableContainingInOrder<>(cookieMatchers);
+ }
+
+ /**
+ * The default {@link HttpCookie#equals(Object)} is not good enough for
+ * testing purposes. Also the {@link HttpCookie#toString()} only emits some
+ * of the cookie attributes. For testing a dedicated matcher is needed which
+ * takes into account all attributes.
+ */
+ private static final class HttpCookieMatcher
+ extends TypeSafeMatcher<HttpCookie> {
+
+ private final HttpCookie cookie;
+
+ private final int allowedMaxAgeDelta;
+
+ public HttpCookieMatcher(HttpCookie cookie, int allowedMaxAgeDelta) {
+ this.cookie = cookie;
+ this.allowedMaxAgeDelta = allowedMaxAgeDelta;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ describeCookie(description, cookie);
+ }
+
+ @Override
+ protected void describeMismatchSafely(HttpCookie item,
+ Description mismatchDescription) {
+ mismatchDescription.appendText("was ");
+ describeCookie(mismatchDescription, item);
+ }
+
+ @Override
+ protected boolean matchesSafely(HttpCookie otherCookie) {
+ // the equals method in HttpCookie is not specific enough, we want
+ // to consider all attributes!
+ return (equals(cookie.getName(), otherCookie.getName())
+ && equals(cookie.getValue(), otherCookie.getValue())
+ && equals(cookie.getDomain(), otherCookie.getDomain())
+ && equals(cookie.getPath(), otherCookie.getPath())
+ && (cookie.getMaxAge() >= otherCookie.getMaxAge()
+ - allowedMaxAgeDelta)
+ && (cookie.getMaxAge() <= otherCookie.getMaxAge()
+ + allowedMaxAgeDelta)
+ && cookie.isHttpOnly() == otherCookie.isHttpOnly()
+ && cookie.getSecure() == otherCookie.getSecure()
+ && cookie.getVersion() == otherCookie.getVersion());
+ }
+
+ private static boolean equals(String value1, String value2) {
+ if (value1 == null && value2 == null) {
+ return true;
+ }
+ if (value1 == null || value2 == null) {
+ return false;
+ }
+ return value1.equals(value2);
+ }
+
+ @SuppressWarnings("boxing")
+ protected static void describeCookie(Description description,
+ HttpCookie cookie) {
+ description.appendText("HttpCookie[");
+ description.appendText("name: ").appendValue(cookie.getName())
+ .appendText(", ");
+ description.appendText("value: ").appendValue(cookie.getValue())
+ .appendText(", ");
+ description.appendText("domain: ").appendValue(cookie.getDomain())
+ .appendText(", ");
+ description.appendText("path: ").appendValue(cookie.getPath())
+ .appendText(", ");
+ description.appendText("maxAge: ").appendValue(cookie.getMaxAge())
+ .appendText(", ");
+ description.appendText("httpOnly: ")
+ .appendValue(cookie.isHttpOnly()).appendText(", ");
+ description.appendText("secure: ").appendValue(cookie.getSecure())
+ .appendText(", ");
+ description.appendText("version: ").appendValue(cookie.getVersion())
+ .appendText(", ");
+ description.appendText("]");
+ }
+ }
+} \ No newline at end of file

Back to the top