aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/META-INF/MANIFEST.MF112
-rw-r--r--org.eclipse.jgit.test/build.properties3
-rw-r--r--org.eclipse.jgit.test/pom.xml6
-rw-r--r--org.eclipse.jgit.test/tests.bzl3
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/log4j.properties14
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/simplelogger.properties12
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java28
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java70
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java12
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java133
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java103
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java20
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackConnectionTest.java24
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackPushConnectionTest.java96
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ObjectIdMatcher.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java149
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java30
18 files changed, 711 insertions, 108 deletions
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
index 2fba2d3c7d..8a0babdb8e 100644
--- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Automatic-Module-Name: org.eclipse.jgit.test
Bundle-SymbolicName: org.eclipse.jgit.test
-Bundle-Version: 5.12.1.qualifier
+Bundle-Version: 5.13.1.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %Bundle-Vendor
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
@@ -16,59 +16,61 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
org.apache.commons.compress.compressors.gzip;version="[1.15.0,2.0)",
org.apache.commons.compress.compressors.xz;version="[1.15.0,2.0)",
org.assertj.core.api;version="[3.14.0,4.0.0)",
- org.eclipse.jgit.annotations;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.api;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.api.errors;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.archive;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.attributes;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.awtui;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.blame;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.diff;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.dircache;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.errors;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.events;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.fnmatch;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.gitrepo;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.hooks;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.ignore;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.ignore.internal;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal.fsck;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal.revwalk;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal.storage.dfs;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal.storage.file;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal.storage.io;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal.storage.pack;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal.storage.reftable;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal.transport.connectivity;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal.transport.http;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.internal.transport.parser;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.junit;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.junit.time;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.lfs;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.lib;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.lib.internal;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.logging;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.merge;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.nls;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.notes;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.patch;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.pgm;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.pgm.internal;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.revplot;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.revwalk;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.revwalk.filter;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.storage.file;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.storage.pack;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.submodule;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.transport;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.transport.http;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.transport.resolver;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.treewalk;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.treewalk.filter;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.util;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.util.io;version="[5.12.1,5.13.0)",
- org.eclipse.jgit.util.sha1;version="[5.12.1,5.13.0)",
+ org.eclipse.jgit.annotations;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.api;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.api.errors;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.archive;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.attributes;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.awtui;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.blame;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.diff;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.dircache;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.errors;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.events;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.fnmatch;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.gitrepo;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.hooks;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.ignore;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.ignore.internal;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal.fsck;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal.revwalk;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal.storage.dfs;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal.storage.io;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal.storage.pack;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal.storage.reftable;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal.transport.connectivity;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal.transport.http;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.internal.transport.parser;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.junit;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.junit.time;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.lfs;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.lib;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.lib.internal;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.logging;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.merge;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.nls;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.notes;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.patch;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.pgm;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.pgm.internal;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.revplot;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.revwalk;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.revwalk.filter;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.storage.file;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.storage.pack;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.submodule;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.transport;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.transport.http;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.transport.resolver;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.treewalk;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.util;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.util.io;version="[5.13.1,5.14.0)",
+ org.eclipse.jgit.util.sha1;version="[5.13.1,5.14.0)",
+ org.hamcrest;version="[1.1.0,3.0.0)",
+ org.hamcrest.collection;version="[1.1.0,3.0.0)",
org.junit;version="[4.13,5.0.0)",
org.junit.experimental.theories;version="[4.13,5.0.0)",
org.junit.function;version="[4.13.0,5.0.0)",
@@ -82,5 +84,3 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
org.objenesis;version="[2.6.0,3.0.0)",
org.slf4j;version="[1.7.0,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)"
diff --git a/org.eclipse.jgit.test/build.properties b/org.eclipse.jgit.test/build.properties
index b527a74790..212c8bd4d7 100644
--- a/org.eclipse.jgit.test/build.properties
+++ b/org.eclipse.jgit.test/build.properties
@@ -7,5 +7,4 @@ bin.includes = META-INF/,\
plugin.properties,\
bin-tst/,\
bin/
-additional.bundles = org.apache.log4j,\
- org.slf4j.binding.log4j12
+additional.bundles = org.slf4j.binding.simple
diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml
index 3224e991e7..ddd1b7e05e 100644
--- a/org.eclipse.jgit.test/pom.xml
+++ b/org.eclipse.jgit.test/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit-parent</artifactId>
- <version>5.12.1-SNAPSHOT</version>
+ <version>5.13.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jgit.test</artifactId>
@@ -60,9 +60,9 @@
<dependency>
<groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-library</artifactId>
+ <artifactId>hamcrest</artifactId>
<scope>test</scope>
- <version>[1.1.0,2.0.0)</version>
+ <version>${hamcrest-version}</version>
</dependency>
<dependency>
diff --git a/org.eclipse.jgit.test/tests.bzl b/org.eclipse.jgit.test/tests.bzl
index 34df07d5e6..e201bdbcb3 100644
--- a/org.eclipse.jgit.test/tests.bzl
+++ b/org.eclipse.jgit.test/tests.bzl
@@ -36,7 +36,7 @@ def tests(tests):
]
if src.endswith("SecurityManagerMissingPermissionsTest.java"):
additional_deps = [
- "//lib:log4j",
+ "//lib:slf4j-simple",
]
if src.endswith("JDKHttpConnectionTest.java"):
additional_deps = [
@@ -68,6 +68,7 @@ def tests(tests):
"//lib:javaewah",
"//lib:junit",
"//lib:slf4j-api",
+ "//lib:slf4j-simple",
"//org.eclipse.jgit:jgit",
"//org.eclipse.jgit.junit:junit",
"//org.eclipse.jgit.lfs:jgit-lfs",
diff --git a/org.eclipse.jgit.test/tst-rsrc/log4j.properties b/org.eclipse.jgit.test/tst-rsrc/log4j.properties
deleted file mode 100644
index 856a731ab9..0000000000
--- a/org.eclipse.jgit.test/tst-rsrc/log4j.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-
-# Root logger option
-log4j.rootLogger=INFO, stdout
-
-# Direct log messages to stdout
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.Target=System.out
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
-log4j.appender.fileLogger.bufferedIO = true
-log4j.appender.fileLogger.bufferSize = 4096
-
-#log4j.logger.org.eclipse.jgit.util.FS = DEBUG
-#log4j.logger.org.eclipse.jgit.internal.storage.file.FileSnapshot = DEBUG
diff --git a/org.eclipse.jgit.test/tst-rsrc/simplelogger.properties b/org.eclipse.jgit.test/tst-rsrc/simplelogger.properties
index 011b2f8bb0..235fea21ac 100644
--- a/org.eclipse.jgit.test/tst-rsrc/simplelogger.properties
+++ b/org.eclipse.jgit.test/tst-rsrc/simplelogger.properties
@@ -1,9 +1,9 @@
-org.slf4j.simpleLogger.logFile = System.err
-org.slf4j.simpleLogger.cacheOutputStream = true
-org.slf4j.simpleLogger.defaultLogLevel = info
-org.slf4j.simpleLogger.showDateTime = true
-org.slf4j.simpleLogger.dateTimeFormat = HH:mm:ss.SSSXXX
-org.slf4j.simpleLogger.showThreadName = true
+org.slf4j.simpleLogger.defaultLogLevel=info
+org.slf4j.simpleLogger.logFile=System.err
+org.slf4j.simpleLogger.showDateTime=true
+org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss
+org.slf4j.simpleLogger.showThreadName=true
+org.slf4j.simpleLogger.showLogName=true
#org.slf4j.simpleLogger.log.org.eclipse.jgit.util.FS = debug
#org.slf4j.simpleLogger.log.org.eclipse.jgit.internal.storage.file.FileSnapshot = debug
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java
index a07f37009e..d0fbdbd090 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/SecurityManagerMissingPermissionsTest.java
@@ -13,17 +13,15 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
-import java.io.StringWriter;
+import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.Policy;
import java.util.Collections;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.apache.log4j.WriterAppender;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.util.FileUtils;
import org.junit.After;
@@ -38,25 +36,21 @@ public class SecurityManagerMissingPermissionsTest extends RepositoryTestCase {
/**
* Collects all logging sent to the logging system.
*/
- private final StringWriter errorOutputWriter = new StringWriter();
-
- /**
- * Appender to intercept all logging sent to the logging system.
- */
- private WriterAppender appender;
+ private final ByteArrayOutputStream errorOutput = new ByteArrayOutputStream();
private SecurityManager originalSecurityManager;
+ private PrintStream defaultErrorOutput;
+
@Override
@Before
public void setUp() throws Exception {
originalSecurityManager = System.getSecurityManager();
- appender = new WriterAppender(
- new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN),
- errorOutputWriter);
-
- Logger.getRootLogger().addAppender(appender);
+ // slf4j-simple logs to System.err, redirect it to enable asserting
+ // logged errors
+ defaultErrorOutput = System.err;
+ System.setErr(new PrintStream(errorOutput));
refreshPolicyAllPermission(Policy.getPolicy());
System.setSecurityManager(new SecurityManager());
@@ -85,14 +79,14 @@ public class SecurityManagerMissingPermissionsTest extends RepositoryTestCase {
addRepoToClose(git.getRepository());
- assertEquals("", errorOutputWriter.toString());
+ assertEquals("", errorOutput.toString());
}
@Override
@After
public void tearDown() throws Exception {
System.setSecurityManager(originalSecurityManager);
- Logger.getRootLogger().removeAppender(appender);
+ System.setErr(defaultErrorOutput);
super.tearDown();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
index 62824d3aec..b694f4aaf7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, 2020 Google Inc. and others
+ * Copyright (C) 2010, 2021 Google Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -18,6 +18,8 @@ import static org.junit.Assert.assertTrue;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.Status;
@@ -34,8 +36,12 @@ import org.eclipse.jgit.patch.FileHeader;
import org.eclipse.jgit.patch.HunkHeader;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig;
+import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.FileTreeIterator;
+import org.eclipse.jgit.treewalk.filter.OrTreeFilter;
import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.eclipse.jgit.treewalk.filter.PathSuffixFilter;
+import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.jgit.util.io.DisabledOutputStream;
@@ -492,6 +498,68 @@ public class DiffFormatterTest extends RepositoryTestCase {
}
@Test
+ public void testFilter() throws Exception {
+ RevCommit parent;
+ RevCommit head;
+ try (Git git = new Git(db)) {
+ writeTrashFile("foo.txt", "foo\n");
+ writeTrashFile("src/some.txt", "some\n");
+ writeTrashFile("src/image.png", "image\n");
+ writeTrashFile("src/test.pdf", "test\n");
+ writeTrashFile("src/xyz.txt", "xyz\n");
+ git.add().addFilepattern(".").call();
+ parent = git.commit().setMessage("initial").call();
+ writeTrashFile("foo.txt", "FOO\n");
+ writeTrashFile("src/some.txt", "SOME\n");
+ writeTrashFile("src/image.png", "IMAGE\n");
+ writeTrashFile("src/test.pdf", "TEST\n");
+ writeTrashFile("src/xyz.txt", "XYZ\n");
+ git.add().addFilepattern(".").call();
+ head = git.commit().setMessage("second").call();
+ }
+ try (ByteArrayOutputStream os = new ByteArrayOutputStream();
+ DiffFormatter dfmt = new DiffFormatter(os)) {
+ dfmt.setRepository(db);
+ List<TreeFilter> skip = new ArrayList<>();
+ skip.add(PathSuffixFilter.create(".png"));
+ skip.add(PathSuffixFilter.create(".pdf"));
+ dfmt.setPathFilter(OrTreeFilter.create(skip).negate());
+ dfmt.format(
+ new CanonicalTreeParser(null, db.newObjectReader(),
+ parent.getTree()),
+ new CanonicalTreeParser(null, db.newObjectReader(),
+ head.getTree()));
+ dfmt.flush();
+
+ String actual = os.toString("UTF-8");
+
+ String expected = "diff --git a/foo.txt b/foo.txt\n"
+ + "index 257cc56..b7d6715 100644\n"
+ + "--- a/foo.txt\n"
+ + "+++ b/foo.txt\n"
+ + "@@ -1 +1 @@\n"
+ + "-foo\n"
+ + "+FOO\n"
+ + "diff --git a/src/some.txt b/src/some.txt\n"
+ + "index 363ef61..76cea5f 100644\n"
+ + "--- a/src/some.txt\n"
+ + "+++ b/src/some.txt\n"
+ + "@@ -1 +1 @@\n"
+ + "-some\n"
+ + "+SOME\n"
+ + "diff --git a/src/xyz.txt b/src/xyz.txt\n"
+ + "index cd470e6..d4e3ab0 100644\n"
+ + "--- a/src/xyz.txt\n"
+ + "+++ b/src/xyz.txt\n"
+ + "@@ -1 +1 @@\n"
+ + "-xyz\n"
+ + "+XYZ\n";
+
+ assertEquals(expected, actual);
+ }
+ }
+
+ @Test
public void testTrackedFileInIgnoredFolderChanged()
throws Exception {
String expectedDiff = "diff --git a/empty/empty/foo b/empty/empty/foo\n"
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java
index 509935dfb9..7eab1dcb09 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java
@@ -200,4 +200,16 @@ public class LockFileTest extends RepositoryTestCase {
assertFalse(lock.isLocked());
checkFile(f, "contentother");
}
+
+ @Test
+ public void testUnlockNoop() throws Exception {
+ File f = writeTrashFile("somefile", "content");
+ try {
+ LockFile lock = new LockFile(f);
+ lock.unlock();
+ lock.unlock();
+ } catch (Throwable e) {
+ fail("unlock should be noop if not locked at all.");
+ }
+ }
}
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 e422ab9db3..71aca9d80c 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
@@ -18,6 +18,10 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -25,6 +29,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -32,6 +37,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.internal.storage.file.PackIndex.MutableEntry;
import org.eclipse.jgit.internal.storage.pack.PackExt;
@@ -43,6 +49,7 @@ import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdSet;
import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.Sets;
import org.eclipse.jgit.revwalk.DepthWalk;
@@ -58,6 +65,7 @@ import org.eclipse.jgit.transport.PackParser;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
public class PackWriterTest extends SampleDataRepositoryTestCase {
@@ -626,6 +634,131 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
}
}
+ @Test
+ public void testTotalPackFilesScanWhenSearchForReuseTimeoutNotSet()
+ throws Exception {
+ FileRepository fileRepository = setUpRepoWithMultiplePackfiles();
+ PackWriter mockedPackWriter = Mockito
+ .spy(new PackWriter(config, fileRepository.newObjectReader()));
+
+ doNothing().when(mockedPackWriter).select(any(), any());
+
+ try (FileOutputStream packOS = new FileOutputStream(
+ getPackFileToWrite(fileRepository, mockedPackWriter))) {
+ mockedPackWriter.writePack(NullProgressMonitor.INSTANCE,
+ NullProgressMonitor.INSTANCE, packOS);
+ }
+
+ long numberOfPackFiles = new GC(fileRepository)
+ .getStatistics().numberOfPackFiles;
+ int expectedSelectCalls =
+ // Objects contained in multiple packfiles * number of packfiles
+ 2 * (int) numberOfPackFiles +
+ // Objects in single packfile
+ 1;
+ verify(mockedPackWriter, times(expectedSelectCalls)).select(any(),
+ any());
+ }
+
+ @Test
+ public void testTotalPackFilesScanWhenSkippingSearchForReuseTimeoutCheck()
+ throws Exception {
+ FileRepository fileRepository = setUpRepoWithMultiplePackfiles();
+ PackConfig packConfig = new PackConfig();
+ packConfig.setSearchForReuseTimeout(Duration.ofSeconds(-1));
+ PackWriter mockedPackWriter = Mockito.spy(
+ new PackWriter(packConfig, fileRepository.newObjectReader()));
+
+ doNothing().when(mockedPackWriter).select(any(), any());
+
+ try (FileOutputStream packOS = new FileOutputStream(
+ getPackFileToWrite(fileRepository, mockedPackWriter))) {
+ mockedPackWriter.writePack(NullProgressMonitor.INSTANCE,
+ NullProgressMonitor.INSTANCE, packOS);
+ }
+
+ long numberOfPackFiles = new GC(fileRepository)
+ .getStatistics().numberOfPackFiles;
+ int expectedSelectCalls =
+ // Objects contained in multiple packfiles * number of packfiles
+ 2 * (int) numberOfPackFiles +
+ // Objects contained in single packfile
+ 1;
+ verify(mockedPackWriter, times(expectedSelectCalls)).select(any(),
+ any());
+ }
+
+ @Test
+ public void testPartialPackFilesScanWhenDoingSearchForReuseTimeoutCheck()
+ throws Exception {
+ FileRepository fileRepository = setUpRepoWithMultiplePackfiles();
+ PackConfig packConfig = new PackConfig();
+ packConfig.setSearchForReuseTimeout(Duration.ofSeconds(-1));
+ PackWriter mockedPackWriter = Mockito.spy(
+ new PackWriter(packConfig, fileRepository.newObjectReader()));
+ mockedPackWriter.enableSearchForReuseTimeout();
+
+ doNothing().when(mockedPackWriter).select(any(), any());
+
+ try (FileOutputStream packOS = new FileOutputStream(
+ getPackFileToWrite(fileRepository, mockedPackWriter))) {
+ mockedPackWriter.writePack(NullProgressMonitor.INSTANCE,
+ NullProgressMonitor.INSTANCE, packOS);
+ }
+
+ int expectedSelectCalls = 3; // Objects in packfiles
+ verify(mockedPackWriter, times(expectedSelectCalls)).select(any(),
+ any());
+ }
+
+ /**
+ * Creates objects and packfiles in the following order:
+ * <ul>
+ * <li>Creates 2 objects (C1 = commit, T1 = tree)
+ * <li>Creates packfile P1 (containing C1, T1)
+ * <li>Creates 1 object (C2 commit)
+ * <li>Creates packfile P2 (containing C1, T1, C2)
+ * <li>Create 1 object (C3 commit)
+ * </ul>
+ *
+ * @throws Exception
+ */
+ private FileRepository setUpRepoWithMultiplePackfiles() throws Exception {
+ FileRepository fileRepository = createWorkRepository();
+ try (Git git = new Git(fileRepository)) {
+ // Creates 2 objects (C1 = commit, T1 = tree)
+ git.commit().setMessage("First commit").call();
+ GC gc = new GC(fileRepository);
+ gc.setPackExpireAgeMillis(Long.MAX_VALUE);
+ gc.setExpireAgeMillis(Long.MAX_VALUE);
+ // Creates packfile P1 (containing C1, T1)
+ gc.gc();
+ // Creates 1 object (C2 commit)
+ git.commit().setMessage("Second commit").call();
+ // Creates packfile P2 (containing C1, T1, C2)
+ gc.gc();
+ // Create 1 object (C3 commit)
+ git.commit().setMessage("Third commit").call();
+ }
+ return fileRepository;
+ }
+
+ private PackFile getPackFileToWrite(FileRepository fileRepository,
+ PackWriter mockedPackWriter) throws IOException {
+ File packdir = fileRepository.getObjectDatabase().getPackDirectory();
+ PackFile packFile = new PackFile(packdir,
+ mockedPackWriter.computeName(), PackExt.PACK);
+
+ Set<ObjectId> all = new HashSet<>();
+ for (Ref r : fileRepository.getRefDatabase().getRefs()) {
+ all.add(r.getObjectId());
+ }
+
+ mockedPackWriter.preparePack(NullProgressMonitor.INSTANCE, all,
+ PackWriter.NONE);
+ return packFile;
+ }
+
private FileRepository setupRepoForShallowFetch() throws Exception {
FileRepository repo = createBareRepository();
// TestRepository will close the repo, but we need to return an open
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 327b554b48..fe3c1db502 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
@@ -34,6 +34,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.text.MessageFormat;
@@ -50,6 +51,7 @@ import java.util.function.Consumer;
import org.eclipse.jgit.api.MergeCommand.FastForwardMode;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.internal.JGitText;
+import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.merge.MergeConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
@@ -1463,6 +1465,107 @@ public class ConfigTest {
assertEquals("tr ue", parseEscapedValue("tr \\\r\n ue"));
}
+ @Test
+ public void testCommitTemplateEmptyConfig()
+ throws ConfigInvalidException, IOException {
+ // no values defined nowhere
+ Config config = new Config(null);
+ assertNull(config.get(CommitConfig.KEY).getCommitTemplatePath());
+ assertNull(config.get(CommitConfig.KEY).getCommitTemplateContent());
+ }
+
+ @Test
+ public void testCommitTemplateConfig()
+ throws ConfigInvalidException, IOException {
+
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ String expectedTemplatePath = tempFile.getPath();
+
+ Config config = parse(
+ "[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+
+ String templatePath = config.get(CommitConfig.KEY)
+ .getCommitTemplatePath();
+ String commitEncoding = config.get(CommitConfig.KEY)
+ .getCommitEncoding();
+ assertEquals(expectedTemplatePath, templatePath);
+ assertEquals(templateContent,
+ config.get(CommitConfig.KEY).getCommitTemplateContent());
+ assertNull("no commitEncoding has been set so it must be null",
+ commitEncoding);
+ }
+
+ @Test
+ public void testCommitTemplateEncoding()
+ throws ConfigInvalidException, IOException {
+ Config config = new Config(null);
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ String expectedTemplatePath = tempFile.getPath();
+ config = parse("[i18n]\n\tcommitEncoding = utf-8\n"
+ + "[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+ assertEquals(templateContent,
+ config.get(CommitConfig.KEY).getCommitTemplateContent());
+ String commitEncoding = config.get(CommitConfig.KEY)
+ .getCommitEncoding();
+ assertEquals("commitEncoding has been set to utf-8 it must be utf-8",
+ "utf-8", commitEncoding);
+ }
+
+ @Test
+ public void testCommitTemplatePathInHomeDirecory()
+ throws ConfigInvalidException, IOException {
+ Config config = new Config(null);
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ // proper evaluation of the ~/ directory
+ String homeDir = System.getProperty("user.home");
+ File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder",
+ ".tmp", new File(homeDir));
+ tempFileInHomeDirectory.deleteOnExit();
+ JGitTestUtil.write(tempFileInHomeDirectory, templateContent);
+ String expectedTemplatePath = tempFileInHomeDirectory.getPath()
+ .replace(homeDir, "~");
+ config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+ String templatePath = config.get(CommitConfig.KEY)
+ .getCommitTemplatePath();
+ assertEquals(expectedTemplatePath, templatePath);
+ assertEquals(templateContent,
+ config.get(CommitConfig.KEY).getCommitTemplateContent());
+ }
+
+ @Test(expected = ConfigInvalidException.class)
+ public void testCommitTemplateWithInvalidEncoding()
+ throws ConfigInvalidException, IOException {
+ Config config = new Config(null);
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ config = parse("[i18n]\n\tcommitEncoding = invalidEcoding\n"
+ + "[commit]\n\ttemplate = " + tempFile.getPath() + "\n");
+ config.get(CommitConfig.KEY).getCommitTemplateContent();
+ }
+
+ @Test(expected = FileNotFoundException.class)
+ public void testCommitTemplateWithInvalidPath()
+ throws ConfigInvalidException, IOException {
+ Config config = new Config(null);
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ // commit message encoding
+ String expectedTemplatePath = "nonExistingTemplate";
+ config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+ String templatePath = config.get(CommitConfig.KEY)
+ .getCommitTemplatePath();
+ assertEquals(expectedTemplatePath, templatePath);
+ config.get(CommitConfig.KEY).getCommitTemplateContent();
+ }
+
private static void assertValueRoundTrip(String value)
throws ConfigInvalidException {
assertValueRoundTrip(value, value);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java
index 31629f3de9..5cce11aa1f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java
@@ -15,6 +15,7 @@ import static org.junit.Assert.assertNull;
import java.util.Collections;
+import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.treewalk.filter.AndTreeFilter;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
@@ -253,4 +254,23 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase {
assertEquals(0, a.getParentCount());
assertNull(rw.next());
}
+
+ @Test
+ public void testStopWhenPathDisappears() throws Exception {
+ DirCacheEntry file1 = file("src/d1/file1", blob("a"));
+ DirCacheEntry file2 = file("src/d1/file2", blob("a"));
+ DirCacheEntry file3 = file("src/d1/file3", blob("a"));
+ RevCommit a = commit(tree(file1));
+ RevCommit b = commit(tree(file1, file2), a);
+ RevCommit c = commit(tree(file1, file3), a);
+ RevCommit d = commit(tree(file1, file2, file3), b, c);
+ filter("src/d1");
+ markStart(d);
+ rw.setRewriteParents(false);
+
+ assertCommit(d, rw.next());
+ assertCommit(c, rw.next());
+ assertCommit(b, rw.next());
+ assertCommit(a, rw.next());
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackConnectionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackConnectionTest.java
index 7d438c1dd8..505f334905 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackConnectionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackConnectionTest.java
@@ -15,11 +15,15 @@ import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
+import org.eclipse.jgit.errors.NoRemoteRepositoryException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdRef;
@@ -30,6 +34,16 @@ import org.junit.Test;
public class BasePackConnectionTest {
@Test
+ public void testReadAdvertisedRefsShouldThrowExceptionWithOriginalCause() {
+ try (FailingBasePackConnection basePackConnection =
+ new FailingBasePackConnection()) {
+ Exception result = assertThrows(NoRemoteRepositoryException.class,
+ basePackConnection::readAdvertisedRefs);
+ assertEquals(EOFException.class, result.getCause().getClass());
+ }
+ }
+
+ @Test
public void testUpdateWithSymRefsAdds() {
final Ref mainRef = new ObjectIdRef.Unpeeled(Ref.Storage.LOOSE,
"refs/heads/main", ObjectId.fromString(
@@ -244,4 +258,12 @@ public class BasePackConnectionTest {
assertEquals(oidName, headRef.getObjectId().name());
assertEquals(oidName, mainRef.getObjectId().name());
}
-} \ No newline at end of file
+
+ private static class FailingBasePackConnection extends BasePackConnection {
+ FailingBasePackConnection() {
+ super(new TransportLocal(new URIish(),
+ new java.io.File("")));
+ pckIn = new PacketLineIn(new ByteArrayInputStream(new byte[0]));
+ }
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackPushConnectionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackPushConnectionTest.java
new file mode 100644
index 0000000000..cf8c5ffe79
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BasePackPushConnectionTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2022 Darius Jokilehto <darius.jokilehto+os@gmail.com>
+ * Copyright (c) 2022 Antonio Barone <syntonyze@gmail.com>
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.eclipse.jgit.transport;
+
+import org.eclipse.jgit.errors.NoRemoteRepositoryException;
+import org.eclipse.jgit.errors.TransportException;
+import org.eclipse.jgit.internal.JGitText;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+public class BasePackPushConnectionTest {
+ @Test
+ public void testNoRemoteRepository() {
+ NoRemoteRepositoryException openFetchException =
+ new NoRemoteRepositoryException( new URIish(), "not found");
+ IOException ioException = new IOException("not read");
+
+ try (FailingBasePackPushConnection fbppc =
+ new FailingBasePackPushConnection(openFetchException)) {
+ TransportException result = fbppc.noRepository(ioException);
+
+ assertEquals(openFetchException, result);
+ assertThat(Arrays.asList(result.getSuppressed()),
+ hasItem(ioException));
+ }
+ }
+
+ @Test
+ public void testPushNotPermitted() {
+ URIish uri = new URIish();
+ TransportException openFetchException = new TransportException(uri,
+ "a transport exception");
+ IOException ioException = new IOException("not read");
+
+ try (FailingBasePackPushConnection fbppc =
+ new FailingBasePackPushConnection(openFetchException)) {
+ TransportException result = fbppc.noRepository(ioException);
+
+ assertEquals(TransportException.class, result.getClass());
+ assertThat(result.getMessage(),
+ endsWith(JGitText.get().pushNotPermitted));
+ assertEquals(openFetchException, result.getCause());
+ assertThat(Arrays.asList(result.getSuppressed()),
+ hasItem(ioException));
+ }
+ }
+
+ @Test
+ public void testReadAdvertisedRefPropagatesCauseAndSuppressedExceptions() {
+ IOException ioException = new IOException("not read");
+ try (FailingBasePackPushConnection basePackConnection =
+ new FailingBasePackPushConnection(
+ new NoRemoteRepositoryException(
+ new URIish(), "not found", ioException))) {
+ Exception result = assertThrows(NoRemoteRepositoryException.class,
+ basePackConnection::readAdvertisedRefs);
+ assertEquals(ioException, result.getCause());
+ assertThat(Arrays.asList(result.getSuppressed()),
+ hasItem(instanceOf(EOFException.class)));
+ }
+ }
+
+ private static class FailingBasePackPushConnection
+ extends BasePackPushConnection {
+ FailingBasePackPushConnection(TransportException openFetchException) {
+ super(new TransportLocal(new URIish(),
+ new java.io.File("")) {
+ @Override public FetchConnection openFetch()
+ throws TransportException {
+ throw openFetchException;
+ }
+ });
+ pckIn = new PacketLineIn(new ByteArrayInputStream(new byte[0]));
+ }
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ObjectIdMatcher.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ObjectIdMatcher.java
index c3df19a230..77e8afb2b9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ObjectIdMatcher.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ObjectIdMatcher.java
@@ -16,7 +16,6 @@ import java.util.stream.Collectors;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Sets;
import org.hamcrest.Description;
-import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
@@ -59,7 +58,6 @@ class ObjectIdMatcher extends TypeSafeMatcher<Collection<ObjectId>> {
* @return true if examined and specified sets contains exactly the same
* elements.
*/
- @Factory
static Matcher<Collection<ObjectId>> hasOnlyObjectIds(
String... oids) {
return new ObjectIdMatcher(Sets.of(oids));
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 3958de2d93..127711ff91 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
@@ -460,6 +460,8 @@ public class UploadPackTest {
private FetchV2Request fetchRequest;
+ private ObjectInfoRequest objectInfoRequest;
+
@Override
public void onCapabilities(CapabilitiesV2Request req) {
capabilitiesRequest = req;
@@ -474,6 +476,11 @@ public class UploadPackTest {
public void onFetch(FetchV2Request req) {
fetchRequest = req;
}
+
+ @Override
+ public void onObjectInfo(ObjectInfoRequest req) {
+ objectInfoRequest = req;
+ }
}
@Test
@@ -999,6 +1006,108 @@ public class UploadPackTest {
}
@Test
+ public void testV2FetchWithoutWaitForDoneReceivesPackfile()
+ throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
+
+ RevBlob parentBlob = remote.blob(commonInBlob + "a");
+ RevCommit parent = remote
+ .commit(remote.tree(remote.file("foo", parentBlob)));
+ remote.update("branch1", parent);
+
+ RevCommit localParent = null;
+ RevCommit localChild = null;
+ try (TestRepository<InMemoryRepository> local = new TestRepository<>(
+ client)) {
+ RevBlob localParentBlob = local.blob(commonInBlob + "a");
+ localParent = local
+ .commit(local.tree(local.file("foo", localParentBlob)));
+ RevBlob localChildBlob = local.blob(commonInBlob + "b");
+ localChild = local.commit(
+ local.tree(local.file("foo", localChildBlob)), localParent);
+ local.update("branch1", localChild);
+ }
+
+ ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n",
+ PacketLineIn.delimiter(),
+ "have " + localParent.toObjectId().getName() + "\n",
+ "have " + localChild.toObjectId().getName() + "\n",
+ PacketLineIn.end());
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("acknowledgments"));
+ assertThat(Arrays.asList(pckIn.readString()),
+ hasItems("ACK " + parent.toObjectId().getName()));
+ assertThat(pckIn.readString(), is("ready"));
+ assertTrue(PacketLineIn.isDelimiter(pckIn.readString()));
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ }
+
+ @Test
+ public void testV2FetchWithWaitForDoneOnlyDoesNegotiation()
+ throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
+
+ RevBlob parentBlob = remote.blob(commonInBlob + "a");
+ RevCommit parent = remote
+ .commit(remote.tree(remote.file("foo", parentBlob)));
+ remote.update("branch1", parent);
+
+ RevCommit localParent = null;
+ RevCommit localChild = null;
+ try (TestRepository<InMemoryRepository> local = new TestRepository<>(
+ client)) {
+ RevBlob localParentBlob = local.blob(commonInBlob + "a");
+ localParent = local
+ .commit(local.tree(local.file("foo", localParentBlob)));
+ RevBlob localChildBlob = local.blob(commonInBlob + "b");
+ localChild = local.commit(
+ local.tree(local.file("foo", localChildBlob)), localParent);
+ local.update("branch1", localChild);
+ }
+
+ ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n",
+ PacketLineIn.delimiter(), "wait-for-done\n",
+ "have " + localParent.toObjectId().getName() + "\n",
+ "have " + localChild.toObjectId().getName() + "\n",
+ PacketLineIn.end());
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("acknowledgments"));
+ assertThat(Arrays.asList(pckIn.readString()),
+ hasItems("ACK " + parent.toObjectId().getName()));
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
+ }
+
+ @Test
+ public void testV2FetchWithWaitForDoneOnlyDoesNegotiationAndNothingToAck()
+ throws Exception {
+ String commonInBlob = "abcdefghijklmnopqrstuvwxyz";
+
+ RevCommit localParent = null;
+ RevCommit localChild = null;
+ try (TestRepository<InMemoryRepository> local = new TestRepository<>(
+ client)) {
+ RevBlob localParentBlob = local.blob(commonInBlob + "a");
+ localParent = local
+ .commit(local.tree(local.file("foo", localParentBlob)));
+ RevBlob localChildBlob = local.blob(commonInBlob + "b");
+ localChild = local.commit(
+ local.tree(local.file("foo", localChildBlob)), localParent);
+ local.update("branch1", localChild);
+ }
+
+ ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n",
+ PacketLineIn.delimiter(), "wait-for-done\n",
+ "have " + localParent.toObjectId().getName() + "\n",
+ "have " + localChild.toObjectId().getName() + "\n",
+ PacketLineIn.end());
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("acknowledgments"));
+ assertThat(pckIn.readString(), is("NAK"));
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
+ }
+
+ @Test
public void testV2FetchServerStopsNegotiationForRefWithoutParents()
throws Exception {
RevCommit fooCommit = remote.commit().message("x").create();
@@ -2594,4 +2703,44 @@ public class UploadPackTest {
return refdb;
}
}
+
+ @Test
+ public void testObjectInfo() throws Exception {
+ server.getConfig().setBoolean("uploadpack", null, "advertiseobjectinfo",
+ true);
+
+ RevBlob blob1 = remote.blob("foobar");
+ RevBlob blob2 = remote.blob("fooba");
+ RevTree tree = remote.tree(remote.file("1", blob1),
+ remote.file("2", blob2));
+ RevCommit commit = remote.commit(tree);
+ remote.update("master", commit);
+
+ TestV2Hook hook = new TestV2Hook();
+ ByteArrayInputStream recvStream = uploadPackV2((UploadPack up) -> {
+ up.setProtocolV2Hook(hook);
+ }, "command=object-info\n", "size",
+ "oid " + ObjectId.toString(blob1.getId()),
+ "oid " + ObjectId.toString(blob2.getId()), PacketLineIn.end());
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(hook.objectInfoRequest, notNullValue());
+ assertThat(pckIn.readString(), is("size"));
+ assertThat(pckIn.readString(),
+ is(ObjectId.toString(blob1.getId()) + " 6"));
+ assertThat(pckIn.readString(),
+ is(ObjectId.toString(blob2.getId()) + " 5"));
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
+ }
+
+ @Test
+ public void testObjectInfo_invalidOid() throws Exception {
+ server.getConfig().setBoolean("uploadpack", null, "advertiseobjectinfo",
+ true);
+
+ assertThrows(UploadPackInternalServerErrorException.class,
+ () -> uploadPackV2("command=object-info\n", "size",
+ "oid invalid",
+ PacketLineIn.end()));
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
index f289a922bb..5adf7faf20 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
@@ -99,7 +99,7 @@ import org.slf4j.LoggerFactory;
public class WalkEncryptionTest {
/**
- * Logger setup: ${project_loc}/tst-rsrc/log4j.properties
+ * Logger setup: ${project_loc}/tst-rsrc/simplelogger.properties
*/
static final Logger logger = LoggerFactory.getLogger(WalkEncryptionTest.class);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java
index d8133913df..0b5a7356c8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009, 2013 Google Inc. and others
+ * Copyright (C) 2009, 2021 Google Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -41,10 +41,11 @@ public class PathSuffixFilterTest extends RepositoryTestCase {
@Test
public void testRecursiveFiltering() throws IOException {
- ObjectId treeId = createTree("a.sth", "a.txt", "sub/b.sth", "sub/b.txt");
+ ObjectId treeId = createTree("a.sth", "a.txt", "sub/b.sth", "sub/b.txt",
+ "t.sth", "t.txt");
List<String> paths = getMatchingPaths(".txt", treeId, true);
- List<String> expected = Arrays.asList("a.txt", "sub/b.txt");
+ List<String> expected = Arrays.asList("a.txt", "sub/b.txt", "t.txt");
assertEquals(expected, paths);
}
@@ -59,6 +60,17 @@ public class PathSuffixFilterTest extends RepositoryTestCase {
assertEquals(Arrays.asList("abc", "c"), getMatchingPaths("c", treeId));
}
+ @Test
+ public void testNegated() throws IOException {
+ ObjectId treeId = createTree("a.sth", "a.txt", "sub/b.sth",
+ "sub/b.txt", "t.sth", "t.txt");
+
+ List<String> paths = getMatchingPaths(".txt", treeId, true, true);
+ List<String> expected = Arrays.asList("a.sth", "sub/b.sth", "t.sth");
+
+ assertEquals(expected, paths);
+ }
+
private ObjectId createTree(String... paths) throws IOException {
final ObjectInserter odi = db.newObjectInserter();
final DirCache dc = db.readDirCache();
@@ -80,8 +92,18 @@ public class PathSuffixFilterTest extends RepositoryTestCase {
private List<String> getMatchingPaths(String suffixFilter,
final ObjectId treeId, boolean recursiveWalk) throws IOException {
+ return getMatchingPaths(suffixFilter, treeId, recursiveWalk, false);
+ }
+
+ private List<String> getMatchingPaths(String suffixFilter,
+ final ObjectId treeId, boolean recursiveWalk, boolean negated)
+ throws IOException {
try (TreeWalk tw = new TreeWalk(db)) {
- tw.setFilter(PathSuffixFilter.create(suffixFilter));
+ TreeFilter filter = PathSuffixFilter.create(suffixFilter);
+ if (negated) {
+ filter = filter.negate();
+ }
+ tw.setFilter(filter);
tw.setRecursive(recursiveWalk);
tw.addTree(treeId);