Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java12
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java16
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java12
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextLoadTest.java110
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java40
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java7
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherParametrizedTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DeltaBaseCacheTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java111
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java21
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableCompactorTest.java325
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabaseTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java238
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java18
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java141
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java69
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java80
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java92
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java251
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java105
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java105
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorWithTimeControl.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java41
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java19
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java11
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java14
53 files changed, 1658 insertions, 314 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java
index 5f7434b41f..cc21b473ec 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java
@@ -70,19 +70,19 @@ import org.junit.Test;
* ---------------------------------------------------------------------
* | HEAD DirCache Worktree | HEAD DirCache
* ---------------------------------------------------------------------
- * f1_1 | - - c | => e: path unknown
- * f1_2 | - c - | => no changes
+ * f1_1 | - - c | => e: path unknown
+ * f1_2 | - c - | => no changes
* f1_3 | c - - | - -
* f1_4 | - c c | c c
* f1_5 | c c - | - -
- * f1_6 | c - c | => no changes
- * f1_7 | c c c | => no changes
+ * f1_6 | c - c | => no changes
+ * f1_7 | c c c | => no changes
* ---------------------------------------------------------------------
* f1_8 | - c c' | c' c'
* f1_9 | c - c' | c' c'
* f1_10 | c c' - | - -
* f1_11 | c c c' | c' c'
- * f1_12 | c c' c | => no changes
+ * f1_12 | c c' c | => no changes
* f1_13 | c c' c' | c' c'
* ---------------------------------------------------------------------
* f1_14 | c c' c'' | c'' c''
@@ -97,7 +97,7 @@ import org.junit.Test;
* ---------------------------------------------------------------------------
* | HEAD DirCache Worktree | HEAD DirCache
* ---------------------------------------------------------------------------
- * f1_1_f2_14 | - - c | => e: path unknown
+ * f1_1_f2_14 | - - c | => e: path unknown
* f1_2_f2_14 | - c - | - -
* f1_6_f2_14 | c - c | c c
* f1_7_f2_14 | c c c | c c
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 6a667830e8..d78a328402 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
@@ -158,9 +158,9 @@ public class DescribeCommandTest extends RepositoryTestCase {
* Make sure it finds a tag when not all ancestries include a tag.
*
* <pre>
- * c1 -+-> T -
+ * c1 -+-&gt; T -
* | |
- * +-> c3 -+-> c4
+ * +-&gt; c3 -+-&gt; c4
* </pre>
*
* @throws Exception
@@ -193,9 +193,9 @@ public class DescribeCommandTest extends RepositoryTestCase {
* When t2 dominates t1, it's clearly preferable to describe by using t2.
*
* <pre>
- * t1 -+-> t2 -
+ * t1 -+-&gt; t2 -
* | |
- * +-> c3 -+-> c4
+ * +-&gt; c3 -+-&gt; c4
* </pre>
*
* @throws Exception
@@ -225,9 +225,9 @@ public class DescribeCommandTest extends RepositoryTestCase {
* When t1 is nearer than t2, t2 should be found
*
* <pre>
- * c1 -+-> c2 -> t1 -+
+ * c1 -+-&gt; c2 -&gt; t1 -+
* | |
- * +-> t2 -> c3 -+-> c4
+ * +-&gt; t2 -&gt; c3 -+-&gt; c4
* </pre>
*
* @throws Exception
@@ -254,9 +254,9 @@ public class DescribeCommandTest extends RepositoryTestCase {
* paths
*
* <pre>
- * c1 -+-> t1 -> c2 -+
+ * c1 -+-&gt; t1 -&gt; c2 -+
* | |
- * +-> t2 -> c3 -+-> c4
+ * +-&gt; t2 -&gt; c3 -+-&gt; c4
* </pre>
*
* @throws Exception
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
index 2ee77a010a..1e3a39aad8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
@@ -42,6 +42,7 @@
package org.eclipse.jgit.api;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_CRLF;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_LF;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.DIRECT;
@@ -53,7 +54,6 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.eclipse.jgit.lib.CoreConfig.EolStreamType;
@@ -150,9 +150,8 @@ public class EolStreamTypeUtilTest {
EolStreamType streamTypeWithBinaryCheck, String output,
String expectedConversion) throws Exception {
ByteArrayOutputStream b;
- byte[] outputBytes = output.getBytes(StandardCharsets.UTF_8);
- byte[] expectedConversionBytes = expectedConversion
- .getBytes(StandardCharsets.UTF_8);
+ byte[] outputBytes = output.getBytes(UTF_8);
+ byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);
// test using output text and assuming it was declared TEXT
b = new ByteArrayOutputStream();
@@ -278,9 +277,8 @@ public class EolStreamTypeUtilTest {
private void testCheckin(EolStreamType streamTypeText,
EolStreamType streamTypeWithBinaryCheck, String input,
String expectedConversion) throws Exception {
- byte[] inputBytes = input.getBytes(StandardCharsets.UTF_8);
- byte[] expectedConversionBytes = expectedConversion
- .getBytes(StandardCharsets.UTF_8);
+ byte[] inputBytes = input.getBytes(UTF_8);
+ byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);
// test using input text and assuming it was declared TEXT
try (InputStream in = EolStreamTypeUtil.wrapInputStream(
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 a341284850..cc5a0249cb 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
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.api;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -593,7 +594,7 @@ public class PullCommandTest extends RepositoryTestCase {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(actFile);
- fos.write(string.getBytes("UTF-8"));
+ fos.write(string.getBytes(UTF_8));
fos.close();
} finally {
if (fos != null)
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
index 6f6b1158eb..dfe05b808e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.api;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -397,7 +398,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(actFile);
- fos.write(string.getBytes("UTF-8"));
+ fos.write(string.getBytes(UTF_8));
fos.close();
} finally {
if (fos != null)
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
index 0cc0816c16..3f43c6b1bb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.api;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -1463,7 +1464,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]);
PersonIdent parsedIdent = git.rebase().parseAuthor(
- convertedAuthor.getBytes("UTF-8"));
+ convertedAuthor.getBytes(UTF_8));
assertEquals(ident.getName(), parsedIdent.getName());
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
// this is rounded to the last second
@@ -1480,7 +1481,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]);
parsedIdent = git.rebase().parseAuthor(
- convertedAuthor.getBytes("UTF-8"));
+ convertedAuthor.getBytes(UTF_8));
assertEquals(ident.getName(), parsedIdent.getName());
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
assertEquals(123456789000L, parsedIdent.getWhen().getTime());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java
index 72cc1d1814..196c4f7d9c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/AttributesMatcherTest.java
@@ -424,7 +424,7 @@ public class AttributesMatcherTest {
* @param target
* Target file path relative to repository's GIT_DIR
*/
- public void assertMatched(String pattern, String target) {
+ private void assertMatched(String pattern, String target) {
boolean value = match(pattern, target);
assertTrue("Expected a match for: " + pattern + " with: " + target,
value);
@@ -439,7 +439,7 @@ public class AttributesMatcherTest {
* @param target
* Target file path relative to repository's GIT_DIR
*/
- public void assertNotMatched(String pattern, String target) {
+ private void assertNotMatched(String pattern, String target) {
boolean value = match(pattern, target);
assertFalse("Expected no match for: " + pattern + " with: " + target,
value);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
index 4130b7ee5b..0f13a68b25 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
@@ -43,11 +43,10 @@
package org.eclipse.jgit.diff;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.io.UnsupportedEncodingException;
-
import org.junit.Test;
public abstract class AbstractDiffTestCase {
@@ -241,10 +240,6 @@ public abstract class AbstractDiffTestCase {
r.append(text.charAt(i));
r.append('\n');
}
- try {
- return new RawText(r.toString().getBytes("UTF-8"));
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
+ return new RawText(r.toString().getBytes(UTF_8));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java
index d6a5dcde2b..70447c7d5d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditListTest.java
@@ -53,6 +53,7 @@ import java.util.Iterator;
import org.junit.Test;
public class EditListTest {
+ @SuppressWarnings("unlikely-arg-type")
@Test
public void testEmpty() {
final EditList l = new EditList();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java
index 1a0c39ebfe..c621a7fab4 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/EditTest.java
@@ -125,6 +125,7 @@ public class EditTest {
assertEquals("REPLACE(1-2,1-4)", e.toString());
}
+ @SuppressWarnings("unlikely-arg-type")
@Test
public void testEquals1() {
final Edit e1 = new Edit(1, 2, 3, 4);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextLoadTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextLoadTest.java
new file mode 100644
index 0000000000..a11402f2fe
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextLoadTest.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2017, Google Inc.
+ * 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.diff;
+
+import org.eclipse.jgit.errors.BinaryBlobException;
+import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.lib.ObjectLoader;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class RawTextLoadTest extends RepositoryTestCase {
+ private static byte[] generate(int size, int nullAt) {
+ byte[] data = new byte[size];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) ((i % 72 == 0) ? '\n' : (i%10) + '0');
+ }
+ if (nullAt >= 0) {
+ data[nullAt] = '\0';
+ }
+ return data;
+ }
+
+ private RawText textFor(byte[] data, int limit) throws IOException, BinaryBlobException {
+ FileRepository repo = createBareRepository();
+ ObjectId id;
+ try (ObjectInserter ins = repo.getObjectDatabase().newInserter()) {
+ id = ins.insert(Constants.OBJ_BLOB, data);
+ }
+ ObjectLoader ldr = repo.open(id);
+ return RawText.load(ldr, limit);
+ }
+
+ @Test
+ public void testSmallOK() throws Exception {
+ byte[] data = generate(1000, -1);
+ RawText result = textFor(data, 1 << 20);
+ Assert.assertArrayEquals(result.content, data);
+ }
+
+ @Test(expected = BinaryBlobException.class)
+ public void testSmallNull() throws Exception {
+ byte[] data = generate(1000, 22);
+ textFor(data, 1 << 20);
+ }
+
+ @Test
+ public void testBigOK() throws Exception {
+ byte[] data = generate(10000, -1);
+ RawText result = textFor(data, 1 << 20);
+ Assert.assertArrayEquals(result.content, data);
+ }
+
+ @Test(expected = BinaryBlobException.class)
+ public void testBigWithNullAtStart() throws Exception {
+ byte[] data = generate(10000, 22);
+ textFor(data, 1 << 20);
+ }
+
+ @Test(expected = BinaryBlobException.class)
+ public void testBinaryThreshold() throws Exception {
+ byte[] data = generate(2 << 20, -1);
+ textFor(data, 1 << 20);
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
index 93ea9a7ab5..6ad59b9e56 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
@@ -44,6 +44,7 @@
package org.eclipse.jgit.diff;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -51,7 +52,6 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.util.RawParseUtils;
@@ -110,8 +110,7 @@ public class RawTextTest {
}
@Test
- public void testComparatorReduceCommonStartEnd()
- throws UnsupportedEncodingException {
+ public void testComparatorReduceCommonStartEnd() {
final RawTextComparator c = RawTextComparator.DEFAULT;
Edit e;
@@ -137,54 +136,51 @@ public class RawTextTest {
e = c.reduceCommonStartEnd(t("abQxy"), t("abRxy"), e);
assertEquals(new Edit(2, 3, 2, 3), e);
- RawText a = new RawText("p\na b\nQ\nc d\n".getBytes("UTF-8"));
- RawText b = new RawText("p\na b \nR\n c d \n".getBytes("UTF-8"));
+ RawText a = new RawText("p\na b\nQ\nc d\n".getBytes(UTF_8));
+ RawText b = new RawText("p\na b \nR\n c d \n".getBytes(UTF_8));
e = new Edit(0, 4, 0, 4);
e = RawTextComparator.WS_IGNORE_ALL.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(2, 3, 2, 3), e);
}
@Test
- public void testComparatorReduceCommonStartEnd_EmptyLine()
- throws UnsupportedEncodingException {
+ public void testComparatorReduceCommonStartEnd_EmptyLine() {
RawText a;
RawText b;
Edit e;
- a = new RawText("R\n y\n".getBytes("UTF-8"));
- b = new RawText("S\n\n y\n".getBytes("UTF-8"));
+ a = new RawText("R\n y\n".getBytes(UTF_8));
+ b = new RawText("S\n\n y\n".getBytes(UTF_8));
e = new Edit(0, 2, 0, 3);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 2), e);
- a = new RawText("S\n\n y\n".getBytes("UTF-8"));
- b = new RawText("R\n y\n".getBytes("UTF-8"));
+ a = new RawText("S\n\n y\n".getBytes(UTF_8));
+ b = new RawText("R\n y\n".getBytes(UTF_8));
e = new Edit(0, 3, 0, 2);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 2, 0, 1), e);
}
@Test
- public void testComparatorReduceCommonStartButLastLineNoEol()
- throws UnsupportedEncodingException {
+ public void testComparatorReduceCommonStartButLastLineNoEol() {
RawText a;
RawText b;
Edit e;
- a = new RawText("start".getBytes("UTF-8"));
- b = new RawText("start of line".getBytes("UTF-8"));
+ a = new RawText("start".getBytes(UTF_8));
+ b = new RawText("start of line".getBytes(UTF_8));
e = new Edit(0, 1, 0, 1);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 1), e);
}
@Test
- public void testComparatorReduceCommonStartButLastLineNoEol_2()
- throws UnsupportedEncodingException {
+ public void testComparatorReduceCommonStartButLastLineNoEol_2() {
RawText a;
RawText b;
Edit e;
- a = new RawText("start".getBytes("UTF-8"));
- b = new RawText("start of\nlastline".getBytes("UTF-8"));
+ a = new RawText("start".getBytes(UTF_8));
+ b = new RawText("start of\nlastline".getBytes(UTF_8));
e = new Edit(0, 1, 0, 2);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 2), e);
@@ -243,10 +239,6 @@ public class RawTextTest {
r.append(text.charAt(i));
r.append('\n');
}
- try {
- return new RawText(r.toString().getBytes("UTF-8"));
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
+ return new RawText(r.toString().getBytes(UTF_8));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
index 4724677bb8..f168e83284 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.diff;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -81,7 +82,7 @@ public class SimilarityIndexTest {
+ "A\n" //
+ "B\n" //
+ "B\n" //
- + "B\n").getBytes("UTF-8");
+ + "B\n").getBytes(UTF_8);
SimilarityIndex si = new SimilarityIndex();
si.hash(new ByteArrayInputStream(in), in.length, false);
assertEquals(2, si.size());
@@ -129,12 +130,12 @@ public class SimilarityIndexTest {
+ "D\r\n" //
+ "B\r\n";
SimilarityIndex src = new SimilarityIndex();
- byte[] bytes1 = text.getBytes("UTF-8");
+ byte[] bytes1 = text.getBytes(UTF_8);
src.hash(new ByteArrayInputStream(bytes1), bytes1.length, true);
src.sort();
SimilarityIndex dst = new SimilarityIndex();
- byte[] bytes2 = text.replace("\r", "").getBytes("UTF-8");
+ byte[] bytes2 = text.replace("\r", "").getBytes(UTF_8);
dst.hash(new ByteArrayInputStream(bytes2), bytes2.length, true);
dst.sort();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
index 6ed2c215e9..9afb58ecfb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.gitrepo;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -54,7 +55,6 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
-import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
@@ -213,7 +213,8 @@ public class RepoCommandTest extends RepositoryTestCase {
repos.put("platform/base", child);
RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(StandardCharsets.UTF_8)))
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos)
.setURI("platform/")
.setTargetURI("platform/superproject")
@@ -263,7 +264,7 @@ public class RepoCommandTest extends RepositoryTestCase {
repos.put("plugins/cookbook", child);
RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(StandardCharsets.UTF_8)))
+ .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos)
.setURI("")
.setTargetURI("gerrit")
@@ -317,7 +318,7 @@ public class RepoCommandTest extends RepositoryTestCase {
repos.put(repoUrl, child);
RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(StandardCharsets.UTF_8)))
+ .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos)
.setURI(baseUrl)
.setTargetURI("gerrit")
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java
index bcc8f7e47f..06164c8a91 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/FastIgnoreRuleTest.java
@@ -465,7 +465,7 @@ public class FastIgnoreRuleTest {
split("/a/b/c/", '/').toArray());
}
- public void assertMatched(String pattern, String path) {
+ private void assertMatched(String pattern, String path) {
boolean match = match(pattern, path);
String result = path + " is " + (match ? "ignored" : "not ignored")
+ " via '" + pattern + "' rule";
@@ -485,7 +485,7 @@ public class FastIgnoreRuleTest {
match);
}
- public void assertNotMatched(String pattern, String path) {
+ private void assertNotMatched(String pattern, String path) {
boolean match = match(pattern, path);
String result = path + " is " + (match ? "ignored" : "not ignored")
+ " via '" + pattern + "' rule";
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherParametrizedTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherParametrizedTest.java
index 529c75ff39..137230d09f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherParametrizedTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreMatcherParametrizedTest.java
@@ -346,7 +346,7 @@ public class IgnoreMatcherParametrizedTest {
* Target file path relative to repository's GIT_DIR
* @param assume
*/
- public void assertMatched(String pattern, String target, Boolean... assume) {
+ private void assertMatched(String pattern, String target, Boolean... assume) {
boolean value = match(pattern, target);
if (assume.length == 0 || !assume[0].booleanValue())
assertTrue("Expected a match for: " + pattern + " with: " + target,
@@ -366,7 +366,7 @@ public class IgnoreMatcherParametrizedTest {
* Target file path relative to repository's GIT_DIR
* @param assume
*/
- public void assertNotMatched(String pattern, String target,
+ private void assertNotMatched(String pattern, String target,
Boolean... assume) {
boolean value = match(pattern, target);
if (assume.length == 0 || !assume[0].booleanValue())
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
index 4a7dcd535f..1178eb3e8a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.ignore;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -541,11 +542,11 @@ public class IgnoreNodeTest extends RepositoryTestCase {
writeTrashFile(name, data.toString());
}
- private InputStream writeToString(String... rules) throws IOException {
+ private InputStream writeToString(String... rules) {
StringBuilder data = new StringBuilder();
for (String line : rules) {
data.append(line + "\n");
}
- return new ByteArrayInputStream(data.toString().getBytes("UTF-8"));
+ return new ByteArrayInputStream(data.toString().getBytes(UTF_8));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
index 4228c9dbec..3db27926c6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
@@ -41,6 +41,7 @@
*/
package org.eclipse.jgit.indexdiff;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -60,7 +61,6 @@ import java.io.OutputStreamWriter;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -130,8 +130,7 @@ public class IndexDiffWithSymlinkTest extends LocalDiskRepositoryTestCase {
File restoreScript = new File(testDir, name + ".sh");
try (OutputStream out = new BufferedOutputStream(
new FileOutputStream(restoreScript));
- Writer writer = new OutputStreamWriter(out,
- StandardCharsets.UTF_8)) {
+ Writer writer = new OutputStreamWriter(out, UTF_8)) {
writer.write("echo `which git` 1>&2\n");
writer.write("echo `git --version` 1>&2\n");
writer.write("git init " + name + " && \\\n");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DeltaBaseCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DeltaBaseCacheTest.java
index 32d711f1f8..6a5d3c2347 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DeltaBaseCacheTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DeltaBaseCacheTest.java
@@ -64,7 +64,7 @@ public class DeltaBaseCacheTest {
@Before
public void setUp() {
DfsRepositoryDescription repo = new DfsRepositoryDescription("test");
- key = DfsStreamKey.of(repo, "test.key");
+ key = DfsStreamKey.of(repo, "test.key", null);
cache = new DeltaBaseCache(SZ);
rng = new TestRng(getClass().getSimpleName());
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java
index 2e3ee4526f..d29744dfc5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java
@@ -50,6 +50,7 @@ import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.stream.LongStream;
import org.eclipse.jgit.junit.TestRng;
import org.eclipse.jgit.lib.ObjectId;
@@ -84,9 +85,9 @@ public class DfsBlockCacheTest {
ins.flush();
}
- long oldSize = cache.getCurrentSize();
+ long oldSize = LongStream.of(cache.getCurrentSize()).sum();
assertTrue(oldSize > 2000);
- assertEquals(0, cache.getHitCount());
+ assertEquals(0, LongStream.of(cache.getHitCount()).sum());
List<DfsPackDescription> packs = r1.getObjectDatabase().listPacks();
InMemoryRepository r2 = new InMemoryRepository(repo);
@@ -95,8 +96,8 @@ public class DfsBlockCacheTest {
byte[] actual = rdr.open(id, OBJ_BLOB).getBytes();
assertTrue(Arrays.equals(content, actual));
}
- assertEquals(0, cache.getMissCount());
- assertEquals(oldSize, cache.getCurrentSize());
+ assertEquals(0, LongStream.of(cache.getMissCount()).sum());
+ assertEquals(oldSize, LongStream.of(cache.getCurrentSize()).sum());
}
@SuppressWarnings("resource")
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 55a5f726de..5b567d00f7 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
@@ -9,16 +9,17 @@ import static org.eclipse.jgit.internal.storage.pack.PackExt.REFTABLE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
-import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
+import org.eclipse.jgit.internal.storage.dfs.DfsRefDatabase;
import org.eclipse.jgit.internal.storage.reftable.RefCursor;
import org.eclipse.jgit.internal.storage.reftable.ReftableConfig;
import org.eclipse.jgit.internal.storage.reftable.ReftableReader;
@@ -722,7 +723,7 @@ public class DfsGarbageCollectorTest {
DfsPackDescription t1 = odb.newPack(INSERT);
try (DfsOutputStream out = odb.writeFile(t1, REFTABLE)) {
- out.write("ignored".getBytes(StandardCharsets.UTF_8));
+ new ReftableWriter().begin(out).finish();
t1.addFileExt(REFTABLE);
}
odb.commitPack(Collections.singleton(t1), null);
@@ -739,9 +740,9 @@ public class DfsGarbageCollectorTest {
assertTrue("commit0 in pack", isObjectInPack(commit0, pack));
assertTrue("commit1 in pack", isObjectInPack(commit1, pack));
- // Only INSERT REFTABLE above is present.
+ // A GC and the older INSERT REFTABLE above is present.
DfsReftable[] tables = odb.getReftables();
- assertEquals(1, tables.length);
+ assertEquals(2, tables.length);
assertEquals(t1, tables[0].getPackDescription());
}
@@ -754,7 +755,7 @@ public class DfsGarbageCollectorTest {
DfsPackDescription t1 = odb.newPack(INSERT);
try (DfsOutputStream out = odb.writeFile(t1, REFTABLE)) {
- out.write("ignored".getBytes(StandardCharsets.UTF_8));
+ new ReftableWriter().begin(out).finish();
t1.addFileExt(REFTABLE);
}
odb.commitPack(Collections.singleton(t1), null);
@@ -843,6 +844,106 @@ public class DfsGarbageCollectorTest {
}
}
+ @Test
+ public void reftableWithoutTombstoneResurrected() throws Exception {
+ RevCommit commit0 = commit().message("0").create();
+ String NEXT = "refs/heads/next";
+ DfsRefDatabase refdb = (DfsRefDatabase)repo.getRefDatabase();
+ git.update(NEXT, commit0);
+ Ref next = refdb.exactRef(NEXT);
+ assertNotNull(next);
+ assertEquals(commit0, next.getObjectId());
+
+ git.delete(NEXT);
+ refdb.clearCache();
+ assertNull(refdb.exactRef(NEXT));
+
+ DfsGarbageCollector gc = new DfsGarbageCollector(repo);
+ gc.setReftableConfig(new ReftableConfig());
+ gc.setIncludeDeletes(false);
+ gc.setConvertToReftable(false);
+ run(gc);
+ assertEquals(1, odb.getReftables().length);
+ try (DfsReader ctx = odb.newReader();
+ ReftableReader rr = odb.getReftables()[0].open(ctx)) {
+ rr.setIncludeDeletes(true);
+ assertEquals(1, rr.minUpdateIndex());
+ assertEquals(2, rr.maxUpdateIndex());
+ assertNull(rr.exactRef(NEXT));
+ }
+
+ RevCommit commit1 = commit().message("1").create();
+ DfsPackDescription t1 = odb.newPack(INSERT);
+ Ref newNext = new ObjectIdRef.PeeledNonTag(Ref.Storage.LOOSE, NEXT,
+ commit1);
+ try (DfsOutputStream out = odb.writeFile(t1, REFTABLE)) {
+ ReftableWriter w = new ReftableWriter();
+ w.setMinUpdateIndex(1);
+ w.setMaxUpdateIndex(1);
+ w.begin(out);
+ w.writeRef(newNext, 1);
+ w.finish();
+ t1.addFileExt(REFTABLE);
+ t1.setReftableStats(w.getStats());
+ }
+ odb.commitPack(Collections.singleton(t1), null);
+ assertEquals(2, odb.getReftables().length);
+ refdb.clearCache();
+ newNext = refdb.exactRef(NEXT);
+ assertNotNull(newNext);
+ assertEquals(commit1, newNext.getObjectId());
+ }
+
+ @Test
+ public void reftableWithTombstoneNotResurrected() throws Exception {
+ RevCommit commit0 = commit().message("0").create();
+ String NEXT = "refs/heads/next";
+ DfsRefDatabase refdb = (DfsRefDatabase)repo.getRefDatabase();
+ git.update(NEXT, commit0);
+ Ref next = refdb.exactRef(NEXT);
+ assertNotNull(next);
+ assertEquals(commit0, next.getObjectId());
+
+ git.delete(NEXT);
+ refdb.clearCache();
+ assertNull(refdb.exactRef(NEXT));
+
+ DfsGarbageCollector gc = new DfsGarbageCollector(repo);
+ gc.setReftableConfig(new ReftableConfig());
+ gc.setIncludeDeletes(true);
+ gc.setConvertToReftable(false);
+ run(gc);
+ assertEquals(1, odb.getReftables().length);
+ try (DfsReader ctx = odb.newReader();
+ ReftableReader rr = odb.getReftables()[0].open(ctx)) {
+ rr.setIncludeDeletes(true);
+ assertEquals(1, rr.minUpdateIndex());
+ assertEquals(2, rr.maxUpdateIndex());
+ next = rr.exactRef(NEXT);
+ assertNotNull(next);
+ assertNull(next.getObjectId());
+ }
+
+ RevCommit commit1 = commit().message("1").create();
+ DfsPackDescription t1 = odb.newPack(INSERT);
+ Ref newNext = new ObjectIdRef.PeeledNonTag(Ref.Storage.LOOSE, NEXT,
+ commit1);
+ try (DfsOutputStream out = odb.writeFile(t1, REFTABLE)) {
+ ReftableWriter w = new ReftableWriter();
+ w.setMinUpdateIndex(1);
+ w.setMaxUpdateIndex(1);
+ w.begin(out);
+ w.writeRef(newNext, 1);
+ w.finish();
+ t1.addFileExt(REFTABLE);
+ t1.setReftableStats(w.getStats());
+ }
+ odb.commitPack(Collections.singleton(t1), null);
+ assertEquals(2, odb.getReftables().length);
+ refdb.clearCache();
+ assertNull(refdb.exactRef(NEXT));
+ }
+
private TestRepository<InMemoryRepository>.CommitBuilder commit() {
return git.commit();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java
index 343120ef5f..a9edf73b85 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java
@@ -178,7 +178,7 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase {
}
String packName = "pack-" + id.name();
- File packDir = new File(db.getObjectDatabase().getDirectory(), "pack");
+ File packDir = db.getObjectDatabase().getPackDirectory();
File idxFile = new File(packDir, packName + ".idx");
File packFile = new File(packDir, packName + ".pack");
FileUtils.mkdir(packDir, true);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java
index 09438e9649..4813d28017 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java
@@ -272,7 +272,7 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
}
private File fullPackFileName(final ObjectId name, final String suffix) {
- final File packdir = new File(db.getObjectDatabase().getDirectory(), "pack");
+ final File packdir = db.getObjectDatabase().getPackDirectory();
return new File(packdir, "pack-" + name.name() + suffix);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java
index 5393987781..79d72c56d0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java
@@ -71,7 +71,7 @@ public class GcOrphanFilesTest extends GcTestCase {
@Before
public void setUp() throws Exception {
super.setUp();
- packDir = new File(repo.getObjectsDirectory(), PACK);
+ packDir = repo.getObjectDatabase().getPackDirectory();
}
@Test
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 f1cbb99d5a..cbb73bb08e 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
@@ -129,8 +129,8 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
assertTrue(receivingDB.getObjectDatabase().hasPackedObject(id));
// preparations
- File packsFolder = new File(receivingDB.getObjectsDirectory(),
- "pack");
+ File packsFolder = receivingDB.getObjectDatabase()
+ .getPackDirectory();
// prepare creation of a temporary file in the pack folder. This
// simulates that a native git gc is happening starting to write
// temporary files but has not yet finished
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java
index 8596f74f81..b782ce87ff 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackInserterTest.java
@@ -575,9 +575,12 @@ public class PackInserterTest extends RepositoryTestCase {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
- String name = file.getFileName().toString();
- if (!attrs.isDirectory() && badName.test(name)) {
- bad.add(name);
+ Path fileName = file.getFileName();
+ if (fileName != null) {
+ String name = fileName.toString();
+ if (!attrs.isDirectory() && badName.test(name)) {
+ bad.add(name);
+ }
}
return FileVisitResult.CONTINUE;
}
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 9b97eb4ff4..379432ddbb 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
@@ -337,7 +337,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
*/
@Test
public void testWritePack2DeltasCRC32Copy() throws IOException {
- final File packDir = new File(db.getObjectDatabase().getDirectory(), "pack");
+ final File packDir = db.getObjectDatabase().getPackDirectory();
final File crc32Pack = new File(packDir,
"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");
final File crc32Idx = new File(packDir,
@@ -713,7 +713,7 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
pw.preparePack(NullProgressMonitor.INSTANCE, ow, want, have, NONE);
String id = pw.computeName().getName();
- File packdir = new File(repo.getObjectsDirectory(), "pack");
+ File packdir = repo.getObjectDatabase().getPackDirectory();
File packFile = new File(packdir, "pack-" + id + ".pack");
FileOutputStream packOS = new FileOutputStream(packFile);
pw.writePack(NullProgressMonitor.INSTANCE,
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
index 9d23d8334c..aa50697172 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
@@ -46,6 +46,7 @@
package org.eclipse.jgit.internal.storage.file;
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -55,7 +56,6 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@@ -82,6 +82,7 @@ import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.util.IO;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -360,11 +361,15 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
assertEquals("a many line\ncomment\n to test", c.getString("user",
null, "defaultCheckInComment"));
c.save();
- final FileReader fr = new FileReader(cfg);
- final char[] cbuf = new char[configStr.length()];
- fr.read(cbuf);
- fr.close();
- assertEquals(configStr, new String(cbuf));
+
+ // Saving normalizes out the weird "\\n\\\n" to a single escaped newline,
+ // and quotes the whole string.
+ final String expectedStr = " [core];comment\n\tfilemode = yes\n"
+ + "[user]\n"
+ + " email = A U Thor <thor@example.com> # Just an example...\n"
+ + " name = \"A Thor \\\\ \\\"\\t \"\n"
+ + " defaultCheckInComment = a many line\\ncomment\\n to test\n";
+ assertEquals(expectedStr, new String(IO.readFully(cfg), Constants.CHARSET));
}
@Test
@@ -544,9 +549,9 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
}
@Test
- public void test025_computeSha1NoStore() throws IOException {
+ public void test025_computeSha1NoStore() {
byte[] data = "test025 some data, more than 16 bytes to get good coverage"
- .getBytes("ISO-8859-1");
+ .getBytes(ISO_8859_1);
try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
final ObjectId id = formatter.idFor(Constants.OBJ_BLOB, data);
assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableCompactorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableCompactorTest.java
new file mode 100644
index 0000000000..46a37ff603
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableCompactorTest.java
@@ -0,0 +1,325 @@
+/*
+ * Copyright (C) 2017, Google Inc.
+ * 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.reftable;
+
+import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH;
+import static org.eclipse.jgit.lib.Ref.Storage.NEW;
+import static org.eclipse.jgit.lib.Ref.Storage.PACKED;
+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.IOException;
+import java.util.Arrays;
+
+import org.eclipse.jgit.internal.storage.io.BlockSource;
+import org.eclipse.jgit.internal.storage.reftable.ReftableWriter.Stats;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectIdRef;
+import org.eclipse.jgit.lib.Ref;
+import org.junit.Test;
+
+public class ReftableCompactorTest {
+ private static final String MASTER = "refs/heads/master";
+ private static final String NEXT = "refs/heads/next";
+
+ @Test
+ public void noTables() throws IOException {
+ ReftableCompactor compactor = new ReftableCompactor();
+ try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+ compactor.compact(out);
+ }
+ Stats stats = compactor.getStats();
+ assertEquals(0, stats.minUpdateIndex());
+ assertEquals(0, stats.maxUpdateIndex());
+ assertEquals(0, stats.refCount());
+ }
+
+ @Test
+ public void oneTable() throws IOException {
+ byte[] inTab;
+ try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) {
+ ReftableWriter writer = new ReftableWriter()
+ .setMinUpdateIndex(0)
+ .setMaxUpdateIndex(0)
+ .begin(inBuf);
+
+ writer.writeRef(ref(MASTER, 1));
+ writer.finish();
+ inTab = inBuf.toByteArray();
+ }
+
+ byte[] outTab;
+ ReftableCompactor compactor = new ReftableCompactor();
+ try (ByteArrayOutputStream outBuf = new ByteArrayOutputStream()) {
+ compactor.tryAddFirst(read(inTab));
+ compactor.compact(outBuf);
+ outTab = outBuf.toByteArray();
+ }
+ Stats stats = compactor.getStats();
+ assertEquals(0, stats.minUpdateIndex());
+ assertEquals(0, stats.maxUpdateIndex());
+ assertEquals(1, stats.refCount());
+
+ ReftableReader rr = read(outTab);
+ try (RefCursor rc = rr.allRefs()) {
+ assertTrue(rc.next());
+ assertEquals(MASTER, rc.getRef().getName());
+ assertEquals(id(1), rc.getRef().getObjectId());
+ assertEquals(0, rc.getUpdateIndex());
+ }
+ }
+
+ @Test
+ public void twoTablesOneRef() throws IOException {
+ byte[] inTab1;
+ try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) {
+ ReftableWriter writer = new ReftableWriter()
+ .setMinUpdateIndex(0)
+ .setMaxUpdateIndex(0)
+ .begin(inBuf);
+
+ writer.writeRef(ref(MASTER, 1));
+ writer.finish();
+ inTab1 = inBuf.toByteArray();
+ }
+
+ byte[] inTab2;
+ try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) {
+ ReftableWriter writer = new ReftableWriter()
+ .setMinUpdateIndex(1)
+ .setMaxUpdateIndex(1)
+ .begin(inBuf);
+
+ writer.writeRef(ref(MASTER, 2));
+ writer.finish();
+ inTab2 = inBuf.toByteArray();
+ }
+
+ byte[] outTab;
+ ReftableCompactor compactor = new ReftableCompactor();
+ try (ByteArrayOutputStream outBuf = new ByteArrayOutputStream()) {
+ compactor.addAll(Arrays.asList(read(inTab1), read(inTab2)));
+ compactor.compact(outBuf);
+ outTab = outBuf.toByteArray();
+ }
+ Stats stats = compactor.getStats();
+ assertEquals(0, stats.minUpdateIndex());
+ assertEquals(1, stats.maxUpdateIndex());
+ assertEquals(1, stats.refCount());
+
+ ReftableReader rr = read(outTab);
+ try (RefCursor rc = rr.allRefs()) {
+ assertTrue(rc.next());
+ assertEquals(MASTER, rc.getRef().getName());
+ assertEquals(id(2), rc.getRef().getObjectId());
+ assertEquals(1, rc.getUpdateIndex());
+ }
+ }
+
+ @Test
+ public void twoTablesTwoRefs() throws IOException {
+ byte[] inTab1;
+ try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) {
+ ReftableWriter writer = new ReftableWriter()
+ .setMinUpdateIndex(0)
+ .setMaxUpdateIndex(0)
+ .begin(inBuf);
+
+ writer.writeRef(ref(MASTER, 1));
+ writer.writeRef(ref(NEXT, 2));
+ writer.finish();
+ inTab1 = inBuf.toByteArray();
+ }
+
+ byte[] inTab2;
+ try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) {
+ ReftableWriter writer = new ReftableWriter()
+ .setMinUpdateIndex(1)
+ .setMaxUpdateIndex(1)
+ .begin(inBuf);
+
+ writer.writeRef(ref(MASTER, 3));
+ writer.finish();
+ inTab2 = inBuf.toByteArray();
+ }
+
+ byte[] outTab;
+ ReftableCompactor compactor = new ReftableCompactor();
+ try (ByteArrayOutputStream outBuf = new ByteArrayOutputStream()) {
+ compactor.addAll(Arrays.asList(read(inTab1), read(inTab2)));
+ compactor.compact(outBuf);
+ outTab = outBuf.toByteArray();
+ }
+ Stats stats = compactor.getStats();
+ assertEquals(0, stats.minUpdateIndex());
+ assertEquals(1, stats.maxUpdateIndex());
+ assertEquals(2, stats.refCount());
+
+ ReftableReader rr = read(outTab);
+ try (RefCursor rc = rr.allRefs()) {
+ assertTrue(rc.next());
+ assertEquals(MASTER, rc.getRef().getName());
+ assertEquals(id(3), rc.getRef().getObjectId());
+ assertEquals(1, rc.getUpdateIndex());
+
+ assertTrue(rc.next());
+ assertEquals(NEXT, rc.getRef().getName());
+ assertEquals(id(2), rc.getRef().getObjectId());
+ assertEquals(0, rc.getUpdateIndex());
+ }
+ }
+
+ @Test
+ public void twoTablesIncludeOneDelete() throws IOException {
+ byte[] inTab1;
+ try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) {
+ ReftableWriter writer = new ReftableWriter()
+ .setMinUpdateIndex(0)
+ .setMaxUpdateIndex(0)
+ .begin(inBuf);
+
+ writer.writeRef(ref(MASTER, 1));
+ writer.finish();
+ inTab1 = inBuf.toByteArray();
+ }
+
+ byte[] inTab2;
+ try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) {
+ ReftableWriter writer = new ReftableWriter()
+ .setMinUpdateIndex(1)
+ .setMaxUpdateIndex(1)
+ .begin(inBuf);
+
+ writer.writeRef(tombstone(MASTER));
+ writer.finish();
+ inTab2 = inBuf.toByteArray();
+ }
+
+ byte[] outTab;
+ ReftableCompactor compactor = new ReftableCompactor();
+ try (ByteArrayOutputStream outBuf = new ByteArrayOutputStream()) {
+ compactor.setIncludeDeletes(true);
+ compactor.addAll(Arrays.asList(read(inTab1), read(inTab2)));
+ compactor.compact(outBuf);
+ outTab = outBuf.toByteArray();
+ }
+ Stats stats = compactor.getStats();
+ assertEquals(0, stats.minUpdateIndex());
+ assertEquals(1, stats.maxUpdateIndex());
+ assertEquals(1, stats.refCount());
+
+ ReftableReader rr = read(outTab);
+ try (RefCursor rc = rr.allRefs()) {
+ assertFalse(rc.next());
+ }
+ }
+
+ @Test
+ public void twoTablesNotIncludeOneDelete() throws IOException {
+ byte[] inTab1;
+ try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) {
+ ReftableWriter writer = new ReftableWriter()
+ .setMinUpdateIndex(0)
+ .setMaxUpdateIndex(0)
+ .begin(inBuf);
+
+ writer.writeRef(ref(MASTER, 1));
+ writer.finish();
+ inTab1 = inBuf.toByteArray();
+ }
+
+ byte[] inTab2;
+ try (ByteArrayOutputStream inBuf = new ByteArrayOutputStream()) {
+ ReftableWriter writer = new ReftableWriter()
+ .setMinUpdateIndex(1)
+ .setMaxUpdateIndex(1)
+ .begin(inBuf);
+
+ writer.writeRef(tombstone(MASTER));
+ writer.finish();
+ inTab2 = inBuf.toByteArray();
+ }
+
+ byte[] outTab;
+ ReftableCompactor compactor = new ReftableCompactor();
+ try (ByteArrayOutputStream outBuf = new ByteArrayOutputStream()) {
+ compactor.setIncludeDeletes(false);
+ compactor.addAll(Arrays.asList(read(inTab1), read(inTab2)));
+ compactor.compact(outBuf);
+ outTab = outBuf.toByteArray();
+ }
+ Stats stats = compactor.getStats();
+ assertEquals(0, stats.minUpdateIndex());
+ assertEquals(1, stats.maxUpdateIndex());
+ assertEquals(0, stats.refCount());
+
+ ReftableReader rr = read(outTab);
+ try (RefCursor rc = rr.allRefs()) {
+ assertFalse(rc.next());
+ }
+ }
+
+ private static Ref ref(String name, int id) {
+ return new ObjectIdRef.PeeledNonTag(PACKED, name, id(id));
+ }
+
+ private static Ref tombstone(String name) {
+ return new ObjectIdRef.Unpeeled(NEW, name, null);
+ }
+
+ private static ObjectId id(int i) {
+ byte[] buf = new byte[OBJECT_ID_LENGTH];
+ buf[0] = (byte) (i & 0xff);
+ buf[1] = (byte) ((i >>> 8) & 0xff);
+ buf[2] = (byte) ((i >>> 16) & 0xff);
+ buf[3] = (byte) (i >>> 24);
+ return ObjectId.fromRaw(buf);
+ }
+
+ private static ReftableReader read(byte[] table) {
+ return new ReftableReader(BlockSource.from(table));
+ }
+}
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 9aef94369b..1684afa4e1 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
@@ -657,7 +657,8 @@ public class RefTreeDatabaseTest {
Ref old = tree.exactRef(reader, name);
Command n;
try (RevWalk rw = new RevWalk(repo)) {
- n = new Command(old, Command.toRef(rw, id, name, true));
+ 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/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index a12831a149..fb1ee8cadb 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
@@ -53,6 +53,7 @@ import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.eclipse.jgit.util.FileUtils.pathToString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -80,7 +81,6 @@ import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.SystemReader;
import org.junit.After;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -89,7 +89,10 @@ import org.junit.rules.TemporaryFolder;
/**
* Test reading of git config
*/
+@SuppressWarnings("boxing")
public class ConfigTest {
+ // A non-ASCII whitespace character: U+2002 EN QUAD.
+ private static final char WS = '\u2002';
@Rule
public ExpectedException expectedEx = ExpectedException.none();
@@ -666,28 +669,6 @@ public class ConfigTest {
assertTrue("Subsection should contain \"B\"", names.contains("B"));
}
- @Test
- public void testQuotingForSubSectionNames() {
- String resultPattern = "[testsection \"{0}\"]\n\ttestname = testvalue\n";
- String result;
-
- Config config = new Config();
- config.setString("testsection", "testsubsection", "testname",
- "testvalue");
-
- result = MessageFormat.format(resultPattern, "testsubsection");
- assertEquals(result, config.toText());
- config.clear();
-
- config.setString("testsection", "#quotable", "testname", "testvalue");
- result = MessageFormat.format(resultPattern, "#quotable");
- assertEquals(result, config.toText());
- config.clear();
-
- config.setString("testsection", "with\"quote", "testname", "testvalue");
- result = MessageFormat.format(resultPattern, "with\\\"quote");
- assertEquals(result, config.toText());
- }
@Test
public void testNoFinalNewline() throws ConfigInvalidException {
@@ -767,7 +748,6 @@ public class ConfigTest {
}
@Test
- @Ignore
public void testIncludeInvalidName() throws ConfigInvalidException {
expectedEx.expect(ConfigInvalidException.class);
expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile);
@@ -775,7 +755,6 @@ public class ConfigTest {
}
@Test
- @Ignore
public void testIncludeNoValue() throws ConfigInvalidException {
expectedEx.expect(ConfigInvalidException.class);
expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile);
@@ -783,7 +762,6 @@ public class ConfigTest {
}
@Test
- @Ignore
public void testIncludeEmptyValue() throws ConfigInvalidException {
expectedEx.expect(ConfigInvalidException.class);
expectedEx.expectMessage(JGitText.get().invalidLineInConfigFile);
@@ -820,10 +798,9 @@ public class ConfigTest {
}
@Test
- @Ignore
public void testIncludeTooManyRecursions() throws IOException {
File config = tmp.newFile("config");
- String include = "[include]\npath=" + config.toPath() + "\n";
+ String include = "[include]\npath=" + pathToString(config) + "\n";
Files.write(config.toPath(), include.getBytes());
FileBasedConfig fbConfig = new FileBasedConfig(null, config,
FS.DETECTED);
@@ -843,7 +820,7 @@ public class ConfigTest {
String fooBar = "[foo]\nbar=true\n";
Files.write(config.toPath(), fooBar.getBytes());
- Config parsed = parse("[include]\npath=" + config.toPath() + "\n");
+ Config parsed = parse("[include]\npath=" + pathToString(config) + "\n");
assertFalse(parsed.getBoolean("foo", "bar", false));
}
@@ -957,4 +934,207 @@ public class ConfigTest {
expectedEx.expect(IllegalArgumentException.class);
parseTime("-1", MILLISECONDS);
}
+
+ @Test
+ public void testEscapeSpacesOnly() throws ConfigInvalidException {
+ // Empty string is read back as null, so this doesn't round-trip.
+ assertEquals("", Config.escapeValue(""));
+
+ assertValueRoundTrip(" ", "\" \"");
+ assertValueRoundTrip(" ", "\" \"");
+ }
+
+ @Test
+ public void testEscapeLeadingSpace() throws ConfigInvalidException {
+ assertValueRoundTrip("x", "x");
+ assertValueRoundTrip(" x", "\" x\"");
+ assertValueRoundTrip(" x", "\" x\"");
+ }
+
+ @Test
+ public void testEscapeTrailingSpace() throws ConfigInvalidException {
+ assertValueRoundTrip("x", "x");
+ assertValueRoundTrip("x ","\"x \"");
+ assertValueRoundTrip("x ","\"x \"");
+ }
+
+ @Test
+ public void testEscapeLeadingAndTrailingSpace()
+ throws ConfigInvalidException {
+ assertValueRoundTrip(" x ", "\" x \"");
+ assertValueRoundTrip(" x ", "\" x \"");
+ assertValueRoundTrip(" x ", "\" x \"");
+ assertValueRoundTrip(" x ", "\" x \"");
+ }
+
+ @Test
+ public void testNoEscapeInternalSpaces() throws ConfigInvalidException {
+ assertValueRoundTrip("x y");
+ assertValueRoundTrip("x y");
+ assertValueRoundTrip("x y");
+ assertValueRoundTrip("x y z");
+ assertValueRoundTrip("x " + WS + " y");
+ }
+
+ @Test
+ public void testNoEscapeSpecialCharacters() throws ConfigInvalidException {
+ assertValueRoundTrip("x\\y", "x\\\\y");
+ assertValueRoundTrip("x\"y", "x\\\"y");
+ assertValueRoundTrip("x\ny", "x\\ny");
+ assertValueRoundTrip("x\ty", "x\\ty");
+ assertValueRoundTrip("x\by", "x\\by");
+ }
+
+ @Test
+ public void testParseLiteralBackspace() throws ConfigInvalidException {
+ // This is round-tripped with an escape sequence by JGit, but C git writes
+ // it out as a literal backslash.
+ assertEquals("x\by", parseEscapedValue("x\by"));
+ }
+
+ @Test
+ public void testEscapeCommentCharacters() throws ConfigInvalidException {
+ assertValueRoundTrip("x#y", "\"x#y\"");
+ assertValueRoundTrip("x;y", "\"x;y\"");
+ }
+
+ @Test
+ public void testEscapeValueInvalidCharacters() {
+ assertIllegalArgumentException(() -> Config.escapeSubsection("x\0y"));
+ }
+
+ @Test
+ public void testEscapeSubsectionInvalidCharacters() {
+ assertIllegalArgumentException(() -> Config.escapeSubsection("x\ny"));
+ assertIllegalArgumentException(() -> Config.escapeSubsection("x\0y"));
+ }
+
+ @Test
+ public void testParseMultipleQuotedRegions() throws ConfigInvalidException {
+ assertEquals("b a z; \n", parseEscapedValue("b\" a\"\" z; \\n\""));
+ }
+
+ @Test
+ public void testParseComments() throws ConfigInvalidException {
+ assertEquals("baz", parseEscapedValue("baz; comment"));
+ assertEquals("baz", parseEscapedValue("baz# comment"));
+ assertEquals("baz", parseEscapedValue("baz ; comment"));
+ assertEquals("baz", parseEscapedValue("baz # comment"));
+
+ assertEquals("baz", parseEscapedValue("baz ; comment"));
+ assertEquals("baz", parseEscapedValue("baz # comment"));
+ assertEquals("baz", parseEscapedValue("baz " + WS + " ; comment"));
+ assertEquals("baz", parseEscapedValue("baz " + WS + " # comment"));
+
+ assertEquals("baz ", parseEscapedValue("\"baz \"; comment"));
+ assertEquals("baz ", parseEscapedValue("\"baz \"# comment"));
+ assertEquals("baz ", parseEscapedValue("\"baz \" ; comment"));
+ assertEquals("baz ", parseEscapedValue("\"baz \" # comment"));
+ }
+
+ @Test
+ public void testEscapeSubsection() throws ConfigInvalidException {
+ assertSubsectionRoundTrip("", "\"\"");
+ assertSubsectionRoundTrip("x", "\"x\"");
+ assertSubsectionRoundTrip(" x", "\" x\"");
+ assertSubsectionRoundTrip("x ", "\"x \"");
+ assertSubsectionRoundTrip(" x ", "\" x \"");
+ assertSubsectionRoundTrip("x y", "\"x y\"");
+ assertSubsectionRoundTrip("x y", "\"x y\"");
+ assertSubsectionRoundTrip("x\\y", "\"x\\\\y\"");
+ assertSubsectionRoundTrip("x\"y", "\"x\\\"y\"");
+
+ // Unlike for values, \b and \t are not escaped.
+ assertSubsectionRoundTrip("x\by", "\"x\by\"");
+ assertSubsectionRoundTrip("x\ty", "\"x\ty\"");
+ }
+
+ @Test
+ public void testParseInvalidValues() {
+ assertInvalidValue(JGitText.get().newlineInQuotesNotAllowed, "x\"\n\"y");
+ assertInvalidValue(JGitText.get().endOfFileInEscape, "x\\");
+ assertInvalidValue(
+ MessageFormat.format(JGitText.get().badEscape, 'q'), "x\\q");
+ }
+
+ @Test
+ public void testParseInvalidSubsections() {
+ assertInvalidSubsection(
+ JGitText.get().newlineInQuotesNotAllowed, "\"x\ny\"");
+ }
+
+ @Test
+ public void testDropBackslashFromInvalidEscapeSequenceInSubsectionName()
+ throws ConfigInvalidException {
+ assertEquals("x0", parseEscapedSubsection("\"x\\0\""));
+ assertEquals("xq", parseEscapedSubsection("\"x\\q\""));
+ // Unlike for values, \b, \n, and \t are not valid escape sequences.
+ assertEquals("xb", parseEscapedSubsection("\"x\\b\""));
+ assertEquals("xn", parseEscapedSubsection("\"x\\n\""));
+ assertEquals("xt", parseEscapedSubsection("\"x\\t\""));
+ }
+
+ private static void assertValueRoundTrip(String value)
+ throws ConfigInvalidException {
+ assertValueRoundTrip(value, value);
+ }
+
+ private static void assertValueRoundTrip(String value, String expectedEscaped)
+ throws ConfigInvalidException {
+ String escaped = Config.escapeValue(value);
+ assertEquals("escape failed;", expectedEscaped, escaped);
+ assertEquals("parse failed;", value, parseEscapedValue(escaped));
+ }
+
+ private static String parseEscapedValue(String escapedValue)
+ throws ConfigInvalidException {
+ String text = "[foo]\nbar=" + escapedValue;
+ Config c = parse(text);
+ return c.getString("foo", null, "bar");
+ }
+
+ private static void assertInvalidValue(String expectedMessage,
+ String escapedValue) {
+ try {
+ parseEscapedValue(escapedValue);
+ fail("expected ConfigInvalidException");
+ } catch (ConfigInvalidException e) {
+ assertEquals(expectedMessage, e.getMessage());
+ }
+ }
+
+ private static void assertSubsectionRoundTrip(String subsection,
+ String expectedEscaped) throws ConfigInvalidException {
+ String escaped = Config.escapeSubsection(subsection);
+ assertEquals("escape failed;", expectedEscaped, escaped);
+ assertEquals("parse failed;", subsection, parseEscapedSubsection(escaped));
+ }
+
+ private static String parseEscapedSubsection(String escapedSubsection)
+ throws ConfigInvalidException {
+ String text = "[foo " + escapedSubsection + "]\nbar = value";
+ Config c = parse(text);
+ Set<String> subsections = c.getSubsections("foo");
+ assertEquals("only one section", 1, subsections.size());
+ return subsections.iterator().next();
+ }
+
+ private static void assertIllegalArgumentException(Runnable r) {
+ try {
+ r.run();
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ }
+
+ private static void assertInvalidSubsection(String expectedMessage,
+ String escapedSubsection) {
+ try {
+ parseEscapedSubsection(escapedSubsection);
+ fail("expected ConfigInvalidException");
+ } catch (ConfigInvalidException e) {
+ assertEquals(expectedMessage, e.getMessage());
+ }
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
index 05573b9468..4d42bd19c5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
@@ -218,8 +218,8 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
/**
* Reset hard from unclean condition.
* <p>
- * WorkDir: Empty <br/>
- * Index: f/g <br/>
+ * WorkDir: Empty <br>
+ * Index: f/g <br>
* Merge: x
*
* @throws Exception
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 476c4e5edf..f6879b968b 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
@@ -45,6 +45,7 @@
package org.eclipse.jgit.lib;
import static java.lang.Integer.valueOf;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.junit.JGitTestUtil.concat;
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH;
import static org.eclipse.jgit.lib.Constants.OBJ_BAD;
@@ -68,7 +69,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
-import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import org.eclipse.jgit.errors.CorruptObjectException;
@@ -1556,11 +1556,11 @@ public class ObjectCheckerTest {
@Test
public void testInvalidTreeDuplicateNames5()
- throws UnsupportedEncodingException, CorruptObjectException {
+ throws CorruptObjectException {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
entry(b, "100644 a");
- byte[] data = b.toString().getBytes("UTF-8");
+ byte[] data = b.toString().getBytes(UTF_8);
checker.setSafeForWindows(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1570,11 +1570,11 @@ public class ObjectCheckerTest {
@Test
public void testInvalidTreeDuplicateNames6()
- throws UnsupportedEncodingException, CorruptObjectException {
+ throws CorruptObjectException {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
entry(b, "100644 a");
- byte[] data = b.toString().getBytes("UTF-8");
+ byte[] data = b.toString().getBytes(UTF_8);
checker.setSafeForMacOS(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1584,11 +1584,11 @@ public class ObjectCheckerTest {
@Test
public void testInvalidTreeDuplicateNames7()
- throws UnsupportedEncodingException, CorruptObjectException {
+ throws CorruptObjectException {
StringBuilder b = new StringBuilder();
entry(b, "100644 \u0065\u0301");
entry(b, "100644 \u00e9");
- byte[] data = b.toString().getBytes("UTF-8");
+ byte[] data = b.toString().getBytes(UTF_8);
checker.setSafeForMacOS(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1598,11 +1598,11 @@ public class ObjectCheckerTest {
@Test
public void testInvalidTreeDuplicateNames8()
- throws UnsupportedEncodingException, CorruptObjectException {
+ throws CorruptObjectException {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
checker.setSafeForMacOS(true);
- checker.checkTree(b.toString().getBytes("UTF-8"));
+ checker.checkTree(b.toString().getBytes(UTF_8));
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
index d8b8750ba3..3272d598bc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
@@ -65,8 +65,12 @@ import org.eclipse.jgit.errors.NoMergeBaseException;
import org.eclipse.jgit.errors.NoMergeBaseException.MergeBaseFailureReason;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.junit.TestRepository;
+import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.lib.ObjectLoader;
+import org.eclipse.jgit.lib.ObjectReader;
+import org.eclipse.jgit.lib.ObjectStream;
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
@@ -689,6 +693,143 @@ public class ResolveMergerTest extends RepositoryTestCase {
}
}
+
+ /**
+ * Merging a change involving large binary files should short-circuit reads.
+ *
+ * @param strategy
+ * @throws Exception
+ */
+ @Theory
+ public void checkContentMergeLargeBinaries(MergeStrategy strategy) throws Exception {
+ Git git = Git.wrap(db);
+ final int LINELEN = 72;
+
+ // setup a merge that would work correctly if we disconsider the stray '\0'
+ // that the file contains near the start.
+ byte[] binary = new byte[LINELEN * 2000];
+ for (int i = 0; i < binary.length; i++) {
+ binary[i] = (byte)((i % LINELEN) == 0 ? '\n' : 'x');
+ }
+ binary[50] = '\0';
+
+ writeTrashFile("file", new String(binary, UTF_8));
+ git.add().addFilepattern("file").call();
+ RevCommit first = git.commit().setMessage("added file").call();
+
+ // Generate an edit in a single line.
+ int idx = LINELEN * 1200 + 1;
+ byte save = binary[idx];
+ binary[idx] = '@';
+ writeTrashFile("file", new String(binary, UTF_8));
+
+ binary[idx] = save;
+ git.add().addFilepattern("file").call();
+ RevCommit masterCommit = git.commit().setAll(true)
+ .setMessage("modified file l 1200").call();
+
+ git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call();
+ binary[LINELEN * 1500 + 1] = '!';
+ writeTrashFile("file", new String(binary, UTF_8));
+ git.add().addFilepattern("file").call();
+ RevCommit sideCommit = git.commit().setAll(true)
+ .setMessage("modified file l 1500").call();
+
+ try (ObjectInserter ins = db.newObjectInserter()) {
+ // Check that we don't read the large blobs.
+ ObjectInserter forbidInserter = new ObjectInserter.Filter() {
+ @Override
+ protected ObjectInserter delegate() {
+ return ins;
+ }
+
+ @Override
+ public ObjectReader newReader() {
+ return new BigReadForbiddenReader(super.newReader(), 8000);
+ }
+ };
+
+ ResolveMerger merger =
+ (ResolveMerger) strategy.newMerger(forbidInserter, db.getConfig());
+ boolean noProblems = merger.merge(masterCommit, sideCommit);
+ assertFalse(noProblems);
+ }
+ }
+
+ /**
+ * Throws an exception if reading beyond limit.
+ */
+ class BigReadForbiddenStream extends ObjectStream.Filter {
+ int limit;
+
+ BigReadForbiddenStream(ObjectStream orig, int limit) {
+ super(orig.getType(), orig.getSize(), orig);
+ this.limit = limit;
+ }
+
+ @Override
+ public long skip(long n) throws IOException {
+ limit -= n;
+ if (limit < 0) {
+ throw new IllegalStateException();
+ }
+
+ return super.skip(n);
+ }
+
+ @Override
+ public int read() throws IOException {
+ int r = super.read();
+ limit--;
+ if (limit < 0) {
+ throw new IllegalStateException();
+ }
+ return r;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ int n = super.read(b, off, len);
+ limit -= n;
+ if (limit < 0) {
+ throw new IllegalStateException();
+ }
+ return n;
+ }
+ }
+
+ class BigReadForbiddenReader extends ObjectReader.Filter {
+ ObjectReader delegate;
+ int limit;
+
+ @Override
+ protected ObjectReader delegate() {
+ return delegate;
+ }
+
+ BigReadForbiddenReader(ObjectReader delegate, int limit) {
+ this.delegate = delegate;
+ this.limit = limit;
+ }
+
+ @Override
+ public ObjectLoader open(AnyObjectId objectId, int typeHint) throws IOException {
+ ObjectLoader orig = super.open(objectId, typeHint);
+ return new ObjectLoader.Filter() {
+ @Override
+ protected ObjectLoader delegate() {
+ return orig;
+ }
+
+ @Override
+ public ObjectStream openStream() throws IOException {
+ ObjectStream os = orig.openStream();
+ return new BigReadForbiddenStream(os, limit);
+ }
+ };
+ }
+ }
+
@Theory
public void checkContentMergeConflict(MergeStrategy strategy)
throws Exception {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
index 1a158425c9..88f240bb1f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.revwalk;
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -113,7 +114,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
assertNull(c.getTree());
assertNull(c.parents);
- c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
+ c.parseCanonical(rw, body.toString().getBytes(UTF_8));
assertNotNull(c.getTree());
assertEquals(treeId, c.getTree().getId());
assertSame(rw.lookupTree(treeId), c.getTree());
@@ -147,7 +148,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
return c;
}
@@ -160,7 +161,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
assertEquals("", c.getFullMessage());
assertEquals("", c.getShortMessage());
@@ -175,7 +176,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent());
assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent());
@@ -184,13 +185,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_implicit_UTF8_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
- b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("UTF-8"));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -204,13 +205,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_implicit_mixed_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
- b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("ISO-8859-1"));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -259,14 +260,14 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_explicit_bad_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
- b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("ISO-8859-1"));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
- b.write("encoding EUC-JP\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("Hi\n".getBytes("UTF-8"));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
+ b.write("encoding EUC-JP\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("Hi\n".getBytes(UTF_8));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -290,14 +291,14 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_explicit_bad_encoded2() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
- b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes("UTF-8"));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes("UTF-8"));
- b.write("encoding ISO-8859-1\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("Hi\n".getBytes("UTF-8"));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
+ b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("Hi\n".getBytes(UTF_8));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
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 95e7ca6d56..122a3973d0 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
@@ -60,6 +60,7 @@ public class RevObjectTest extends RevWalkTestCase {
assertSame(a, a.getId());
}
+ @SuppressWarnings("unlikely-arg-type")
@Test
public void testEquals() throws Exception {
final RevCommit a1 = commit();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
index f97043b7e8..38bd371b90 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.revwalk;
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -97,7 +98,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, b.toString().getBytes("UTF-8"));
+ c.parseCanonical(rw, b.toString().getBytes(UTF_8));
assertNotNull(c.getObject());
assertEquals(id, c.getObject().getId());
assertSame(rw.lookupAny(id, typeCode), c.getObject());
@@ -140,7 +141,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
+ c.parseCanonical(rw, body.toString().getBytes(UTF_8));
assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject());
@@ -188,7 +189,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, body.toString().getBytes("UTF-8"));
+ c.parseCanonical(rw, body.toString().getBytes(UTF_8));
assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject());
@@ -212,7 +213,7 @@ public class RevTagParseTest extends RepositoryTestCase {
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes("UTF-8"));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
return c;
}
@@ -220,17 +221,17 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_implicit_UTF8_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes("UTF-8"));
- b.write("type tree\n".getBytes("UTF-8"));
- b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
+ .getBytes(UTF_8));
+ b.write("type tree\n".getBytes(UTF_8));
+ b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
- .getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
+ .getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -245,16 +246,15 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_implicit_mixed_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes("UTF-8"));
- b.write("type tree\n".getBytes("UTF-8"));
- b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
- b
- .write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
- .getBytes("ISO-8859-1"));
- b.write("\n".getBytes("UTF-8"));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
+ .getBytes(UTF_8));
+ b.write("type tree\n".getBytes(UTF_8));
+ b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
+ b.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
+ .getBytes(ISO_8859_1));
+ b.write("\n".getBytes(UTF_8));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -307,17 +307,17 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_explicit_bad_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes("UTF-8"));
- b.write("type tree\n".getBytes("UTF-8"));
- b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
+ .getBytes(UTF_8));
+ b.write("type tree\n".getBytes(UTF_8));
+ b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
- .getBytes("ISO-8859-1"));
- b.write("encoding EUC-JP\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("Hi\n".getBytes("UTF-8"));
+ .getBytes(ISO_8859_1));
+ b.write("encoding EUC-JP\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("Hi\n".getBytes(UTF_8));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -342,17 +342,17 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_explicit_bad_encoded2() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes("UTF-8"));
- b.write("type tree\n".getBytes("UTF-8"));
- b.write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
+ .getBytes(UTF_8));
+ b.write("type tree\n".getBytes(UTF_8));
+ b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
- .getBytes("UTF-8"));
- b.write("encoding ISO-8859-1\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
- b.write("\n".getBytes("UTF-8"));
- b.write("Hi\n".getBytes("UTF-8"));
+ .getBytes(UTF_8));
+ b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("Hi\n".getBytes(UTF_8));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java
index 1860185493..ab2705cbec 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java
@@ -145,8 +145,9 @@ public class RevWalkFollowFilterTest extends RevWalkTestCase {
/**
* Assert which renames should have happened, in traversal order.
+ *
* @param expectedRenames
- * the rename specs, each one in the form "srcPath->destPath"
+ * the rename specs, each one in the form "srcPath-&gt;destPath"
*/
protected void assertRenames(String... expectedRenames) {
Assert.assertEquals("Unexpected number of renames. Expected: " +
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
index ee845c5325..2a54dc6140 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
@@ -42,6 +42,8 @@
*/
package org.eclipse.jgit.storage.file;
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.util.FileUtils.pathToString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -103,7 +105,7 @@ public class FileBasedConfigTest {
@Test
public void testUTF8withoutBOM() throws IOException, ConfigInvalidException {
- final File file = createFile(CONTENT1.getBytes("UTF-8"));
+ final File file = createFile(CONTENT1.getBytes(UTF_8));
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
config.load();
assertEquals(ALICE, config.getString(USER, null, NAME));
@@ -119,7 +121,7 @@ public class FileBasedConfigTest {
bos1.write(0xEF);
bos1.write(0xBB);
bos1.write(0xBF);
- bos1.write(CONTENT1.getBytes("UTF-8"));
+ bos1.write(CONTENT1.getBytes(UTF_8));
final File file = createFile(bos1.toByteArray());
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
@@ -133,7 +135,7 @@ public class FileBasedConfigTest {
bos2.write(0xEF);
bos2.write(0xBB);
bos2.write(0xBF);
- bos2.write(CONTENT2.getBytes("UTF-8"));
+ bos2.write(CONTENT2.getBytes(UTF_8));
assertArrayEquals(bos2.toByteArray(), IO.readFully(file));
}
@@ -157,9 +159,89 @@ public class FileBasedConfigTest {
assertArrayEquals(bos2.toByteArray(), IO.readFully(file));
}
+ @Test
+ public void testIncludeAbsolute()
+ throws IOException, ConfigInvalidException {
+ final File includedFile = createFile(CONTENT1.getBytes());
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ bos.write("[include]\npath=".getBytes());
+ bos.write(pathToString(includedFile).getBytes());
+
+ final File file = createFile(bos.toByteArray());
+ final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
+ config.load();
+ assertEquals(ALICE, config.getString(USER, null, NAME));
+ }
+
+ @Test
+ public void testIncludeRelativeDot()
+ throws IOException, ConfigInvalidException {
+ final File includedFile = createFile(CONTENT1.getBytes(), "dir1");
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ bos.write("[include]\npath=".getBytes());
+ bos.write(("./" + includedFile.getName()).getBytes());
+
+ final File file = createFile(bos.toByteArray(), "dir1");
+ final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
+ config.load();
+ assertEquals(ALICE, config.getString(USER, null, NAME));
+ }
+
+ @Test
+ public void testIncludeRelativeDotDot()
+ throws IOException, ConfigInvalidException {
+ final File includedFile = createFile(CONTENT1.getBytes(), "dir1");
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ bos.write("[include]\npath=".getBytes());
+ bos.write(("../" + includedFile.getParentFile().getName() + "/"
+ + includedFile.getName()).getBytes());
+
+ final File file = createFile(bos.toByteArray(), "dir2");
+ final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
+ config.load();
+ assertEquals(ALICE, config.getString(USER, null, NAME));
+ }
+
+ @Test
+ public void testIncludeRelativeDotDotNotFound()
+ throws IOException, ConfigInvalidException {
+ final File includedFile = createFile(CONTENT1.getBytes());
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ bos.write("[include]\npath=".getBytes());
+ bos.write(("../" + includedFile.getName()).getBytes());
+
+ final File file = createFile(bos.toByteArray());
+ final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
+ config.load();
+ assertEquals(null, config.getString(USER, null, NAME));
+ }
+
+ @Test
+ public void testIncludeWithTilde()
+ throws IOException, ConfigInvalidException {
+ final File includedFile = createFile(CONTENT1.getBytes(), "home");
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ bos.write("[include]\npath=".getBytes());
+ bos.write(("~/" + includedFile.getName()).getBytes());
+
+ final File file = createFile(bos.toByteArray(), "repo");
+ final FS fs = FS.DETECTED.newInstance();
+ fs.setUserHome(includedFile.getParentFile());
+
+ final FileBasedConfig config = new FileBasedConfig(file, fs);
+ config.load();
+ assertEquals(ALICE, config.getString(USER, null, NAME));
+ }
+
private File createFile(byte[] content) throws IOException {
- trash.mkdirs();
- File f = File.createTempFile(getClass().getName(), null, trash);
+ return createFile(content, null);
+ }
+
+ private File createFile(byte[] content, String subdir) throws IOException {
+ File dir = subdir != null ? new File(trash, subdir) : trash;
+ dir.mkdirs();
+
+ File f = File.createTempFile(getClass().getName(), null, dir);
FileOutputStream os = new FileOutputStream(f, true);
try {
os.write(content);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java
new file mode 100644
index 0000000000..df4b96398f
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java
@@ -0,0 +1,251 @@
+/*
+ * Copyright (C) 2017, Two Sigma Open Source
+ * 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.submodule;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.SubmoduleDeinitCommand;
+import org.eclipse.jgit.api.SubmoduleDeinitResult;
+import org.eclipse.jgit.api.SubmoduleUpdateCommand;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.dircache.DirCacheEditor;
+import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
+import org.eclipse.jgit.dircache.DirCacheEntry;
+import org.eclipse.jgit.junit.JGitTestUtil;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.lib.ConfigConstants;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.FileMode;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.storage.file.FileBasedConfig;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit tests of {@link SubmoduleDeinitCommand}
+ */
+public class SubmoduleDeinitTest extends RepositoryTestCase {
+
+ @Test
+ public void repositoryWithNoSubmodules() throws GitAPIException {
+ SubmoduleDeinitCommand command = new SubmoduleDeinitCommand(db);
+ Collection<SubmoduleDeinitResult> modules = command.call();
+ assertNotNull(modules);
+ assertTrue(modules.isEmpty());
+ }
+
+ @Test
+ public void alreadyClosedSubmodule() throws Exception {
+ final String path = "sub";
+ Git git = Git.wrap(db);
+
+ commitSubmoduleCreation(path, git);
+
+ SubmoduleDeinitResult result = runDeinit(new SubmoduleDeinitCommand(db).addPath("sub"));
+ assertEquals(path, result.getPath());
+ assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.ALREADY_DEINITIALIZED, result.getStatus());
+ }
+
+ @Test
+ public void dirtySubmoduleBecauseUntracked() throws Exception {
+ final String path = "sub";
+ Git git = Git.wrap(db);
+
+ commitSubmoduleCreation(path, git);
+
+ Collection<String> updated = new SubmoduleUpdateCommand(db).addPath(path).setFetch(false).call();
+ assertEquals(1, updated.size());
+
+ File submoduleDir = assertSubmoduleIsInitialized();
+ SubmoduleWalk generator;
+
+ write(new File(submoduleDir, "untracked"), "untracked");
+
+ SubmoduleDeinitResult result = runDeinit(new SubmoduleDeinitCommand(db).addPath("sub"));
+ assertEquals(path, result.getPath());
+ assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus());
+
+ generator = SubmoduleWalk.forIndex(db);
+ assertTrue(generator.next());
+ assertTrue(submoduleDir.isDirectory());
+ assertNotEquals(0, submoduleDir.list().length);
+ }
+
+ @Test
+ public void dirtySubmoduleBecauseNewCommit() throws Exception {
+ final String path = "sub";
+ Git git = Git.wrap(db);
+
+ commitSubmoduleCreation(path, git);
+
+ Collection<String> updated = new SubmoduleUpdateCommand(db).addPath(path).setFetch(false).call();
+ assertEquals(1, updated.size());
+
+ File submoduleDir = assertSubmoduleIsInitialized();
+ SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
+ generator.next();
+
+ //want to create a commit inside the repo...
+ Repository submoduleLocalRepo = generator.getRepository();
+ JGitTestUtil.writeTrashFile(submoduleLocalRepo, "file.txt", "new data");
+ Git.wrap(submoduleLocalRepo).commit().setAll(true).setMessage("local commit").call();
+
+ SubmoduleDeinitResult result = runDeinit(new SubmoduleDeinitCommand(db).addPath("sub"));
+ assertEquals(path, result.getPath());
+ assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.DIRTY, result.getStatus());
+
+ generator = SubmoduleWalk.forIndex(db);
+ assertTrue(generator.next());
+ assertTrue(submoduleDir.isDirectory());
+ assertNotEquals(0, submoduleDir.list().length);
+ }
+
+ private File assertSubmoduleIsInitialized() throws IOException {
+ SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
+ assertTrue(generator.next());
+ File submoduleDir = new File(db.getWorkTree(), generator.getPath());
+ assertTrue(submoduleDir.isDirectory());
+ assertNotEquals(0, submoduleDir.list().length);
+ return submoduleDir;
+ }
+
+ @Test
+ public void dirtySubmoduleWithForce() throws Exception {
+ final String path = "sub";
+ Git git = Git.wrap(db);
+
+ commitSubmoduleCreation(path, git);
+
+ Collection<String> updated = new SubmoduleUpdateCommand(db).addPath(path).setFetch(false).call();
+ assertEquals(1, updated.size());
+
+ File submoduleDir = assertSubmoduleIsInitialized();
+
+ write(new File(submoduleDir, "untracked"), "untracked");
+
+ SubmoduleDeinitCommand command = new SubmoduleDeinitCommand(db).addPath("sub").setForce(true);
+ SubmoduleDeinitResult result = runDeinit(command);
+ assertEquals(path, result.getPath());
+ assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.FORCED, result.getStatus());
+
+ SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
+ assertTrue(generator.next());
+ assertTrue(submoduleDir.isDirectory());
+ assertEquals(0, submoduleDir.list().length);
+ }
+
+ @Test
+ public void cleanSubmodule() throws Exception {
+ final String path = "sub";
+ Git git = Git.wrap(db);
+
+ commitSubmoduleCreation(path, git);
+
+ Collection<String> updated = new SubmoduleUpdateCommand(db).addPath(path).setFetch(false).call();
+ assertEquals(1, updated.size());
+
+ File submoduleDir = assertSubmoduleIsInitialized();
+
+ SubmoduleDeinitResult result = runDeinit(new SubmoduleDeinitCommand(db).addPath("sub"));
+ assertEquals(path, result.getPath());
+ assertEquals(SubmoduleDeinitCommand.SubmoduleDeinitStatus.SUCCESS, result.getStatus());
+
+ SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
+ assertTrue(generator.next());
+ assertTrue(submoduleDir.isDirectory());
+ assertEquals(0, submoduleDir.list().length);
+ }
+
+ private SubmoduleDeinitResult runDeinit(SubmoduleDeinitCommand command) throws GitAPIException {
+ Collection<SubmoduleDeinitResult> deinitialized = command.call();
+ assertNotNull(deinitialized);
+ assertEquals(1, deinitialized.size());
+ return deinitialized.iterator().next();
+ }
+
+
+ private RevCommit commitSubmoduleCreation(String path, Git git) throws IOException, GitAPIException {
+ writeTrashFile("file.txt", "content");
+ git.add().addFilepattern("file.txt").call();
+ final RevCommit commit = git.commit().setMessage("create file").call();
+
+ DirCache cache = db.lockDirCache();
+ DirCacheEditor editor = cache.editor();
+ editor.add(new PathEdit(path) {
+
+ @Override
+ public void apply(DirCacheEntry ent) {
+ ent.setFileMode(FileMode.GITLINK);
+ ent.setObjectId(commit);
+ }
+ });
+ editor.commit();
+
+ StoredConfig config = db.getConfig();
+ config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
+ ConfigConstants.CONFIG_KEY_URL, db.getDirectory().toURI()
+ .toString());
+ config.save();
+
+ FileBasedConfig modulesConfig = new FileBasedConfig(new File(
+ db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
+ modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
+ ConfigConstants.CONFIG_KEY_PATH, path);
+ modulesConfig.save();
+
+ new File(db.getWorkTree(), "sub").mkdir();
+ git.add().addFilepattern(Constants.DOT_GIT_MODULES).call();
+ git.commit().setMessage("create submodule").call();
+ return commit;
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java
index 274fa539cb..7d54399ef3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java
@@ -206,7 +206,7 @@ public class SymlinksTest extends RepositoryTestCase {
* Steps: 1.Add file 'b' 2.Commit 3.Create branch '1' 4.Add symlink 'a'
* 5.Commit 6.Checkout branch '1'
*
- * The working tree should not contain 'a' -> FileMode.MISSING after the
+ * The working tree should not contain 'a' -&gt; FileMode.MISSING after the
* checkout.
*
* @throws Exception
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java
index a57ef40b62..85a8aa7b8b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/test/resources/SampleDataRepositoryTestCase.java
@@ -79,8 +79,7 @@ public abstract class SampleDataRepositoryTestCase extends RepositoryTestCase {
"pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa",
"pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12"
};
- final File packDir = new File(repo.getObjectDatabase().getDirectory(),
- "pack");
+ final File packDir = repo.getObjectDatabase().getPackDirectory();
for (String n : packs) {
JGitTestUtil.copyTestResource(n + ".pack", new File(packDir, n + ".pack"));
JGitTestUtil.copyTestResource(n + ".idx", new File(packDir, n + ".idx"));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
index b2497b879a..5d9bdbdbad 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
@@ -47,7 +47,6 @@
package org.eclipse.jgit.transport;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -270,7 +269,7 @@ public class PackParserTest extends RepositoryTestCase {
fail("PackParser should have failed");
} catch (TooLargeObjectInPackException e) {
assertTrue(e.getMessage().contains("13")); // max obj size
- assertFalse(e.getMessage().contains("14")); // no delta size
+ assertTrue(e.getMessage().contains("14")); // delta size
}
}
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 0e4e9ccd41..c16c1b2a93 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
@@ -184,7 +184,7 @@ public class PushConnectionTest {
updates.put(rru.getRemoteName(), rru);
}
- server.getConfig().setInt("receive", null, "maxCommandBytes", 190);
+ server.getConfig().setInt("receive", null, "maxCommandBytes", 195);
try (Transport tn = testProtocol.open(uri, client, "server");
PushConnection connection = tn.openPush()) {
try {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
index e55d373347..1eb218c865 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
@@ -198,6 +198,10 @@ public class URIishTest {
URIish u = new URIish(str);
assertEquals("file", u.getScheme());
assertFalse(u.isRemote());
+ assertEquals(null, u.getHost());
+ assertEquals(-1, u.getPort());
+ assertEquals(null, u.getUser());
+ assertEquals(null, u.getPass());
assertEquals("D:/m y", u.getRawPath());
assertEquals("D:/m y", u.getPath());
assertEquals("file:///D:/m y", u.toString());
@@ -206,6 +210,84 @@ public class URIishTest {
}
@Test
+ public void testFileProtoWindowsWithHost() throws Exception {
+ final String str = "file://localhost/D:/m y";
+ URIish u = new URIish(str);
+ assertEquals("file", u.getScheme());
+ assertTrue(u.isRemote());
+ assertEquals("localhost", u.getHost());
+ assertEquals(-1, u.getPort());
+ assertEquals(null, u.getUser());
+ assertEquals(null, u.getPass());
+ assertEquals("D:/m y", u.getRawPath());
+ assertEquals("D:/m y", u.getPath());
+ assertEquals("file://localhost/D:/m y", u.toString());
+ assertEquals("file://localhost/D:/m%20y", u.toASCIIString());
+ assertEquals(u, new URIish(str));
+ }
+
+ @Test
+ public void testFileProtoWindowsWithHostAndPort() throws Exception {
+ final String str = "file://localhost:80/D:/m y";
+ URIish u = new URIish(str);
+ assertEquals("file", u.getScheme());
+ assertTrue(u.isRemote());
+ assertEquals("localhost", u.getHost());
+ assertEquals(80, u.getPort());
+ assertEquals(null, u.getUser());
+ assertEquals(null, u.getPass());
+ assertEquals("D:/m y", u.getRawPath());
+ assertEquals("D:/m y", u.getPath());
+ assertEquals("file://localhost:80/D:/m y", u.toString());
+ assertEquals("file://localhost:80/D:/m%20y", u.toASCIIString());
+ assertEquals(u, new URIish(str));
+ }
+
+ @Test
+ public void testFileProtoWindowsWithHostAndEmptyPortIsAmbiguous()
+ throws Exception {
+ final String str = "file://localhost:/D:/m y";
+ URIish u = new URIish(str);
+ assertEquals("file", u.getScheme());
+ assertFalse(u.isRemote());
+ assertEquals(null, u.getHost());
+ assertEquals(-1, u.getPort());
+ assertEquals(null, u.getUser());
+ assertEquals(null, u.getPass());
+ assertEquals("localhost:/D:/m y", u.getRawPath());
+ assertEquals("localhost:/D:/m y", u.getPath());
+ assertEquals("file:///localhost:/D:/m y", u.toString());
+ assertEquals("file:///localhost:/D:/m%20y", u.toASCIIString());
+ assertEquals(u, new URIish(str));
+ }
+
+ @Test
+ public void testFileProtoWindowsMissingHostSlash() throws Exception {
+ final String str = "file://D:/m y";
+ URIish u = new URIish(str);
+ assertEquals("file", u.getScheme());
+ assertFalse(u.isRemote());
+ assertEquals("D:/m y", u.getRawPath());
+ assertEquals("D:/m y", u.getPath());
+ assertEquals("file:///D:/m y", u.toString());
+ assertEquals("file:///D:/m%20y", u.toASCIIString());
+ assertEquals(u, new URIish(str));
+ }
+
+ @Test
+ public void testFileProtoWindowsMissingHostSlash2() throws Exception {
+ final String str = "file://D: /m y";
+ URIish u = new URIish(str);
+ assertEquals("file", u.getScheme());
+ assertFalse(u.isRemote());
+ assertEquals("D: /m y", u.getRawPath());
+ assertEquals("D: /m y", u.getPath());
+ assertEquals("file:///D: /m y", u.toString());
+ assertEquals("file:///D:%20/m%20y", u.toASCIIString());
+ assertEquals(u, new URIish(str));
+ }
+
+ @Test
public void testGitProtoUnix() throws Exception {
final String str = "git://example.com/home/m y";
URIish u = new URIish(str);
@@ -421,6 +503,22 @@ public class URIishTest {
}
@Test
+ public void testSshProtoHostWithEmptyPortAndPath() throws Exception {
+ final String str = "ssh://example.com:/path";
+ URIish u = new URIish(str);
+ assertEquals("ssh", u.getScheme());
+ assertTrue(u.isRemote());
+ assertEquals("/path", u.getRawPath());
+ assertEquals("/path", u.getPath());
+ assertEquals("example.com", u.getHost());
+ assertEquals(-1, u.getPort());
+ assertEquals("ssh://example.com/path", u.toString());
+ assertEquals("ssh://example.com/path", u.toASCIIString());
+ assertEquals(u, new URIish(str));
+ assertEquals(u, new URIish("ssh://example.com/path"));
+ }
+
+ @Test
public void testSshProtoWithUserAndPort() throws Exception {
final String str = "ssh://user@example.com:33/some/p ath";
URIish u = new URIish(str);
@@ -891,13 +989,6 @@ public class URIishTest {
}
@Test
- public void testMissingPort() throws URISyntaxException {
- final String incorrectSshUrl = "ssh://some-host:/path/to/repository.git";
- URIish u = new URIish(incorrectSshUrl);
- assertFalse(TransportGitSsh.PROTO_SSH.canHandle(u));
- }
-
- @Test
public void testALot() throws URISyntaxException {
// user pass host port path
// 1 2 3 4 5
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 27c7674e9c..a8127abd36 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,24 +4,33 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
+import org.eclipse.jgit.errors.TransportException;
+import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector;
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.Repository;
+import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
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.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
/**
* Tests for server upload-pack utilities.
*/
public class UploadPackTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
private URIish uri;
private TestProtocol<Object> testProtocol;
@@ -32,23 +41,14 @@ public class UploadPackTest {
private InMemoryRepository client;
- private RevCommit commit0;
-
- private RevCommit commit1;
-
- private RevCommit tip;
+ private TestRepository<InMemoryRepository> remote;
@Before
public void setUp() throws Exception {
server = newRepo("server");
client = newRepo("client");
- TestRepository<InMemoryRepository> remote =
- new TestRepository<>(server);
- commit0 = remote.commit().message("0").create();
- commit1 = remote.commit().message("1").parent(commit0).create();
- tip = remote.commit().message("2").parent(commit1).create();
- remote.update("master", tip);
+ remote = new TestRepository<>(server);
}
@After
@@ -60,8 +60,32 @@ public class UploadPackTest {
return new InMemoryRepository(new DfsRepositoryDescription(name));
}
+ private void generateBitmaps(InMemoryRepository repo) throws Exception {
+ new DfsGarbageCollector(repo).pack(null);
+ repo.scanForRepoChanges();
+ }
+
+ 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);
+ }
+
@Test
public void testFetchParentOfShallowCommit() throws Exception {
+ RevCommit commit0 = remote.commit().message("0").create();
+ RevCommit commit1 = remote.commit().message("1").parent(commit0).create();
+ RevCommit tip = remote.commit().message("2").parent(commit1).create();
+ remote.update("master", tip);
+
testProtocol = new TestProtocol<>(
new UploadPackFactory<Object>() {
@Override
@@ -87,4 +111,63 @@ public class UploadPackTest {
assertTrue(client.hasObject(commit0.toObjectId()));
}
}
+
+ @Test
+ public void testFetchUnreachableBlobWithBitmap() throws Exception {
+ RevBlob blob = remote.blob("foo");
+ remote.commit(remote.tree(remote.file("foo", blob)));
+ generateBitmaps(server);
+
+ testProtocol = generateReachableCommitUploadPackProtocol();
+ uri = testProtocol.register(ctx, server);
+
+ assertFalse(client.hasObject(blob.toObjectId()));
+
+ try (Transport tn = testProtocol.open(uri, client, "server")) {
+ thrown.expect(TransportException.class);
+ thrown.expectMessage(Matchers.containsString(
+ "want " + blob.name() + " not valid"));
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(blob.name())));
+ }
+ }
+
+ @Test
+ public void testFetchReachableBlobWithBitmap() throws Exception {
+ RevBlob blob = remote.blob("foo");
+ RevCommit commit = remote.commit(remote.tree(remote.file("foo", blob)));
+ remote.update("master", commit);
+ generateBitmaps(server);
+
+ testProtocol = generateReachableCommitUploadPackProtocol();
+ uri = testProtocol.register(ctx, server);
+
+ assertFalse(client.hasObject(blob.toObjectId()));
+
+ try (Transport tn = testProtocol.open(uri, client, "server")) {
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(blob.name())));
+ assertTrue(client.hasObject(blob.toObjectId()));
+ }
+ }
+
+ @Test
+ public void testFetchReachableBlobWithoutBitmap() throws Exception {
+ RevBlob blob = remote.blob("foo");
+ RevCommit commit = remote.commit(remote.tree(remote.file("foo", blob)));
+ remote.update("master", commit);
+
+ testProtocol = generateReachableCommitUploadPackProtocol();
+ uri = testProtocol.register(ctx, server);
+
+ assertFalse(client.hasObject(blob.toObjectId()));
+
+ try (Transport tn = testProtocol.open(uri, client, "server")) {
+ thrown.expect(TransportException.class);
+ thrown.expectMessage(Matchers.containsString(
+ "want " + blob.name() + " not valid"));
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(blob.name())));
+ }
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorWithTimeControl.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorWithTimeControl.java
index ff5730e72f..717a2f3b2c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorWithTimeControl.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorWithTimeControl.java
@@ -58,10 +58,10 @@ import org.eclipse.jgit.util.FS;
* <p>
* This iterator is configured by a list of strictly increasing long values
* t(0), t(1), ..., t(n). For each file with a modification between t(x) and
- * t(x+1) [ t(x) <= time < t(x+1) ] this iterator will report t(x). For files
- * with a modification time smaller t(0) a modification time of 0 is returned.
- * For files with a modification time greater or equal t(n) t(n) will be
- * returned.
+ * t(x+1) [ t(x) &lt;= time &lt; t(x+1) ] this iterator will report t(x). For
+ * files with a modification time smaller t(0) a modification time of 0 is
+ * returned. For files with a modification time greater or equal t(n) t(n) will
+ * be returned.
* <p>
* This class was written especially to test racy-git problems
*/
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java
index cc73c70c58..a6f33451ce 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java
@@ -43,14 +43,13 @@
package org.eclipse.jgit.util;
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.eclipse.jgit.util.QuotedString.GIT_PATH;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
-import java.io.UnsupportedEncodingException;
-
import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
@@ -63,12 +62,7 @@ public class QuotedStringGitPathStyleTest {
}
private static void assertDequote(final String exp, final String in) {
- final byte[] b;
- try {
- b = ('"' + in + '"').getBytes("ISO-8859-1");
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
+ final byte[] b = ('"' + in + '"').getBytes(ISO_8859_1);
final String r = GIT_PATH.dequote(b, 0, b.length);
assertEquals(exp, r);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java
index a8c576334e..f1b3da293d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawCharUtilTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.util;
+import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.eclipse.jgit.util.RawCharUtil.isWhitespace;
import static org.eclipse.jgit.util.RawCharUtil.trimLeadingWhitespace;
import static org.eclipse.jgit.util.RawCharUtil.trimTrailingWhitespace;
@@ -50,8 +51,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import java.io.UnsupportedEncodingException;
-
import org.junit.Test;
public class RawCharUtilTest {
@@ -78,37 +77,31 @@ public class RawCharUtilTest {
/**
* Test method for
* {@link RawCharUtil#trimTrailingWhitespace(byte[], int, int)}.
- *
- * @throws UnsupportedEncodingException
*/
@Test
- public void testTrimTrailingWhitespace()
- throws UnsupportedEncodingException {
- assertEquals(0, trimTrailingWhitespace("".getBytes("US-ASCII"), 0, 0));
- assertEquals(0, trimTrailingWhitespace(" ".getBytes("US-ASCII"), 0, 1));
- assertEquals(1, trimTrailingWhitespace("a ".getBytes("US-ASCII"), 0, 2));
- assertEquals(2,
- trimTrailingWhitespace(" a ".getBytes("US-ASCII"), 0, 3));
- assertEquals(3,
- trimTrailingWhitespace(" a".getBytes("US-ASCII"), 0, 3));
- assertEquals(6, trimTrailingWhitespace(
- " test ".getBytes("US-ASCII"), 2, 9));
+ public void testTrimTrailingWhitespace() {
+ assertEquals(0, trimTrailingWhitespace("".getBytes(US_ASCII), 0, 0));
+ assertEquals(0, trimTrailingWhitespace(" ".getBytes(US_ASCII), 0, 1));
+ assertEquals(1, trimTrailingWhitespace("a ".getBytes(US_ASCII), 0, 2));
+ assertEquals(2, trimTrailingWhitespace(" a ".getBytes(US_ASCII), 0, 3));
+ assertEquals(3, trimTrailingWhitespace(" a".getBytes(US_ASCII), 0, 3));
+ assertEquals(6,
+ trimTrailingWhitespace(" test ".getBytes(US_ASCII), 2, 9));
}
/**
* Test method for
* {@link RawCharUtil#trimLeadingWhitespace(byte[], int, int)}.
- *
- * @throws UnsupportedEncodingException
*/
@Test
- public void testTrimLeadingWhitespace() throws UnsupportedEncodingException {
- assertEquals(0, trimLeadingWhitespace("".getBytes("US-ASCII"), 0, 0));
- assertEquals(1, trimLeadingWhitespace(" ".getBytes("US-ASCII"), 0, 1));
- assertEquals(0, trimLeadingWhitespace("a ".getBytes("US-ASCII"), 0, 2));
- assertEquals(1, trimLeadingWhitespace(" a ".getBytes("US-ASCII"), 0, 3));
- assertEquals(2, trimLeadingWhitespace(" a".getBytes("US-ASCII"), 0, 3));
- assertEquals(2, trimLeadingWhitespace(" test ".getBytes("US-ASCII"),
+ public void testTrimLeadingWhitespace() {
+ assertEquals(0, trimLeadingWhitespace("".getBytes(US_ASCII), 0, 0));
+ assertEquals(1, trimLeadingWhitespace(" ".getBytes(US_ASCII), 0, 1));
+ assertEquals(0, trimLeadingWhitespace("a ".getBytes(US_ASCII), 0, 2));
+ assertEquals(1, trimLeadingWhitespace(" a ".getBytes(US_ASCII), 0, 3));
+ assertEquals(2, trimLeadingWhitespace(" a".getBytes(US_ASCII), 0, 3));
+ assertEquals(2,
+ trimLeadingWhitespace(" test ".getBytes(US_ASCII),
2, 9));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
index 6efdce6d77..0243798666 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtils_LineMapTest.java
@@ -43,11 +43,10 @@
package org.eclipse.jgit.util;
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull;
-import java.io.UnsupportedEncodingException;
-
import org.junit.Test;
public class RawParseUtils_LineMapTest {
@@ -65,29 +64,29 @@ public class RawParseUtils_LineMapTest {
}
@Test
- public void testTwoLineFooBar() throws UnsupportedEncodingException {
- final byte[] buf = "foo\nbar\n".getBytes("ISO-8859-1");
+ public void testTwoLineFooBar() {
+ final byte[] buf = "foo\nbar\n".getBytes(ISO_8859_1);
final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 4, buf.length}, asInts(map));
}
@Test
- public void testTwoLineNoLF() throws UnsupportedEncodingException {
- final byte[] buf = "foo\nbar".getBytes("ISO-8859-1");
+ public void testTwoLineNoLF() {
+ final byte[] buf = "foo\nbar".getBytes(ISO_8859_1);
final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
assertArrayEquals(new int[]{Integer.MIN_VALUE, 0, 4, buf.length}, asInts(map));
}
@Test
- public void testBinary() throws UnsupportedEncodingException {
- final byte[] buf = "xxxfoo\nb\0ar".getBytes("ISO-8859-1");
+ public void testBinary() {
+ final byte[] buf = "xxxfoo\nb\0ar".getBytes(ISO_8859_1);
final IntList map = RawParseUtils.lineMap(buf, 3, buf.length);
assertArrayEquals(new int[]{Integer.MIN_VALUE, 3, buf.length}, asInts(map));
}
@Test
- public void testFourLineBlanks() throws UnsupportedEncodingException {
- final byte[] buf = "foo\n\n\nbar\n".getBytes("ISO-8859-1");
+ public void testFourLineBlanks() {
+ final byte[] buf = "foo\n\n\nbar\n".getBytes(ISO_8859_1);
final IntList map = RawParseUtils.lineMap(buf, 0, buf.length);
assertArrayEquals(new int[]{
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
index 194fab47fc..e8566d2438 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
@@ -42,11 +42,10 @@
*/
package org.eclipse.jgit.util;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import java.io.UnsupportedEncodingException;
-
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.junit.Test;
@@ -94,11 +93,7 @@ public class RawSubStringPatternTest extends RepositoryTestCase {
}
private static RawCharSequence raw(String text) {
- try {
- byte[] bytes = text.getBytes("UTF-8");
- return new RawCharSequence(bytes, 0, bytes.length);
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
+ byte[] bytes = text.getBytes(UTF_8);
+ return new RawCharSequence(bytes, 0, bytes.length);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
index 40cac93f3b..38199d8aaf 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
@@ -44,12 +44,12 @@
package org.eclipse.jgit.util.io;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
import org.junit.Test;
@@ -129,10 +129,6 @@ public class AutoLFInputStreamTest {
}
private static byte[] asBytes(String in) {
- try {
- return in.getBytes("UTF-8");
- } catch (UnsupportedEncodingException ex) {
- throw new AssertionError();
- }
+ return in.getBytes(UTF_8);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
index 07789898a4..e6045a91bd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.util.sha1;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -51,7 +52,6 @@ import static org.junit.Assume.assumeTrue;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -95,15 +95,15 @@ public class SHA1Test {
.fromString("a9993e364706816aba3e25717850c26c9cd0d89d");
MessageDigest m = MessageDigest.getInstance("SHA-1");
- m.update(TEST1.getBytes(StandardCharsets.UTF_8));
+ m.update(TEST1.getBytes(UTF_8));
ObjectId m1 = ObjectId.fromRaw(m.digest());
SHA1 s = SHA1.newInstance();
- s.update(TEST1.getBytes(StandardCharsets.UTF_8));
+ s.update(TEST1.getBytes(UTF_8));
ObjectId s1 = ObjectId.fromRaw(s.digest());
s.reset();
- s.update(TEST1.getBytes(StandardCharsets.UTF_8));
+ s.update(TEST1.getBytes(UTF_8));
ObjectId s2 = s.toObjectId();
assertEquals(m1, s1);
@@ -117,15 +117,15 @@ public class SHA1Test {
.fromString("84983e441c3bd26ebaae4aa1f95129e5e54670f1");
MessageDigest m = MessageDigest.getInstance("SHA-1");
- m.update(TEST2.getBytes(StandardCharsets.UTF_8));
+ m.update(TEST2.getBytes(UTF_8));
ObjectId m1 = ObjectId.fromRaw(m.digest());
SHA1 s = SHA1.newInstance();
- s.update(TEST2.getBytes(StandardCharsets.UTF_8));
+ s.update(TEST2.getBytes(UTF_8));
ObjectId s1 = ObjectId.fromRaw(s.digest());
s.reset();
- s.update(TEST2.getBytes(StandardCharsets.UTF_8));
+ s.update(TEST2.getBytes(UTF_8));
ObjectId s2 = s.toObjectId();
assertEquals(m1, s1);

Back to the top