summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst/org')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java68
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java83
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java24
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java32
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java110
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackDescriptionTest.java293
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/PackSourceTest.java90
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java12
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java106
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java12
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/HugeCommitMessageTest.java95
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java29
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java54
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java138
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java18
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java102
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCullTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java203
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java63
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java321
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java22
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java405
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtilsTest.java43
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java14
61 files changed, 2053 insertions, 485 deletions
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 bb303cc411..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,7 +42,7 @@
package org.eclipse.jgit.api;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -150,8 +150,8 @@ public class EolStreamTypeUtilTest {
EolStreamType streamTypeWithBinaryCheck, String output,
String expectedConversion) throws Exception {
ByteArrayOutputStream b;
- byte[] outputBytes = output.getBytes(CHARSET);
- byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET);
+ 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();
@@ -277,8 +277,8 @@ public class EolStreamTypeUtilTest {
private void testCheckin(EolStreamType streamTypeText,
EolStreamType streamTypeWithBinaryCheck, String input,
String expectedConversion) throws Exception {
- byte[] inputBytes = input.getBytes(CHARSET);
- byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET);
+ 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/NotesCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java
index e234aa339c..6e06e9545a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import java.util.List;
@@ -88,7 +88,7 @@ public class NotesCommandTest extends RepositoryTestCase {
git.notesAdd().setObjectId(commit2).setMessage("data").call();
Note note = git.notesShow().setObjectId(commit2).call();
String content = new String(db.open(note.getData()).getCachedBytes(),
- CHARSET);
+ UTF_8);
assertEquals(content, "data");
git.notesRemove().setObjectId(commit2).call();
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 0b0e3bf3ea..9461c42500 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,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -592,7 +592,7 @@ public class PullCommandTest extends RepositoryTestCase {
private static void writeToFile(File actFile, String string)
throws IOException {
try (FileOutputStream fos = new FileOutputStream(actFile)) {
- fos.write(string.getBytes(CHARSET));
+ fos.write(string.getBytes(UTF_8));
}
}
@@ -606,7 +606,7 @@ public class PullCommandTest extends RepositoryTestCase {
bos.write(buffer, 0, read);
read = fis.read(buffer);
}
- String content = new String(bos.toByteArray(), CHARSET);
+ String content = new String(bos.toByteArray(), UTF_8);
assertEquals(string, content);
}
}
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 b349c66cab..913b4ac434 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,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -396,7 +396,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
private static void writeToFile(File actFile, String string)
throws IOException {
try (FileOutputStream fos = new FileOutputStream(actFile)) {
- fos.write(string.getBytes(CHARSET));
+ fos.write(string.getBytes(UTF_8));
}
}
@@ -410,7 +410,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
bos.write(buffer, 0, read);
read = fis.read(buffer);
}
- String content = new String(bos.toByteArray(), CHARSET);
+ String content = new String(bos.toByteArray(), UTF_8);
assertEquals(string, content);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
index 1af37e25f5..ca86d81301 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
@@ -245,7 +245,7 @@ public class PushCommandTest extends RepositoryTestCase {
git.add().addFilepattern("f" + i).call();
commit = git.commit().setMessage("adding f" + i).call();
git.push().setRemote("test").call();
- git2.getRepository().getAllRefs();
+ git2.getRepository().getRefDatabase().getRefs();
assertEquals("failed to update on attempt " + i, commit.getId(),
git2.getRepository().resolve("refs/heads/test"));
}
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 96e7091ae1..4401bcedb3 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,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -57,9 +57,12 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.RebaseCommand.InteractiveHandler;
@@ -75,6 +78,7 @@ import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.IllegalTodoFileModification;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.events.ListenerHandle;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.ConfigConstants;
@@ -1464,7 +1468,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]);
PersonIdent parsedIdent = git.rebase().parseAuthor(
- convertedAuthor.getBytes(CHARSET));
+ convertedAuthor.getBytes(UTF_8));
assertEquals(ident.getName(), parsedIdent.getName());
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
// this is rounded to the last second
@@ -1481,7 +1485,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]);
parsedIdent = git.rebase().parseAuthor(
- convertedAuthor.getBytes(CHARSET));
+ convertedAuthor.getBytes(UTF_8));
assertEquals(ident.getName(), parsedIdent.getName());
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
assertEquals(123456789000L, parsedIdent.getWhen().getTime());
@@ -1981,6 +1985,62 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
@Test
+ public void testRebaseWithAutoStashAndSubdirs() throws Exception {
+ // create file0, add and commit
+ db.getConfig().setBoolean(ConfigConstants.CONFIG_REBASE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_AUTOSTASH, true);
+ writeTrashFile("sub/file0", "file0");
+ git.add().addFilepattern("sub/file0").call();
+ git.commit().setMessage("commit0").call();
+ // create file1, add and commit
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / modify file0
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("sub/file0", "unstaged modified file0");
+
+ Set<String> modifiedFiles = new HashSet<>();
+ ListenerHandle handle = db.getListenerList()
+ .addWorkingTreeModifiedListener(
+ event -> modifiedFiles.addAll(event.getModified()));
+ try {
+ // rebase
+ assertEquals(Status.OK, git.rebase()
+ .setUpstream("refs/heads/master").call().getStatus());
+ } finally {
+ handle.remove();
+ }
+ checkFile(new File(new File(db.getWorkTree(), "sub"), "file0"),
+ "unstaged modified file0");
+ checkFile(new File(db.getWorkTree(), FILE1), "modified file1");
+ checkFile(new File(db.getWorkTree(), "file2"), "file2");
+ assertEquals(
+ "[file1, mode:100644, content:modified file1]"
+ + "[file2, mode:100644, content:file2]"
+ + "[sub/file0, mode:100644, content:file0]",
+ indexState(CONTENT));
+ assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+ List<String> modified = new ArrayList<>(modifiedFiles);
+ Collections.sort(modified);
+ assertEquals("[file1, sub/file0]", modified.toString());
+ }
+
+ @Test
public void testRebaseWithAutoStashConflictOnApply() throws Exception {
// create file0, add and commit
db.getConfig().setBoolean(ConfigConstants.CONFIG_REBASE_SECTION, null,
@@ -2104,7 +2164,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
int count = 0;
File todoFile = getTodoFile();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
- new FileInputStream(todoFile), CHARSET))) {
+ new FileInputStream(todoFile), UTF_8))) {
String line = br.readLine();
while (line != null) {
int firstBlank = line.indexOf(' ');
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java
index b07c7033f5..8922837139 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ReflogCommandTest.java
@@ -89,7 +89,7 @@ public class ReflogCommandTest extends RepositoryTestCase {
Collection<ReflogEntry> reflog = git.reflog().call();
assertNotNull(reflog);
assertEquals(3, reflog.size());
- ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[reflog.size()]);
+ ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[0]);
assertEquals(reflogs[2].getComment(),
"commit (initial): Initial commit");
assertEquals(reflogs[2].getNewId(), commit1.getId());
@@ -114,7 +114,7 @@ public class ReflogCommandTest extends RepositoryTestCase {
.setRef(Constants.R_HEADS + "b1").call();
assertNotNull(reflog);
assertEquals(2, reflog.size());
- ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[reflog.size()]);
+ ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[0]);
assertEquals(reflogs[0].getComment(), "commit: Removed file");
assertEquals(reflogs[0].getNewId(), commit2.getId());
assertEquals(reflogs[0].getOldId(), commit1.getId());
@@ -136,7 +136,7 @@ public class ReflogCommandTest extends RepositoryTestCase {
Collection<ReflogEntry> reflog = git.reflog().call();
assertNotNull(reflog);
assertEquals(4, reflog.size());
- ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[reflog.size()]);
+ ReflogEntry[] reflogs = reflog.toArray(new ReflogEntry[0]);
assertEquals(reflogs[3].getComment(),
"commit (initial): Initial commit");
assertEquals(reflogs[3].getNewId(), commit1.getId());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
index 8f56a9270e..2b97b307bf 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011-2013, Chris Aniszczyk <caniszczyk@gmail.com>
+ * Copyright (C) 2011-2018, Chris Aniszczyk <caniszczyk@gmail.com>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -52,7 +52,6 @@ import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
-import java.io.PrintWriter;
import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.api.errors.GitAPIException;
@@ -94,45 +93,25 @@ public class ResetCommandTest extends RepositoryTestCase {
git = new Git(db);
initialCommit = git.commit().setMessage("initial commit").call();
+ // create file
+ indexFile = writeTrashFile("a.txt", "content");
+
// create nested file
- File dir = new File(db.getWorkTree(), "dir");
- FileUtils.mkdir(dir);
- File nestedFile = new File(dir, "b.txt");
- FileUtils.createNewFile(nestedFile);
-
- try (PrintWriter nestedFileWriter = new PrintWriter(nestedFile)) {
- nestedFileWriter.print("content");
- nestedFileWriter.flush();
-
- // create file
- indexFile = new File(db.getWorkTree(), "a.txt");
- FileUtils.createNewFile(indexFile);
- try (PrintWriter writer = new PrintWriter(indexFile)) {
- writer.print("content");
- writer.flush();
-
- // add file and commit it
- git.add().addFilepattern("dir").addFilepattern("a.txt").call();
- secondCommit = git.commit()
- .setMessage("adding a.txt and dir/b.txt").call();
-
- prestage = DirCache.read(db.getIndexFile(), db.getFS())
- .getEntry(indexFile.getName());
-
- // modify file and add to index
- writer.print("new content");
- }
- nestedFileWriter.print("new content");
- }
- git.add().addFilepattern("a.txt").addFilepattern("dir").call();
+ writeTrashFile("dir/b.txt", "content");
+
+ // add files and commit them
+ git.add().addFilepattern("a.txt").addFilepattern("dir/b.txt").call();
+ secondCommit = git.commit().setMessage("adding a.txt and dir/b.txt").call();
+
+ prestage = DirCache.read(db.getIndexFile(), db.getFS()).getEntry(indexFile.getName());
+
+ // modify files and add to index
+ writeTrashFile("a.txt", "new content");
+ writeTrashFile("dir/b.txt", "new content");
+ git.add().addFilepattern("a.txt").addFilepattern("dir/b.txt").call();
// create a file not added to the index
- untrackedFile = new File(db.getWorkTree(),
- "notAddedToIndex.txt");
- FileUtils.createNewFile(untrackedFile);
- try (PrintWriter writer2 = new PrintWriter(untrackedFile)) {
- writer2.print("content");
- }
+ untrackedFile = writeTrashFile("notAddedToIndex.txt", "content");
}
@Test
@@ -179,31 +158,29 @@ public class ResetCommandTest extends RepositoryTestCase {
}
@Test
- public void testHardResetWithConflicts_DoOverWriteUntrackedFile()
- throws JGitInternalException,
- AmbiguousObjectException, IOException, GitAPIException {
+ public void testHardResetWithConflicts_OverwriteUntrackedFile() throws Exception {
setupRepository();
+
git.rm().setCached(true).addFilepattern("a.txt").call();
assertTrue(new File(db.getWorkTree(), "a.txt").exists());
- git.reset().setMode(ResetType.HARD).setRef(Constants.HEAD)
- .call();
+
+ git.reset().setMode(ResetType.HARD).setRef(Constants.HEAD).call();
assertTrue(new File(db.getWorkTree(), "a.txt").exists());
assertEquals("content", read(new File(db.getWorkTree(), "a.txt")));
}
@Test
- public void testHardResetWithConflicts_DoDeleteFileFolderConflicts()
- throws JGitInternalException,
- AmbiguousObjectException, IOException, GitAPIException {
+ public void testHardResetWithConflicts_DeleteFileFolderConflict() throws Exception {
setupRepository();
- writeTrashFile("d/c.txt", "x");
- git.add().addFilepattern("d/c.txt").call();
- FileUtils.delete(new File(db.getWorkTree(), "d"), FileUtils.RECURSIVE);
- writeTrashFile("d", "y");
- git.reset().setMode(ResetType.HARD).setRef(Constants.HEAD)
- .call();
- assertFalse(new File(db.getWorkTree(), "d").exists());
+ writeTrashFile("dir-or-file/c.txt", "content");
+ git.add().addFilepattern("dir-or-file/c.txt").call();
+
+ FileUtils.delete(new File(db.getWorkTree(), "dir-or-file"), FileUtils.RECURSIVE);
+ writeTrashFile("dir-or-file", "content");
+
+ git.reset().setMode(ResetType.HARD).setRef(Constants.HEAD).call();
+ assertFalse(new File(db.getWorkTree(), "dir-or-file").exists());
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java
index ad3ab7fbdf..fa6c9609f5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java
@@ -234,7 +234,7 @@ public class StashApplyCommandTest extends RepositoryTestCase {
ObjectId unstashed = git.stashApply().call();
assertEquals(stashed, unstashed);
assertEquals("content2", read(subfolderFile));
- recorder.assertEvent(new String[] { "d1/d2/f.txt", "d1/d2", "d1" },
+ recorder.assertEvent(new String[] { "d1/d2/f.txt" },
ChangeRecorder.EMPTY);
Status status = git.status().call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java
index 344d1af6a0..b6615075c0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.attributes;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -57,7 +58,6 @@ import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.junit.RepositoryTestCase;
-import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -127,14 +127,14 @@ public class CGitAttributesTest extends RepositoryTestCase {
builder.directory(db.getWorkTree());
builder.environment().put("HOME", fs.userHome().getAbsolutePath());
ExecutionResult result = fs.execute(builder, new ByteArrayInputStream(
- input.toString().getBytes(Constants.CHARSET)));
+ input.toString().getBytes(UTF_8)));
String errorOut = toString(result.getStderr());
assertEquals("External git failed", "exit 0\n",
"exit " + result.getRc() + '\n' + errorOut);
LinkedHashMap<String, Attributes> map = new LinkedHashMap<>();
try (BufferedReader r = new BufferedReader(new InputStreamReader(
new BufferedInputStream(result.getStdout().openInputStream()),
- Constants.CHARSET))) {
+ UTF_8))) {
r.lines().forEach(line -> {
// Parse the line and add to result map
int start = 0;
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 32f34213ec..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,7 +43,7 @@
package org.eclipse.jgit.diff;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -240,6 +240,6 @@ public abstract class AbstractDiffTestCase {
r.append(text.charAt(i));
r.append('\n');
}
- return new RawText(r.toString().getBytes(CHARSET));
+ return new RawText(r.toString().getBytes(UTF_8));
}
}
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 58a8b2d468..5885d9b7e6 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,7 +44,7 @@
package org.eclipse.jgit.diff;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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.assertFalse;
@@ -147,8 +147,8 @@ 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(CHARSET));
- RawText b = new RawText("p\na b \nR\n c d \n".getBytes(CHARSET));
+ 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);
@@ -160,14 +160,14 @@ public class RawTextTest {
RawText b;
Edit e;
- a = new RawText("R\n y\n".getBytes(CHARSET));
- b = new RawText("S\n\n y\n".getBytes(CHARSET));
+ 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(CHARSET));
- b = new RawText("R\n y\n".getBytes(CHARSET));
+ 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);
@@ -178,8 +178,8 @@ public class RawTextTest {
RawText a;
RawText b;
Edit e;
- a = new RawText("start".getBytes(CHARSET));
- b = new RawText("start of line".getBytes(CHARSET));
+ 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);
@@ -190,8 +190,8 @@ public class RawTextTest {
RawText a;
RawText b;
Edit e;
- a = new RawText("start".getBytes(CHARSET));
- b = new RawText("start of\nlastline".getBytes(CHARSET));
+ 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);
@@ -250,6 +250,6 @@ public class RawTextTest {
r.append(text.charAt(i));
r.append('\n');
}
- return new RawText(r.toString().getBytes(CHARSET));
+ 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 51a6f8121c..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,7 +43,7 @@
package org.eclipse.jgit.diff;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -82,7 +82,7 @@ public class SimilarityIndexTest {
+ "A\n" //
+ "B\n" //
+ "B\n" //
- + "B\n").getBytes(CHARSET);
+ + "B\n").getBytes(UTF_8);
SimilarityIndex si = new SimilarityIndex();
si.hash(new ByteArrayInputStream(in), in.length, false);
assertEquals(2, si.size());
@@ -130,12 +130,12 @@ public class SimilarityIndexTest {
+ "D\r\n" //
+ "B\r\n";
SimilarityIndex src = new SimilarityIndex();
- byte[] bytes1 = text.getBytes(CHARSET);
+ 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(CHARSET);
+ 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/dircache/DirCacheCGitCompatabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
index c362e7497c..847d0abad4 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.dircache;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -236,7 +236,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
private static Map<String, CGitIndexRecord> readLsFiles() throws Exception {
final LinkedHashMap<String, CGitIndexRecord> r = new LinkedHashMap<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
- new FileInputStream(pathOf("gitgit.lsfiles")), CHARSET))) {
+ new FileInputStream(pathOf("gitgit.lsfiles")), UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
final CGitIndexRecord cr = new CGitIndexRecord(line);
@@ -249,7 +249,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
private static Map<String, CGitLsTreeRecord> readLsTree() throws Exception {
final LinkedHashMap<String, CGitLsTreeRecord> r = new LinkedHashMap<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
- new FileInputStream(pathOf("gitgit.lstree")), CHARSET))) {
+ new FileInputStream(pathOf("gitgit.lstree")), UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
final CGitLsTreeRecord cr = new CGitLsTreeRecord(line);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
index 69a48cc4b5..88a077630e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
@@ -42,7 +42,8 @@
*/
package org.eclipse.jgit.gitrepo;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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,6 +52,8 @@ import java.io.IOException;
import java.net.URI;
import java.util.HashSet;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.junit.Test;
import org.xml.sax.SAXException;
@@ -82,7 +85,7 @@ public class ManifestParserTest {
ManifestParser parser = new ManifestParser(
null, null, "master", baseUrl, null, null);
- parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(CHARSET)));
+ parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)));
// Unfiltered projects should have them all.
results.clear();
results.add("foo");
@@ -136,7 +139,7 @@ public class ManifestParserTest {
baseUrl, null, null);
try {
parser.read(new ByteArrayInputStream(
- xmlContent.toString().getBytes(CHARSET)));
+ xmlContent.toString().getBytes(UTF_8)));
fail("ManifestParser did not throw exception for missing fetch");
} catch (IOException e) {
assertTrue(e.getCause() instanceof SAXException);
@@ -145,6 +148,29 @@ public class ManifestParserTest {
}
}
+ @Test
+ public void testRemoveProject() throws Exception {
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" fetch=\".\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"foo\" name=\"foo\" />")
+ .append("<project path=\"bar\" name=\"bar\" />")
+ .append("<remove-project name=\"foo\" />")
+ .append("<project path=\"foo\" name=\"baz\" />")
+ .append("</manifest>");
+
+ ManifestParser parser = new ManifestParser(null, null, "master",
+ "https://git.google.com/", null, null);
+ parser.read(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(UTF_8)));
+
+ assertEquals(Stream.of("bar", "baz").collect(Collectors.toSet()),
+ parser.getProjects().stream().map(RepoProject::getName)
+ .collect(Collectors.toSet()));
+ }
+
void testNormalize(String in, String want) {
URI got = ManifestParser.normalizeEmptyPath(URI.create(in));
if (!got.toString().equals(want)) {
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 df31ab0869..92f0cf6196 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,7 +42,7 @@
*/
package org.eclipse.jgit.gitrepo;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -217,7 +217,7 @@ public class RepoCommandTest extends RepositoryTestCase {
RevCommit commit = cmd
.setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(CHARSET)))
+ xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos).setURI("platform/")
.setTargetURI("platform/superproject")
.setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
@@ -226,7 +226,7 @@ public class RepoCommandTest extends RepositoryTestCase {
String firstIdStr = commit.getId().name() + ":" + ".gitmodules";
commit = new RepoCommand(dest)
.setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(CHARSET)))
+ xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos).setURI("platform/")
.setTargetURI("platform/superproject")
.setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
@@ -254,7 +254,7 @@ public class RepoCommandTest extends RepositoryTestCase {
RevCommit commit = cmd
.setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(CHARSET)))
+ xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos).setURI("platform/")
.setTargetURI("platform/superproject")
.setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
@@ -268,7 +268,8 @@ public class RepoCommandTest extends RepositoryTestCase {
.getCachedBytes(Integer.MAX_VALUE);
Config base = new Config();
BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "base", "url");
+ String subUrl = cfg.getString("submodule", "platform/base",
+ "url");
assertEquals(subUrl, "../base");
}
}
@@ -287,7 +288,7 @@ public class RepoCommandTest extends RepositoryTestCase {
try (Repository dest = cloneRepository(db, true)) {
RevCommit commit = new RepoCommand(dest)
.setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(CHARSET)))
+ xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(new IndexedRepos()).setURI("platform/")
.setTargetURI("platform/superproject")
.setRecordRemoteBranch(true).setIgnoreRemoteFailures(true)
@@ -301,7 +302,8 @@ public class RepoCommandTest extends RepositoryTestCase {
.getCachedBytes(Integer.MAX_VALUE);
Config base = new Config();
BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "base", "url");
+ String subUrl = cfg.getString("submodule", "platform/base",
+ "url");
assertEquals(subUrl, "https://host.com/platform/base");
}
}
@@ -325,7 +327,7 @@ public class RepoCommandTest extends RepositoryTestCase {
RevCommit commit = cmd
.setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(CHARSET)))
+ xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos).setURI("").setTargetURI("gerrit")
.setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
.call();
@@ -374,7 +376,7 @@ public class RepoCommandTest extends RepositoryTestCase {
RevCommit commit = cmd
.setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(CHARSET)))
+ xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos).setURI(baseUrl)
.setTargetURI("gerrit").setRecordRemoteBranch(true)
.setRecordSubmoduleLabels(true).call();
@@ -387,8 +389,8 @@ public class RepoCommandTest extends RepositoryTestCase {
.getCachedBytes(Integer.MAX_VALUE);
Config base = new Config();
BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "src",
- "url");
+ String subUrl = cfg.getString("submodule",
+ "chromium/src", "url");
assertEquals(
"https://chromium.googlesource.com/chromium/src",
subUrl);
@@ -429,7 +431,7 @@ public class RepoCommandTest extends RepositoryTestCase {
RevCommit commit = cmd
.setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(CHARSET)))
+ xmlContent.toString().getBytes(UTF_8)))
.setRemoteReader(repos).setURI(baseUrl)
.setTargetURI(abs + "/superproject")
.setRecordRemoteBranch(true)
@@ -443,8 +445,8 @@ public class RepoCommandTest extends RepositoryTestCase {
.getCachedBytes(Integer.MAX_VALUE);
Config base = new Config();
BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "src",
- "url");
+ String subUrl = cfg.getString("submodule",
+ "chromium/src", "url");
assertEquals("../chromium/src", subUrl);
}
fetchSlash = !fetchSlash;
@@ -613,7 +615,7 @@ public class RepoCommandTest extends RepositoryTestCase {
String content = reader.readLine();
assertEquals(
"The first line of .gitmodules file should be as expected",
- "[submodule \"foo\"]", content);
+ "[submodule \"" + defaultUri + "\"]", content);
}
// The gitlink should be the same as remote head sha1
String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
@@ -801,9 +803,9 @@ public class RepoCommandTest extends RepositoryTestCase {
.append("<manifest>")
.append("<remote name=\"remote1\" fetch=\".\" />")
.append("<default revision=\"master\" remote=\"remote1\" />")
- .append("<project path=\"bar\" name=\"").append(defaultUri)
- .append("\" revision=\"").append(BRANCH).append("\" >")
- .append("<copyfile src=\"hello.txt\" dest=\"Hello.txt\" />")
+ .append("<project path=\"bar\" name=\"").append(notDefaultUri)
+ .append("\" >")
+ .append("<copyfile src=\"world.txt\" dest=\"World.txt\" />")
.append("</project>").append("</manifest>");
JGitTestUtil.writeTrashFile(tempDb, "new.xml", xmlContent.toString());
command = new RepoCommand(remoteDb);
@@ -819,8 +821,8 @@ public class RepoCommandTest extends RepositoryTestCase {
File hello = new File(localDb.getWorkTree(), "Hello");
assertFalse("The Hello file shouldn't exist", hello.exists());
// The Hello.txt file should exist
- File hellotxt = new File(localDb.getWorkTree(), "Hello.txt");
- assertTrue("The Hello.txt file should exist", hellotxt.exists());
+ File hellotxt = new File(localDb.getWorkTree(), "World.txt");
+ assertTrue("The World.txt file should exist", hellotxt.exists());
dotmodules = new File(localDb.getWorkTree(),
Constants.DOT_GIT_MODULES);
}
@@ -835,9 +837,9 @@ public class RepoCommandTest extends RepositoryTestCase {
String line = reader.readLine();
if (line == null)
break;
- if (line.contains("submodule \"foo\""))
+ if (line.contains("submodule \"" + defaultUri + "\""))
foo = true;
- if (line.contains("submodule \"bar\""))
+ if (line.contains("submodule \"" + notDefaultUri + "\""))
bar = true;
}
assertTrue("The bar submodule should exist", bar);
@@ -876,9 +878,7 @@ public class RepoCommandTest extends RepositoryTestCase {
Constants.DOT_GIT_MODULES);
}
- // The .gitmodules file should have 'submodule "foo"' and shouldn't
- // have
- // 'submodule "foo/bar"' lines.
+ // Check .gitmodules file
try (BufferedReader reader = new BufferedReader(
new FileReader(dotmodules))) {
boolean foo = false;
@@ -888,16 +888,17 @@ public class RepoCommandTest extends RepositoryTestCase {
String line = reader.readLine();
if (line == null)
break;
- if (line.contains("submodule \"foo\""))
+ if (line.contains("submodule \"" + defaultUri + "\""))
foo = true;
- if (line.contains("submodule \"foo/bar\""))
+ if (line.contains("submodule \"" + groupBUri + "\""))
foobar = true;
- if (line.contains("submodule \"a\""))
+ if (line.contains("submodule \"" + groupAUri + "\""))
a = true;
}
- assertTrue("The foo submodule should exist", foo);
- assertFalse("The foo/bar submodule shouldn't exist", foobar);
- assertTrue("The a submodule should exist", a);
+ assertTrue("The " + defaultUri + " submodule should exist", foo);
+ assertFalse("The " + groupBUri + " submodule shouldn't exist",
+ foobar);
+ assertTrue("The " + groupAUri + " submodule should exist", a);
}
}
@@ -1033,11 +1034,11 @@ public class RepoCommandTest extends RepositoryTestCase {
assertEquals(
"Recording remote branches should work for short branch descriptions",
"master",
- c.getString("submodule", "with-branch", "branch"));
+ c.getString("submodule", notDefaultUri, "branch"));
assertEquals(
"Recording remote branches should work for full ref specs",
"refs/heads/master",
- c.getString("submodule", "with-long-branch", "branch"));
+ c.getString("submodule", defaultUri, "branch"));
}
}
@@ -1095,7 +1096,7 @@ public class RepoCommandTest extends RepositoryTestCase {
.append("<project path=\"shallow-please\" ").append("name=\"")
.append(defaultUri).append("\" ").append("clone-depth=\"1\" />")
.append("<project path=\"non-shallow\" ").append("name=\"")
- .append(defaultUri).append("\" />").append("</manifest>");
+ .append(notDefaultUri).append("\" />").append("</manifest>");
JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
xmlContent.toString());
@@ -1115,9 +1116,9 @@ public class RepoCommandTest extends RepositoryTestCase {
FileBasedConfig c = new FileBasedConfig(gitmodules, FS.DETECTED);
c.load();
assertEquals("Recording shallow configuration should work", "true",
- c.getString("submodule", "shallow-please", "shallow"));
+ c.getString("submodule", defaultUri, "shallow"));
assertNull("Recording non shallow configuration should work",
- c.getString("submodule", "non-shallow", "shallow"));
+ c.getString("submodule", notDefaultUri, "shallow"));
}
}
@@ -1176,6 +1177,43 @@ public class RepoCommandTest extends RepositoryTestCase {
}
}
+ @Test
+ public void testTwoPathUseTheSameName() throws Exception {
+ Repository remoteDb = createBareRepository();
+ Repository tempDb = createWorkRepository();
+
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" fetch=\".\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"path1\" ").append("name=\"")
+ .append(defaultUri).append("\" />")
+ .append("<project path=\"path2\" ").append("name=\"")
+ .append(defaultUri).append("\" />").append("</manifest>");
+ JGitTestUtil.writeTrashFile(tempDb, "manifest.xml",
+ xmlContent.toString());
+
+ RepoCommand command = new RepoCommand(remoteDb);
+ command.setPath(
+ tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml")
+ .setURI(rootUri).setRecommendShallow(true).call();
+ File directory = createTempDirectory("testBareRepo");
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
+ .setURI(remoteDb.getDirectory().toURI().toString()).call()
+ .getRepository();) {
+ File gitmodules = new File(localDb.getWorkTree(), ".gitmodules");
+ assertTrue("The .gitmodules file should exist",
+ gitmodules.exists());
+ FileBasedConfig c = new FileBasedConfig(gitmodules, FS.DETECTED);
+ c.load();
+ assertEquals("A module should exist for path1", "path1",
+ c.getString("submodule", defaultUri + "/path1", "path"));
+ assertEquals("A module should exist for path2", "path2",
+ c.getString("submodule", defaultUri + "/path2", "path"));
+ }
+ }
+
private void resolveRelativeUris() {
// Find the longest common prefix ends with "/" as rootUri.
defaultUri = defaultDb.getDirectory().toURI().toString();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java
index 0c6ed0c19e..b4c20a7e4c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.ignore;
+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.assertFalse;
@@ -56,7 +57,6 @@ import java.util.LinkedHashSet;
import java.util.Set;
import org.eclipse.jgit.junit.RepositoryTestCase;
-import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -113,7 +113,7 @@ public class CGitIgnoreTest extends RepositoryTestCase {
"exit " + result.getRc() + '\n' + errorOut);
try (BufferedReader r = new BufferedReader(new InputStreamReader(
new BufferedInputStream(result.getStdout().openInputStream()),
- Constants.CHARSET))) {
+ UTF_8))) {
return r.lines().toArray(String[]::new);
}
}
@@ -131,7 +131,7 @@ public class CGitIgnoreTest extends RepositoryTestCase {
"exit " + result.getRc() + '\n' + errorOut);
try (BufferedReader r = new BufferedReader(new InputStreamReader(
new BufferedInputStream(result.getStdout().openInputStream()),
- Constants.CHARSET))) {
+ UTF_8))) {
return r.lines().toArray(String[]::new);
}
}
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 78d9a82c24..cbc0761463 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,7 +42,7 @@
*/
package org.eclipse.jgit.ignore;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -767,6 +767,6 @@ public class IgnoreNodeTest extends RepositoryTestCase {
for (String line : rules) {
data.append(line + "\n");
}
- return new ByteArrayInputStream(data.toString().getBytes(CHARSET));
+ 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 26c11c7eb7..7e513d2c39 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,7 +41,7 @@
*/
package org.eclipse.jgit.indexdiff;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -128,7 +128,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, CHARSET)) {
+ 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");
@@ -170,7 +170,7 @@ public class IndexDiffWithSymlinkTest extends LocalDiskRepositoryTestCase {
private String readStream(InputStream stream) throws IOException {
try (BufferedReader in = new BufferedReader(
- new InputStreamReader(stream))) {
+ new InputStreamReader(stream, UTF_8))) {
StringBuilder out = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
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 5b567d00f7..bfa30d5b4b 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
@@ -972,7 +972,7 @@ public class DfsGarbageCollectorTest {
private static boolean isReachable(Repository repo, AnyObjectId id)
throws IOException {
try (RevWalk rw = new RevWalk(repo)) {
- for (Ref ref : repo.getAllRefs().values()) {
+ for (Ref ref : repo.getRefDatabase().getRefs()) {
rw.markStart(rw.parseCommit(ref.getObjectId()));
}
for (RevCommit next; (next = rw.next()) != null;) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackDescriptionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackDescriptionTest.java
new file mode 100644
index 0000000000..55e1a9c4cc
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackDescriptionTest.java
@@ -0,0 +1,293 @@
+/*
+ * Copyright (C) 2018, Google LLC.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.internal.storage.dfs;
+
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.COMPACT;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC_REST;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC_TXN;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.INSERT;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.RECEIVE;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.UNREACHABLE_GARBAGE;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.INDEX;
+import static org.eclipse.jgit.internal.storage.pack.PackExt.PACK;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Comparator;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
+import org.junit.Before;
+import org.junit.Test;
+
+public final class DfsPackDescriptionTest {
+ private AtomicInteger counter;
+
+ @Before
+ public void setUp() {
+ counter = new AtomicInteger();
+ }
+
+ @Test
+ public void objectLookupComparatorEqual() throws Exception {
+ DfsPackDescription a = create(RECEIVE);
+ a.setFileSize(PACK, 1);
+ a.setFileSize(INDEX, 1);
+ a.setLastModified(1);
+ a.setObjectCount(1);
+ a.setMaxUpdateIndex(1);
+
+ DfsPackDescription b = create(INSERT);
+ b.setFileSize(PACK, 1);
+ b.setFileSize(INDEX, 2);
+ b.setLastModified(1);
+ b.setObjectCount(1);
+ b.setMaxUpdateIndex(2);
+
+ assertComparesEqual(DfsPackDescription.objectLookupComparator(), a, b);
+ }
+
+ @Test
+ public void objectLookupComparatorPackSource() throws Exception {
+ DfsPackDescription a = create(COMPACT);
+ a.setFileSize(PACK, 2);
+ a.setLastModified(1);
+ a.setObjectCount(2);
+
+ DfsPackDescription b = create(GC);
+ b.setFileSize(PACK, 1);
+ b.setLastModified(2);
+ b.setObjectCount(1);
+
+ assertComparesLessThan(DfsPackDescription.objectLookupComparator(), a, b);
+ }
+
+ @Test
+ public void objectLookupComparatorCustomPackSourceComparator()
+ throws Exception {
+ DfsPackDescription a = create(GC);
+
+ DfsPackDescription b = create(COMPACT);
+
+ assertComparesLessThan(DfsPackDescription.objectLookupComparator(), b, a);
+ assertComparesLessThan(
+ DfsPackDescription.objectLookupComparator(
+ new PackSource.ComparatorBuilder()
+ .add(GC)
+ .add(INSERT, RECEIVE, GC_REST, GC_TXN, UNREACHABLE_GARBAGE)
+ .add(COMPACT)
+ .build()),
+ a, b);
+ }
+
+ @Test
+ public void objectLookupComparatorGcFileSize() throws Exception {
+ // a is older and smaller.
+ DfsPackDescription a = create(GC_REST);
+ a.setFileSize(PACK, 100);
+ a.setLastModified(1);
+ a.setObjectCount(2);
+
+ // b is newer and larger.
+ DfsPackDescription b = create(GC_REST);
+ b.setFileSize(PACK, 200);
+ b.setLastModified(2);
+ b.setObjectCount(1);
+
+ // Since they have the same GC type, tiebreaker is size, and a comes first.
+ assertComparesLessThan(DfsPackDescription.objectLookupComparator(), a, b);
+ }
+
+ @Test
+ public void objectLookupComparatorNonGcLastModified()
+ throws Exception {
+ // a is older and smaller.
+ DfsPackDescription a = create(INSERT);
+ a.setFileSize(PACK, 100);
+ a.setLastModified(1);
+ a.setObjectCount(2);
+
+ // b is newer and larger.
+ DfsPackDescription b = create(INSERT);
+ b.setFileSize(PACK, 200);
+ b.setLastModified(2);
+ b.setObjectCount(1);
+
+ // Since they have the same type but not GC, tiebreaker is last modified,
+ // and b comes first.
+ assertComparesLessThan(DfsPackDescription.objectLookupComparator(), b, a);
+ }
+
+ @Test
+ public void objectLookupComparatorObjectCount() throws Exception {
+ DfsPackDescription a = create(INSERT);
+ a.setObjectCount(1);
+
+ DfsPackDescription b = create(INSERT);
+ b.setObjectCount(2);
+
+ assertComparesLessThan(DfsPackDescription.objectLookupComparator(), a, b);
+ }
+
+ @Test
+ public void reftableComparatorEqual() throws Exception {
+ DfsPackDescription a = create(INSERT);
+ a.setFileSize(PACK, 100);
+ a.setObjectCount(1);
+
+ DfsPackDescription b = create(INSERT);
+ b.setFileSize(PACK, 200);
+ a.setObjectCount(2);
+
+ assertComparesEqual(DfsPackDescription.reftableComparator(), a, b);
+ }
+
+ @Test
+ public void reftableComparatorPackSource() throws Exception {
+ DfsPackDescription a = create(INSERT);
+ a.setMaxUpdateIndex(1);
+ a.setLastModified(1);
+
+ DfsPackDescription b = create(GC);
+ b.setMaxUpdateIndex(2);
+ b.setLastModified(2);
+
+ assertComparesLessThan(DfsPackDescription.reftableComparator(), b, a);
+ }
+
+ @Test
+ public void reftableComparatorMaxUpdateIndex() throws Exception {
+ DfsPackDescription a = create(INSERT);
+ a.setMaxUpdateIndex(1);
+ a.setLastModified(2);
+
+ DfsPackDescription b = create(INSERT);
+ b.setMaxUpdateIndex(2);
+ b.setLastModified(1);
+
+ assertComparesLessThan(DfsPackDescription.reftableComparator(), a, b);
+ }
+
+ @Test
+ public void reftableComparatorLastModified() throws Exception {
+ DfsPackDescription a = create(INSERT);
+ a.setLastModified(1);
+
+ DfsPackDescription b = create(INSERT);
+ b.setLastModified(2);
+
+ assertComparesLessThan(DfsPackDescription.reftableComparator(), a, b);
+ }
+
+ @Test
+ public void reuseComparatorEqual() throws Exception {
+ DfsPackDescription a = create(RECEIVE);
+ a.setFileSize(PACK, 1);
+ a.setFileSize(INDEX, 1);
+ a.setLastModified(1);
+ a.setObjectCount(1);
+ a.setMaxUpdateIndex(1);
+
+ DfsPackDescription b = create(INSERT);
+ b.setFileSize(PACK, 2);
+ b.setFileSize(INDEX, 2);
+ b.setLastModified(2);
+ b.setObjectCount(2);
+ b.setMaxUpdateIndex(2);
+
+ assertComparesEqual(DfsPackDescription.reuseComparator(), a, b);
+ }
+
+ @Test
+ public void reuseComparatorGcPackSize() throws Exception {
+ DfsPackDescription a = create(GC_REST);
+ a.setFileSize(PACK, 1);
+ a.setFileSize(INDEX, 1);
+ a.setLastModified(2);
+ a.setObjectCount(1);
+ a.setMaxUpdateIndex(1);
+
+ DfsPackDescription b = create(GC_REST);
+ b.setFileSize(PACK, 2);
+ b.setFileSize(INDEX, 2);
+ b.setLastModified(1);
+ b.setObjectCount(2);
+ b.setMaxUpdateIndex(2);
+
+ assertComparesLessThan(DfsPackDescription.reuseComparator(), b, a);
+ }
+
+ private DfsPackDescription create(PackSource source) {
+ return new DfsPackDescription(
+ new DfsRepositoryDescription("repo"),
+ "pack_" + counter.incrementAndGet(),
+ source);
+ }
+
+ private static <T> void assertComparesEqual(
+ Comparator<T> comparator, T o1, T o2) {
+ assertEquals(
+ "first object must compare equal to itself",
+ 0, comparator.compare(o1, o1));
+ assertEquals(
+ "second object must compare equal to itself",
+ 0, comparator.compare(o2, o2));
+ assertEquals(
+ "first object must compare equal to second object",
+ 0, comparator.compare(o1, o2));
+ }
+
+ private static <T> void assertComparesLessThan(
+ Comparator<T> comparator, T o1, T o2) {
+ assertEquals(
+ "first object must compare equal to itself",
+ 0, comparator.compare(o1, o1));
+ assertEquals(
+ "second object must compare equal to itself",
+ 0, comparator.compare(o2, o2));
+ assertEquals(
+ "first object must compare less than second object",
+ -1, comparator.compare(o1, o2));
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/PackSourceTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/PackSourceTest.java
new file mode 100644
index 0000000000..7bf1f587f8
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/PackSourceTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2018, Google LLC.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.internal.storage.dfs;
+
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.COMPACT;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.DEFAULT_COMPARATOR;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC_REST;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.GC_TXN;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.INSERT;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.RECEIVE;
+import static org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource.UNREACHABLE_GARBAGE;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class PackSourceTest {
+ @Test
+ public void defaultComaprator() throws Exception {
+ assertEquals(0, DEFAULT_COMPARATOR.compare(INSERT, INSERT));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(RECEIVE, RECEIVE));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(COMPACT, COMPACT));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(GC, GC));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(GC_REST, GC_REST));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(GC_TXN, GC_TXN));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(UNREACHABLE_GARBAGE, UNREACHABLE_GARBAGE));
+
+ assertEquals(0, DEFAULT_COMPARATOR.compare(INSERT, RECEIVE));
+ assertEquals(0, DEFAULT_COMPARATOR.compare(RECEIVE, INSERT));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(INSERT, COMPACT));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(COMPACT, INSERT));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(RECEIVE, COMPACT));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(COMPACT, RECEIVE));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(COMPACT, GC));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(GC, COMPACT));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(GC, GC_REST));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(GC_REST, GC));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(GC_REST, GC_TXN));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(GC_TXN, GC_REST));
+
+ assertEquals(-1, DEFAULT_COMPARATOR.compare(GC_TXN, UNREACHABLE_GARBAGE));
+ assertEquals(1, DEFAULT_COMPARATOR.compare(UNREACHABLE_GARBAGE, GC_TXN));
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
index e1adeedc54..3a43564180 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
@@ -46,7 +46,7 @@
package org.eclipse.jgit.internal.storage.file;
import static org.eclipse.jgit.junit.Assert.assertEquals;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -263,7 +263,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
ObjectId blobId;
try (ObjectInserter ins = bareRepo.newObjectInserter()) {
- blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(CHARSET));
+ blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(UTF_8));
ins.flush();
}
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 e113db12ac..02073226d0 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
@@ -47,7 +47,7 @@
package org.eclipse.jgit.internal.storage.file;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -368,7 +368,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
+ " 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));
+ assertEquals(expectedStr, new String(IO.readFully(cfg), UTF_8));
}
@Test
@@ -517,7 +517,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
4294967295000L, 60));
commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com",
4294967295000L, 60));
- commit.setEncoding(CHARSET);
+ commit.setEncoding(UTF_8);
commit.setMessage("\u00dcbergeeks");
ObjectId cid = insertCommit(commit);
assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name());
@@ -559,7 +559,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
final ObjectId treeId;
try (ObjectInserter oi = db.newObjectInserter()) {
final ObjectId blobId = oi.insert(Constants.OBJ_BLOB,
- "and this is the data in me\n".getBytes(Constants.CHARSET
+ "and this is the data in me\n".getBytes(UTF_8
.name()));
TreeFormatter fmt = new TreeFormatter();
fmt.append("i-am-a-file", FileMode.REGULAR_FILE, blobId);
@@ -666,9 +666,9 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
ObjectId id2;
try (ObjectInserter ins = db.newObjectInserter()) {
id1 = ins.insert(
- Constants.OBJ_BLOB, "contents1".getBytes(Constants.CHARSET));
+ Constants.OBJ_BLOB, "contents1".getBytes(UTF_8));
id2 = ins.insert(
- Constants.OBJ_BLOB, "contents2".getBytes(Constants.CHARSET));
+ Constants.OBJ_BLOB, "contents2".getBytes(UTF_8));
ins.flush();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java
index 82ad28ed21..01426eeb8c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.internal.storage.file;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -77,7 +78,7 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
try (BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(JGitTestUtil
.getTestResourceFile("all_packed_objects.txt")),
- Constants.CHARSET))) {
+ UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
final String[] parts = line.split(" {1,}");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java
index d9b58e206f..ffb6f4ee77 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java
@@ -50,6 +50,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -243,7 +244,8 @@ public class GcCommitSelectionTest extends GcTestCase {
List<RevCommit> commits = Arrays.asList(m0, m1, m2, b3, m4, b5, m6, b7,
m8, m9);
- PackWriterBitmapPreparer preparer = newPeparer(m9, commits);
+ PackWriterBitmapPreparer preparer = newPreparer(
+ Collections.singleton(m9), commits, new PackConfig());
List<BitmapCommit> selection = new ArrayList<>(
preparer.selectCommits(commits.size(), PackWriter.NONE));
@@ -267,15 +269,107 @@ public class GcCommitSelectionTest extends GcTestCase {
return commit.create();
}
- private PackWriterBitmapPreparer newPeparer(RevCommit want,
- List<RevCommit> commits)
- throws IOException {
+ @Test
+ public void testDistributionOnMultipleBranches() throws Exception {
+ BranchBuilder[] branches = { tr.branch("refs/heads/main"),
+ tr.branch("refs/heads/a"), tr.branch("refs/heads/b"),
+ tr.branch("refs/heads/c") };
+ RevCommit[] tips = new RevCommit[branches.length];
+ List<RevCommit> commits = createHistory(branches, tips);
+ PackConfig config = new PackConfig();
+ config.setBitmapContiguousCommitCount(1);
+ config.setBitmapRecentCommitSpan(5);
+ config.setBitmapDistantCommitSpan(20);
+ config.setBitmapRecentCommitCount(100);
+ Set<RevCommit> wants = new HashSet<>(Arrays.asList(tips));
+ PackWriterBitmapPreparer preparer = newPreparer(wants, commits, config);
+ List<BitmapCommit> selection = new ArrayList<>(
+ preparer.selectCommits(commits.size(), PackWriter.NONE));
+ Set<ObjectId> selected = new HashSet<>();
+ for (BitmapCommit c : selection) {
+ selected.add(c.toObjectId());
+ }
+
+ // Verify that each branch has uniform bitmap selection coverage
+ for (RevCommit c : wants) {
+ assertTrue(selected.contains(c.toObjectId()));
+ int count = 1;
+ int selectedCount = 1;
+ RevCommit parent = c;
+ while (parent.getParentCount() != 0) {
+ parent = parent.getParent(0);
+ count++;
+ if (selected.contains(parent.toObjectId())) {
+ selectedCount++;
+ }
+ }
+ // The selection algorithm prefers merges and will look in the
+ // current range plus the recent commit span before selecting a
+ // commit. Since this history has no merges, we expect the recent
+ // span should have 100/10=10 and distant commit spans should have
+ // 100/25=4 per 100 commit range.
+ int expectedCount = 10 + (count - 100 - 24) / 25;
+ assertTrue(expectedCount <= selectedCount);
+ }
+ }
+
+ private List<RevCommit> createHistory(BranchBuilder[] branches,
+ RevCommit[] tips) throws Exception {
+ /*-
+ * Create a history like this, where branches a, b and c branch off of the main branch
+ * at commits 100, 200 and 300, and where commit times move forward alternating between
+ * branches.
+ *
+ * o...o...o...o...o commits root,m0,m1,...,m399
+ * \ \ \
+ * \ \ o... commits branch_c,c300,c301,...,c399
+ * \ \
+ * \ o...o... commits branch_b,b200,b201,...,b399
+ * \
+ * o...o...o... commits branch_a,b100,b101,...,a399
+ */
+ List<RevCommit> commits = new ArrayList<>();
+ String[] prefixes = { "m", "a", "b", "c" };
+ int branchCount = branches.length;
+ tips[0] = addCommit(commits, branches[0], "root");
+ int counter = 0;
+
+ for (int b = 0; b < branchCount; b++) {
+ for (int i = 0; i < 100; i++, counter++) {
+ for (int j = 0; j <= b; j++) {
+ tips[j] = addCommit(commits, branches[j],
+ prefixes[j] + counter);
+ }
+ }
+ // Create a new branch from current value of the master branch
+ if (b < branchCount - 1) {
+ tips[b + 1] = addCommit(branches[b + 1],
+ "branch_" + prefixes[b + 1], tips[0]);
+ }
+ }
+ return commits;
+ }
+
+ private RevCommit addCommit(List<RevCommit> commits, BranchBuilder bb,
+ String msg, RevCommit... parents) throws Exception {
+ CommitBuilder commit = bb.commit().message(msg).add(msg, msg).tick(1);
+ if (parents.length > 0) {
+ commit.noParents();
+ for (RevCommit parent : parents) {
+ commit.parent(parent);
+ }
+ }
+ RevCommit c = commit.create();
+ commits.add(c);
+ return c;
+ }
+
+ private PackWriterBitmapPreparer newPreparer(Set<RevCommit> wants,
+ List<RevCommit> commits, PackConfig config) throws IOException {
List<ObjectToPack> objects = new ArrayList<>(commits.size());
for (RevCommit commit : commits) {
objects.add(new ObjectToPack(commit, Constants.OBJ_COMMIT));
}
- Set<ObjectId> wants = Collections.singleton((ObjectId) want);
- PackConfig config = new PackConfig();
PackBitmapIndexBuilder builder = new PackBitmapIndexBuilder(objects);
return new PackWriterBitmapPreparer(
tr.getRepository().newObjectReader(), builder,
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
index ec60bd9137..1d11573b99 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/MergedReftableTest.java
@@ -80,7 +80,7 @@ public class MergedReftableTest {
try (RefCursor rc = mr.seekRef(HEAD)) {
assertFalse(rc.next());
}
- try (RefCursor rc = mr.seekRef(R_HEADS)) {
+ try (RefCursor rc = mr.seekRefsWithPrefix(R_HEADS)) {
assertFalse(rc.next());
}
}
@@ -94,7 +94,7 @@ public class MergedReftableTest {
try (RefCursor rc = mr.seekRef(HEAD)) {
assertFalse(rc.next());
}
- try (RefCursor rc = mr.seekRef(R_HEADS)) {
+ try (RefCursor rc = mr.seekRefsWithPrefix(R_HEADS)) {
assertFalse(rc.next());
}
}
@@ -108,7 +108,7 @@ public class MergedReftableTest {
try (RefCursor rc = mr.seekRef(HEAD)) {
assertFalse(rc.next());
}
- try (RefCursor rc = mr.seekRef(R_HEADS)) {
+ try (RefCursor rc = mr.seekRefsWithPrefix(R_HEADS)) {
assertFalse(rc.next());
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
index 3ea3061e38..0ee785c60c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/reftable/ReftableTest.java
@@ -101,7 +101,7 @@ public class ReftableTest {
try (RefCursor rc = t.seekRef(HEAD)) {
assertFalse(rc.next());
}
- try (RefCursor rc = t.seekRef(R_HEADS)) {
+ try (RefCursor rc = t.seekRefsWithPrefix(R_HEADS)) {
assertFalse(rc.next());
}
try (LogCursor rc = t.allLogs()) {
@@ -317,10 +317,10 @@ public class ReftableTest {
public void namespaceNotFound() throws IOException {
Ref exp = ref(MASTER, 1);
ReftableReader t = read(write(exp));
- try (RefCursor rc = t.seekRef("refs/changes/")) {
+ try (RefCursor rc = t.seekRefsWithPrefix("refs/changes/")) {
assertFalse(rc.next());
}
- try (RefCursor rc = t.seekRef("refs/tags/")) {
+ try (RefCursor rc = t.seekRefsWithPrefix("refs/tags/")) {
assertFalse(rc.next());
}
}
@@ -332,12 +332,12 @@ public class ReftableTest {
Ref v1 = tag(V1_0, 3, 4);
ReftableReader t = read(write(master, next, v1));
- try (RefCursor rc = t.seekRef("refs/tags/")) {
+ try (RefCursor rc = t.seekRefsWithPrefix("refs/tags/")) {
assertTrue(rc.next());
assertEquals(V1_0, rc.getRef().getName());
assertFalse(rc.next());
}
- try (RefCursor rc = t.seekRef("refs/heads/")) {
+ try (RefCursor rc = t.seekRefsWithPrefix("refs/heads/")) {
assertTrue(rc.next());
assertEquals(MASTER, rc.getRef().getName());
@@ -484,7 +484,7 @@ public class ReftableTest {
try (RefCursor rc = t.allRefs()) {
assertFalse(rc.next());
}
- try (RefCursor rc = t.seekRef("refs/heads/")) {
+ try (RefCursor rc = t.seekRefsWithPrefix("refs/heads/")) {
assertFalse(rc.next());
}
try (LogCursor lc = t.allLogs()) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java
index 965899e7a0..b7027f3272 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.junit;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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.assertNotEquals;
@@ -418,6 +418,6 @@ public class TestRepositoryTest {
RevObject obj = tr.get(rw.parseTree(treeish), path);
assertSame(RevBlob.class, obj.getClass());
ObjectLoader loader = rw.getObjectReader().open(obj);
- return new String(loader.getCachedBytes(), CHARSET);
+ return new String(loader.getCachedBytes(), UTF_8);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/HugeCommitMessageTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/HugeCommitMessageTest.java
new file mode 100644
index 0000000000..4193c4ba3e
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/HugeCommitMessageTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.lib;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.storage.file.WindowCacheConfig;
+import org.eclipse.jgit.storage.pack.PackConfig;
+import org.junit.Test;
+
+public class HugeCommitMessageTest extends RepositoryTestCase {
+
+ private static final int HUGE_SIZE = Math.max(15 * WindowCacheConfig.MB,
+ PackConfig.DEFAULT_BIG_FILE_THRESHOLD + WindowCacheConfig.MB);
+ // Larger than the 5MB fallback limit in RevWalk.getCachedBytes(RevObject
+ // obj, ObjectLoader ldr), and also larger than the default
+ // streamFileThreshold.
+
+ @Test
+ public void testHugeCommitMessage() throws Exception {
+ try (Git git = new Git(db)) {
+ writeTrashFile("foo", "foo");
+ git.add().addFilepattern("foo").call();
+ WindowCacheConfig wc = new WindowCacheConfig();
+ wc.setStreamFileThreshold(HUGE_SIZE + WindowCacheConfig.MB);
+ wc.install();
+ RevCommit commit = git.commit()
+ .setMessage(insanelyHugeCommitMessage()).call();
+ Ref master = db.findRef("master");
+ List<Ref> actual = git.branchList().setContains(commit.getName())
+ .call();
+ assertTrue("Should be contained in branch master",
+ actual.contains(master));
+ }
+ }
+
+ private String insanelyHugeCommitMessage() {
+ final String oneLine = "012345678901234567890123456789012345678901234567890123456789\n";
+ StringBuilder b = new StringBuilder(HUGE_SIZE + oneLine.length());
+ // Give the message a real header; otherwise even writing the reflog
+ // message may run into troubles because RevCommit.getShortMessage()
+ // will return the whole message.
+ b.append("An insanely huge commit message\n\n");
+ while (b.length() < HUGE_SIZE) {
+ b.append(oneLine);
+ }
+ return b.toString();
+ }
+
+}
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 1ab36f0b62..531c918e9b 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,7 +45,7 @@
package org.eclipse.jgit.lib;
import static java.lang.Integer.valueOf;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -1560,7 +1560,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
entry(b, "100644 a");
- byte[] data = b.toString().getBytes(CHARSET);
+ byte[] data = b.toString().getBytes(UTF_8);
checker.setSafeForWindows(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1574,7 +1574,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
entry(b, "100644 a");
- byte[] data = b.toString().getBytes(CHARSET);
+ byte[] data = b.toString().getBytes(UTF_8);
checker.setSafeForMacOS(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1588,7 +1588,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 \u0065\u0301");
entry(b, "100644 \u00e9");
- byte[] data = b.toString().getBytes(CHARSET);
+ byte[] data = b.toString().getBytes(UTF_8);
checker.setSafeForMacOS(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1602,7 +1602,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
checker.setSafeForMacOS(true);
- checker.checkTree(b.toString().getBytes(CHARSET));
+ checker.checkTree(b.toString().getBytes(UTF_8));
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
index 8d9ccab1bd..3542dfad2d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
@@ -45,6 +45,7 @@ package org.eclipse.jgit.lib;
import static java.lang.Long.valueOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
import java.io.File;
import java.io.FileOutputStream;
@@ -157,10 +158,13 @@ public class RacyGitTests extends RepositoryTestCase {
// Remember the last modTime of index file. All modifications times of
// further modification are translated to this value so it looks that
// files have been modified in the same time slot as the index file
- modTimes.add(Long.valueOf(db.getIndexFile().lastModified()));
+ long indexMod = db.getIndexFile().lastModified();
+ modTimes.add(Long.valueOf(indexMod));
// modify one file
- addToWorkDir("a", "a2");
+ long aMod = addToWorkDir("a", "a2").lastModified();
+ assumeTrue(aMod == indexMod);
+
// now update the index the index. 'a' has to be racily clean -- because
// it's modification time is exactly the same as the previous index file
// mod time.
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
index 2481e64997..a42027b584 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
@@ -58,7 +58,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
-import java.util.Map;
+import java.util.Optional;
import java.util.TreeSet;
import org.eclipse.jgit.lib.Ref.Storage;
@@ -148,17 +148,22 @@ public class RefTest extends SampleDataRepositoryTestCase {
ObjectId r = db.resolve("refs/remotes/origin/HEAD");
assertEquals(masterId, r);
- Map<String, Ref> allRefs = db.getAllRefs();
- Ref refHEAD = allRefs.get("refs/remotes/origin/HEAD");
- assertNotNull(refHEAD);
- assertEquals(masterId, refHEAD.getObjectId());
- assertFalse(refHEAD.isPeeled());
- assertNull(refHEAD.getPeeledObjectId());
-
- Ref refmaster = allRefs.get("refs/remotes/origin/master");
- assertEquals(masterId, refmaster.getObjectId());
- assertFalse(refmaster.isPeeled());
- assertNull(refmaster.getPeeledObjectId());
+ List<Ref> allRefs = db.getRefDatabase().getRefs();
+ Optional<Ref> refHEAD = allRefs.stream()
+ .filter(ref -> ref.getName().equals("refs/remotes/origin/HEAD"))
+ .findAny();
+ assertTrue(refHEAD.isPresent());
+ assertEquals(masterId, refHEAD.get().getObjectId());
+ assertFalse(refHEAD.get().isPeeled());
+ assertNull(refHEAD.get().getPeeledObjectId());
+
+ Optional<Ref> refmaster = allRefs.stream().filter(
+ ref -> ref.getName().equals("refs/remotes/origin/master"))
+ .findAny();
+ assertTrue(refmaster.isPresent());
+ assertEquals(masterId, refmaster.get().getObjectId());
+ assertFalse(refmaster.get().isPeeled());
+ assertNull(refmaster.get().getPeeledObjectId());
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java
index aaa08a9e31..a67c750dba 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java
@@ -42,6 +42,8 @@
*/
package org.eclipse.jgit.merge;
+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.assertTrue;
@@ -881,7 +883,7 @@ public class CrissCrossMergeTest extends RepositoryTestCase {
StringBuilder result = new StringBuilder();
ObjectReader or = r.newObjectReader();
try (BufferedReader br = new BufferedReader(
- new InputStreamReader(or.open(blobId).openStream()))) {
+ new InputStreamReader(or.open(blobId).openStream(), UTF_8))) {
String line;
boolean first = true;
while ((line = br.readLine()) != null) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
index 58093a3729..8f12dd7b27 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.merge;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -60,6 +60,7 @@ import java.util.Map;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.MergeResult;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
+import org.eclipse.jgit.api.RebaseResult;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
@@ -428,6 +429,44 @@ public class MergerTest extends RepositoryTestCase {
indexState(CONTENT));
}
+ @Theory
+ public void rebaseWithCrlfAutoCrlfTrue(MergeStrategy strategy)
+ throws IOException, GitAPIException {
+ Git git = Git.wrap(db);
+ db.getConfig().setString("core", null, "autocrlf", "true");
+ db.getConfig().save();
+ writeTrashFile("crlf.txt", "line 1\r\nline 2\r\nline 3\r\n");
+ git.add().addFilepattern("crlf.txt").call();
+ RevCommit first = git.commit().setMessage("base").call();
+
+ git.checkout().setCreateBranch(true).setStartPoint(first)
+ .setName("brancha").call();
+
+ File testFile = writeTrashFile("crlf.txt",
+ "line 1\r\nmodified line\r\nline 3\r\n");
+ git.add().addFilepattern("crlf.txt").call();
+ git.commit().setMessage("on brancha").call();
+
+ git.checkout().setName("master").call();
+ File otherFile = writeTrashFile("otherfile.txt", "a line\r\n");
+ git.add().addFilepattern("otherfile.txt").call();
+ git.commit().setMessage("on master").call();
+
+ git.checkout().setName("brancha").call();
+ checkFile(testFile, "line 1\r\nmodified line\r\nline 3\r\n");
+ assertFalse(otherFile.exists());
+
+ RebaseResult rebaseResult = git.rebase().setStrategy(strategy)
+ .setUpstream(db.resolve("master")).call();
+ assertEquals(RebaseResult.Status.OK, rebaseResult.getStatus());
+ checkFile(testFile, "line 1\r\nmodified line\r\nline 3\r\n");
+ checkFile(otherFile, "a line\r\n");
+ assertEquals(
+ "[crlf.txt, mode:100644, content:line 1\nmodified line\nline 3\n]"
+ + "[otherfile.txt, mode:100644, content:a line\n]",
+ indexState(CONTENT));
+ }
+
/**
* Merging two equal subtrees when the index does not contain any file in
* that subtree should lead to a merged state.
@@ -754,7 +793,7 @@ public class MergerTest extends RepositoryTestCase {
}
binary[50] = '\0';
- writeTrashFile("file", new String(binary, CHARSET));
+ writeTrashFile("file", new String(binary, UTF_8));
git.add().addFilepattern("file").call();
RevCommit first = git.commit().setMessage("added file").call();
@@ -762,7 +801,7 @@ public class MergerTest extends RepositoryTestCase {
int idx = LINELEN * 1200 + 1;
byte save = binary[idx];
binary[idx] = '@';
- writeTrashFile("file", new String(binary, CHARSET));
+ writeTrashFile("file", new String(binary, UTF_8));
binary[idx] = save;
git.add().addFilepattern("file").call();
@@ -771,7 +810,7 @@ public class MergerTest extends RepositoryTestCase {
git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call();
binary[LINELEN * 1500 + 1] = '!';
- writeTrashFile("file", new String(binary, CHARSET));
+ writeTrashFile("file", new String(binary, UTF_8));
git.add().addFilepattern("file").call();
RevCommit sideCommit = git.commit().setAll(true)
.setMessage("modified file l 1500").call();
@@ -933,7 +972,7 @@ public class MergerTest extends RepositoryTestCase {
merger.getMergeResults().get("file");
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
fmt.formatMerge(out, merger.getMergeResults().get("file"),
- "BASE", "OURS", "THEIRS", CHARSET.name());
+ "BASE", "OURS", "THEIRS", UTF_8.name());
String expected = "<<<<<<< OURS\n"
+ "1master\n"
+ "=======\n"
@@ -941,7 +980,7 @@ public class MergerTest extends RepositoryTestCase {
+ ">>>>>>> THEIRS\n"
+ "2\n"
+ "3";
- assertEquals(expected, new String(out.toByteArray(), CHARSET));
+ assertEquals(expected, new String(out.toByteArray(), UTF_8));
}
}
}
@@ -1328,6 +1367,7 @@ public class MergerTest extends RepositoryTestCase {
if (obj == null) {
return null;
}
- return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), CHARSET);
+ return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(),
+ UTF_8);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
index 7b5868a393..e383f36bca 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.patch;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -83,7 +83,7 @@ public class GetTextTest {
@Test
public void testGetText_Convert() throws IOException {
final Charset csOld = ISO_8859_1;
- final Charset csNew = CHARSET;
+ final Charset csNew = UTF_8;
final Patch p = parseTestPatchFile();
assertTrue(p.getErrors().isEmpty());
assertEquals(1, p.getFiles().size());
@@ -103,7 +103,7 @@ public class GetTextTest {
@Test
public void testGetText_DiffCc() throws IOException {
final Charset csOld = ISO_8859_1;
- final Charset csNew = CHARSET;
+ final Charset csNew = UTF_8;
final Patch p = parseTestPatchFile();
assertTrue(p.getErrors().isEmpty());
assertEquals(1, p.getFiles().size());
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 cfefac3aa1..b814984935 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
@@ -44,7 +44,7 @@
package org.eclipse.jgit.revwalk;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -114,7 +114,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
assertNull(c.getTree());
assertNull(c.parents);
- c.parseCanonical(rw, body.toString().getBytes(CHARSET));
+ c.parseCanonical(rw, body.toString().getBytes(UTF_8));
assertNotNull(c.getTree());
assertEquals(treeId, c.getTree().getId());
assertSame(rw.lookupTree(treeId), c.getTree());
@@ -148,7 +148,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
return c;
}
@@ -161,7 +161,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
assertEquals("", c.getFullMessage());
assertEquals("", c.getShortMessage());
@@ -176,7 +176,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
+ 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());
@@ -185,18 +185,18 @@ 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(CHARSET));
- b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(CHARSET));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ 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());
- assertSame(Constants.CHARSET, c.getEncoding());
+ assertSame(UTF_8, c.getEncoding());
assertEquals("F\u00f6r fattare", c.getAuthorIdent().getName());
assertEquals("Sm\u00f6rg\u00e5sbord", c.getShortMessage());
assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage());
@@ -205,18 +205,18 @@ 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(CHARSET));
+ 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(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ 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());
- assertSame(Constants.CHARSET, c.getEncoding());
+ assertSame(UTF_8, c.getEncoding());
assertEquals("F\u00f6r fattare", c.getAuthorIdent().getName());
assertEquals("Sm\u00f6rg\u00e5sbord", c.getShortMessage());
assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage());
@@ -260,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(CHARSET));
+ 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(CHARSET));
- b.write("encoding EUC-JP\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("Hi\n".getBytes(CHARSET));
+ 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());
@@ -291,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(CHARSET));
- b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(CHARSET));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
- b.write("encoding ISO-8859-1\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("Hi\n".getBytes(CHARSET));
+ 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());
@@ -313,13 +313,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
public void testParse_incorrectUtf8Name() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(CHARSET));
- b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ .getBytes(UTF_8));
+ b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
b.write("committer co <c@example.com> 1218123390 -0500\n"
- .getBytes(CHARSET));
- b.write("encoding 'utf8'\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
+ .getBytes(UTF_8));
+ b.write("encoding 'utf8'\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
RevCommit c = new RevCommit(
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
@@ -338,12 +338,12 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_illegalEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
- b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET));
- b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
- b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("message\n".getBytes(CHARSET));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
+ b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
+ b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("message\n".getBytes(UTF_8));
RevCommit c = new RevCommit(
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
@@ -365,12 +365,12 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_unsupportedEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
- b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET));
- b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
- b.write("encoding it_IT.UTF8\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("message\n".getBytes(CHARSET));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
+ b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
+ b.write("encoding it_IT.UTF8\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("message\n".getBytes(UTF_8));
RevCommit c = new RevCommit(
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
@@ -486,4 +486,36 @@ public class RevCommitParseTest extends RepositoryTestCase {
private static ObjectId id(String str) {
return ObjectId.fromString(str);
}
+
+ @Test
+ public void testParse_gpgSig() throws Exception {
+ String commit = "tree e3a1035abd2b319bb01e57d69b0ba6cab289297e\n" +
+ "parent 54e895b87c0768d2317a2b17062e3ad9f76a8105\n" +
+ "committer A U Thor <author@xample.com 1528968566 +0200\n" +
+ "gpgsig -----BEGIN PGP SIGNATURE-----\n" +
+ " \n" +
+ " wsBcBAABCAAQBQJbGB4pCRBK7hj4Ov3rIwAAdHIIAENrvz23867ZgqrmyPemBEZP\n" +
+ " U24B1Tlq/DWvce2buaxmbNQngKZ0pv2s8VMc11916WfTIC9EKvioatmpjduWvhqj\n" +
+ " znQTFyiMor30pyYsfrqFuQZvqBW01o8GEWqLg8zjf9Rf0R3LlOEw86aT8CdHRlm6\n" +
+ " wlb22xb8qoX4RB+LYfz7MhK5F+yLOPXZdJnAVbuyoMGRnDpwdzjL5Hj671+XJxN5\n" +
+ " SasRdhxkkfw/ZnHxaKEc4juMz8Nziz27elRwhOQqlTYoXNJnsV//wy5Losd7aKi1\n" +
+ " xXXyUpndEOmT0CIcKHrN/kbYoVL28OJaxoBuva3WYQaRrzEe3X02NMxZe9gkSqA=\n" +
+ " =TClh\n" +
+ " -----END PGP SIGNATURE-----\n" +
+ "some other header\n\n" +
+ "commit message";
+
+ final RevCommit c;
+ c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
+ c.parseCanonical(new RevWalk(db), commit.getBytes(UTF_8));
+ String gpgSig = new String(c.getRawGpgSignature(), UTF_8);
+ assertTrue(gpgSig.startsWith("-----BEGIN"));
+ assertTrue(gpgSig.endsWith("END PGP SIGNATURE-----"));
+ }
+
+ @Test
+ public void testParse_NoGpgSig() throws Exception {
+ final RevCommit c = create("a message");
+ assertNull(c.getRawGpgSignature());
+ }
}
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 8e389ae252..4969305de0 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
@@ -144,13 +144,13 @@ public class RevObjectTest extends RevWalkTestCase {
final RevCommit a = commit();
final RevFlag flag1 = rw.newFlag("flag1");
final RevFlag flag2 = rw.newFlag("flag2");
- assertEquals(0, a.flags);
+ assertEquals(RevWalk.PARSED, a.flags);
a.add(flag1);
- assertEquals(flag1.mask, a.flags);
+ assertEquals(RevWalk.PARSED | flag1.mask, a.flags);
a.add(flag2);
- assertEquals(flag1.mask | flag2.mask, a.flags);
+ assertEquals(RevWalk.PARSED | flag1.mask | flag2.mask, a.flags);
}
@Test
@@ -162,10 +162,10 @@ public class RevObjectTest extends RevWalkTestCase {
s.add(flag1);
s.add(flag2);
- assertEquals(0, a.flags);
+ assertEquals(RevWalk.PARSED, a.flags);
a.add(s);
- assertEquals(flag1.mask | flag2.mask, a.flags);
+ assertEquals(RevWalk.PARSED | flag1.mask | flag2.mask, a.flags);
}
@Test
@@ -175,9 +175,9 @@ public class RevObjectTest extends RevWalkTestCase {
final RevFlag flag2 = rw.newFlag("flag2");
a.add(flag1);
a.add(flag2);
- assertEquals(flag1.mask | flag2.mask, a.flags);
+ assertEquals(RevWalk.PARSED | flag1.mask | flag2.mask, a.flags);
a.remove(flag2);
- assertEquals(flag1.mask, a.flags);
+ assertEquals(RevWalk.PARSED | flag1.mask, a.flags);
}
@Test
@@ -191,8 +191,8 @@ public class RevObjectTest extends RevWalkTestCase {
s.add(flag2);
a.add(flag3);
a.add(s);
- assertEquals(flag1.mask | flag2.mask | flag3.mask, a.flags);
+ assertEquals(RevWalk.PARSED | flag1.mask | flag2.mask | flag3.mask, a.flags);
a.remove(s);
- assertEquals(flag3.mask, a.flags);
+ assertEquals(RevWalk.PARSED | flag3.mask, a.flags);
}
}
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 e11cef7c92..1b45473066 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
@@ -44,7 +44,7 @@
package org.eclipse.jgit.revwalk;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -98,7 +98,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, b.toString().getBytes(CHARSET));
+ c.parseCanonical(rw, b.toString().getBytes(UTF_8));
assertNotNull(c.getObject());
assertEquals(id, c.getObject().getId());
assertSame(rw.lookupAny(id, typeCode), c.getObject());
@@ -141,7 +141,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, body.toString().getBytes(CHARSET));
+ c.parseCanonical(rw, body.toString().getBytes(UTF_8));
assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject());
@@ -189,7 +189,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, body.toString().getBytes(CHARSET));
+ c.parseCanonical(rw, body.toString().getBytes(UTF_8));
assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject());
@@ -213,7 +213,7 @@ public class RevTagParseTest extends RepositoryTestCase {
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
return c;
}
@@ -221,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(CHARSET));
- b.write("type tree\n".getBytes(CHARSET));
- b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
+ .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(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ .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());
@@ -246,15 +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(CHARSET));
- b.write("type tree\n".getBytes(CHARSET));
- b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
+ .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(CHARSET));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ 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(CHARSET));
- b.write("type tree\n".getBytes(CHARSET));
- b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
+ .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(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("Hi\n".getBytes(CHARSET));
+ 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(CHARSET));
- b.write("type tree\n".getBytes(CHARSET));
- b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
+ .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(CHARSET));
- b.write("encoding ISO-8859-1\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("Hi\n".getBytes(CHARSET));
+ .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());
@@ -365,13 +365,13 @@ public class RevTagParseTest extends RepositoryTestCase {
@Test
public void testParse_illegalEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
- b.write("type tree\n".getBytes(CHARSET));
- b.write("tag v1.0\n".getBytes(CHARSET));
- b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(CHARSET));
- b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("message\n".getBytes(CHARSET));
+ b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("type tree\n".getBytes(UTF_8));
+ b.write("tag v1.0\n".getBytes(UTF_8));
+ b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(UTF_8));
+ b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("message\n".getBytes(UTF_8));
RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
t.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -384,13 +384,13 @@ public class RevTagParseTest extends RepositoryTestCase {
@Test
public void testParse_unsupportedEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
- b.write("type tree\n".getBytes(CHARSET));
- b.write("tag v1.0\n".getBytes(CHARSET));
- b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(CHARSET));
- b.write("encoding it_IT.UTF8\n".getBytes(CHARSET));
- b.write("\n".getBytes(CHARSET));
- b.write("message\n".getBytes(CHARSET));
+ b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("type tree\n".getBytes(UTF_8));
+ b.write("tag v1.0\n".getBytes(UTF_8));
+ b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(UTF_8));
+ b.write("encoding it_IT.UTF8\n".getBytes(UTF_8));
+ b.write("\n".getBytes(UTF_8));
+ b.write("message\n".getBytes(UTF_8));
RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
t.parseCanonical(new RevWalk(db), b.toByteArray());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCullTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCullTest.java
index fb52828c5b..7984a37193 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCullTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkCullTest.java
@@ -85,7 +85,7 @@ public class RevWalkCullTest extends RevWalkTestCase {
@Test
public void testProperlyCullAllAncestors_LongHistory() throws Exception {
- final RevCommit a = commit();
+ RevCommit a = commit();
RevCommit b = commit(a);
for (int i = 0; i < 24; i++) {
b = commit(b);
@@ -94,6 +94,12 @@ public class RevWalkCullTest extends RevWalkTestCase {
}
final RevCommit c = commit(b);
+ // TestRepository eagerly parses newly created objects. The current rw
+ // is caching that parsed state. To verify that RevWalk itself is lazy,
+ // set up a new one.
+ rw.close();
+ rw = createRevWalk();
+ RevCommit a2 = rw.lookupCommit(a);
markStart(c);
markUninteresting(b);
assertCommit(c, rw.next());
@@ -102,6 +108,6 @@ public class RevWalkCullTest extends RevWalkTestCase {
// We should have aborted before we got back so far that "a"
// would be parsed. Thus, its parents shouldn't be allocated.
//
- assertNull(a.parents);
+ assertNull(a2.parents);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java
index 6df36e78f1..7554d7a479 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkShallowTest.java
@@ -58,138 +58,155 @@ public class RevWalkShallowTest extends RevWalkTestCase {
@Test
public void testDepth1() throws Exception {
- final RevCommit a = commit();
- final RevCommit b = commit(a);
- final RevCommit c = commit(b);
- final RevCommit d = commit(c);
+ RevCommit[] commits = setupLinearChain();
- createShallowFile(d);
+ createShallowFile(commits[3]);
+ updateCommits(commits);
- rw.reset();
- markStart(d);
- assertCommit(d, rw.next());
+ rw.markStart(commits[3]);
+ assertCommit(commits[3], rw.next());
assertNull(rw.next());
}
@Test
public void testDepth2() throws Exception {
- final RevCommit a = commit();
- final RevCommit b = commit(a);
- final RevCommit c = commit(b);
- final RevCommit d = commit(c);
+ RevCommit[] commits = setupLinearChain();
- createShallowFile(c);
+ createShallowFile(commits[2]);
+ updateCommits(commits);
- rw.reset();
- markStart(d);
- assertCommit(d, rw.next());
- assertCommit(c, rw.next());
+ rw.markStart(commits[3]);
+ assertCommit(commits[3], rw.next());
+ assertCommit(commits[2], rw.next());
assertNull(rw.next());
}
@Test
public void testDepth3() throws Exception {
- final RevCommit a = commit();
- final RevCommit b = commit(a);
- final RevCommit c = commit(b);
- final RevCommit d = commit(c);
+ RevCommit[] commits = setupLinearChain();
- createShallowFile(b);
+ createShallowFile(commits[1]);
+ updateCommits(commits);
- rw.reset();
- markStart(d);
- assertCommit(d, rw.next());
- assertCommit(c, rw.next());
- assertCommit(b, rw.next());
+ rw.markStart(commits[3]);
+ assertCommit(commits[3], rw.next());
+ assertCommit(commits[2], rw.next());
+ assertCommit(commits[1], rw.next());
assertNull(rw.next());
}
@Test
- public void testMergeCommitOneParentShallow() throws Exception {
- final RevCommit a = commit();
- final RevCommit b = commit(a);
- final RevCommit c = commit(b);
- final RevCommit d = commit(b);
- final RevCommit e = commit(d);
- final RevCommit merge = commit(c, e);
-
- createShallowFile(e);
-
- rw.reset();
- markStart(merge);
- assertCommit(merge, rw.next());
- assertCommit(e, rw.next());
- assertCommit(c, rw.next());
- assertCommit(b, rw.next());
- assertCommit(a, rw.next());
+ public void testObjectDirectorySnapshot() throws Exception {
+ RevCommit[] commits = setupLinearChain();
+
+ createShallowFile(commits[3]);
+ updateCommits(commits);
+
+ markStart(commits[3]);
+ assertCommit(commits[3], rw.next());
assertNull(rw.next());
- }
- @Test
- public void testMergeCommitEntirelyShallow() throws Exception {
- final RevCommit a = commit();
- final RevCommit b = commit(a);
- final RevCommit c = commit(b);
- final RevCommit d = commit(b);
- final RevCommit e = commit(d);
- final RevCommit merge = commit(c, e);
-
- createShallowFile(c, e);
-
- rw.reset();
- markStart(merge);
- assertCommit(merge, rw.next());
- assertCommit(e, rw.next());
- assertCommit(c, rw.next());
+ createShallowFile(commits[2]);
+ updateCommits(commits);
+
+ markStart(commits[3]);
+ assertCommit(commits[3], rw.next());
+ assertCommit(commits[2], rw.next());
assertNull(rw.next());
}
+ private RevCommit[] setupLinearChain() throws Exception {
+ RevCommit[] commits = new RevCommit[4];
+ RevCommit parent = null;
+ for (int i = 0; i < commits.length; i++) {
+ commits[i] = parent != null ? commit(parent) : commit();
+ parent = commits[i];
+ }
+ return commits;
+ }
+
@Test
- public void testObjectDirectorySnapshot() throws Exception {
- RevCommit a = commit();
- RevCommit b = commit(a);
- RevCommit c = commit(b);
- RevCommit d = commit(c);
+ public void testMergeCommitOneParentShallow() throws Exception {
+ RevCommit[] commits = setupMergeChain();
- createShallowFile(d);
+ createShallowFile(commits[4]);
+ updateCommits(commits);
- rw.reset();
- markStart(d);
- assertCommit(d, rw.next());
+ markStart(commits[5]);
+ assertCommit(commits[5], rw.next());
+ assertCommit(commits[4], rw.next());
+ assertCommit(commits[2], rw.next());
+ assertCommit(commits[1], rw.next());
+ assertCommit(commits[0], rw.next());
assertNull(rw.next());
+ }
- rw = createRevWalk();
- a = rw.lookupCommit(a);
- b = rw.lookupCommit(b);
- c = rw.lookupCommit(c);
- d = rw.lookupCommit(d);
-
- rw.reset();
- markStart(d);
- assertCommit(d, rw.next());
- assertNull(rw.next());
+ @Test
+ public void testMergeCommitEntirelyShallow() throws Exception {
+ RevCommit[] commits = setupMergeChain();
- createShallowFile(c);
+ createShallowFile(commits[2], commits[4]);
+ updateCommits(commits);
- rw = createRevWalk();
- a = rw.lookupCommit(a);
- b = rw.lookupCommit(b);
- c = rw.lookupCommit(c);
- d = rw.lookupCommit(d);
-
- rw.reset();
- markStart(d);
- assertCommit(d, rw.next());
- assertCommit(c, rw.next());
+ markStart(commits[5]);
+ assertCommit(commits[5], rw.next());
+ assertCommit(commits[4], rw.next());
+ assertCommit(commits[2], rw.next());
assertNull(rw.next());
}
+ private RevCommit[] setupMergeChain() throws Exception {
+ /*-
+ * Create a history like this, diverging at 1 and merging at 5:
+ *
+ * ---o--o commits 3,4
+ * / \
+ * o--o--o------o commits 0,1,2,5
+ */
+ RevCommit[] commits = new RevCommit[6];
+ commits[0] = commit();
+ commits[1] = commit(commits[0]);
+ commits[2] = commit(commits[1]);
+ commits[3] = commit(commits[1]);
+ commits[4] = commit(commits[3]);
+ commits[5] = commit(commits[2], commits[4]);
+ return commits;
+ }
+
+ private void updateCommits(RevCommit[] commits) {
+ // Relookup commits using the new RevWalk
+ for (int i = 0; i < commits.length; i++) {
+ commits[i] = rw.lookupCommit(commits[i].getId());
+ }
+ }
+
private void createShallowFile(ObjectId... shallowCommits)
throws IOException {
- final StringBuilder builder = new StringBuilder();
- for (ObjectId commit : shallowCommits)
+ // Reset the RevWalk since the new shallow file invalidates the existing
+ // RevWalk's shallow state.
+ rw.close();
+ rw = createRevWalk();
+ StringBuilder builder = new StringBuilder();
+ for (ObjectId commit : shallowCommits) {
builder.append(commit.getName() + "\n");
+ }
JGitTestUtil.write(new File(db.getDirectory(), "shallow"),
builder.toString());
}
+
+ @Test
+ public void testShallowCommitParse() throws Exception {
+ RevCommit a = commit();
+ RevCommit b = commit(a);
+
+ createShallowFile(b);
+
+ rw.close();
+ rw = createRevWalk();
+ b = rw.parseCommit(b);
+
+ markStart(b);
+ assertCommit(b, rw.next());
+ assertNull(rw.next());
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
index a26ae10af3..cb92a955bc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
@@ -115,7 +115,7 @@ public class RevWalkUtilsReachableTest extends RevWalkTestCase {
}
private void assertContains(RevCommit commit, Collection<Ref> refsThatShouldContainCommit) throws Exception {
- Collection<Ref> allRefs = db.getAllRefs().values();
+ Collection<Ref> allRefs = db.getRefDatabase().getRefs();
Collection<Ref> sortedRefs = RefComparator.sort(allRefs);
List<Ref> actual = RevWalkUtils.findBranchesReachableFrom(commit,
rw, sortedRefs);
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 0dea5ce97b..7f0d60295c 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,7 +42,7 @@
*/
package org.eclipse.jgit.storage.file;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -105,7 +105,7 @@ public class FileBasedConfigTest {
@Test
public void testUTF8withoutBOM() throws IOException, ConfigInvalidException {
- final File file = createFile(CONTENT1.getBytes(CHARSET));
+ 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));
@@ -121,7 +121,7 @@ public class FileBasedConfigTest {
bos1.write(0xEF);
bos1.write(0xBB);
bos1.write(0xBF);
- bos1.write(CONTENT1.getBytes(CHARSET));
+ bos1.write(CONTENT1.getBytes(UTF_8));
final File file = createFile(bos1.toByteArray());
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
@@ -135,7 +135,7 @@ public class FileBasedConfigTest {
bos2.write(0xEF);
bos2.write(0xBB);
bos2.write(0xBF);
- bos2.write(CONTENT2.getBytes(CHARSET));
+ bos2.write(CONTENT2.getBytes(UTF_8));
assertArrayEquals(bos2.toByteArray(), IO.readFully(file));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
index 57809734c3..1ff64a2e28 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
@@ -136,7 +136,49 @@ public class SubmoduleAddTest extends RepositoryTestCase {
}
SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
+ generator.loadModulesConfig();
assertTrue(generator.next());
+ assertEquals(path, generator.getModuleName());
+ assertEquals(path, generator.getPath());
+ assertEquals(commit, generator.getObjectId());
+ assertEquals(uri, generator.getModulesUrl());
+ assertEquals(path, generator.getModulesPath());
+ assertEquals(uri, generator.getConfigUrl());
+ try (Repository subModRepo = generator.getRepository()) {
+ assertNotNull(subModRepo);
+ assertEquals(subCommit, commit);
+ }
+
+ Status status = Git.wrap(db).status().call();
+ assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
+ assertTrue(status.getAdded().contains(path));
+ }
+ }
+
+ @Test
+ public void addSubmoduleWithName() throws Exception {
+ try (Git git = new Git(db)) {
+ writeTrashFile("file.txt", "content");
+ git.add().addFilepattern("file.txt").call();
+ RevCommit commit = git.commit().setMessage("create file").call();
+
+ SubmoduleAddCommand command = new SubmoduleAddCommand(db);
+ String name = "testsub";
+ command.setName(name);
+ String path = "sub";
+ command.setPath(path);
+ String uri = db.getDirectory().toURI().toString();
+ command.setURI(uri);
+ ObjectId subCommit;
+ try (Repository repo = command.call()) {
+ assertNotNull(repo);
+ subCommit = repo.resolve(Constants.HEAD);
+ }
+
+ SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
+ generator.loadModulesConfig();
+ assertTrue(generator.next());
+ assertEquals(name, generator.getModuleName());
assertEquals(path, generator.getPath());
assertEquals(commit, generator.getObjectId());
assertEquals(uri, generator.getModulesUrl());
@@ -187,16 +229,13 @@ public class SubmoduleAddTest extends RepositoryTestCase {
public void addSubmoduleWithInvalidPath() throws Exception {
SubmoduleAddCommand command = new SubmoduleAddCommand(db);
command.setPath("-invalid-path");
- // TODO(ms) set name to a valid value in 5.1.0 and adapt expected
- // message below
+ command.setName("sub");
command.setURI("http://example.com/repo/x.git");
try {
command.call().close();
fail("Exception not thrown");
} catch (IllegalArgumentException e) {
- // TODO(ms) should check for submodule path, but can't set name
- // before 5.1.0
- assertEquals("Invalid submodule name '-invalid-path'",
+ assertEquals("Invalid submodule path '-invalid-path'",
e.getMessage());
}
}
@@ -299,4 +338,18 @@ public class SubmoduleAddTest extends RepositoryTestCase {
ConfigConstants.CONFIG_KEY_URL));
}
}
+
+ @Test
+ public void denySubmoduleWithDotDot() throws Exception {
+ SubmoduleAddCommand command = new SubmoduleAddCommand(db);
+ command.setName("dir/../");
+ command.setPath("sub");
+ command.setURI(db.getDirectory().toURI().toString());
+ try {
+ command.call();
+ fail();
+ } catch (IllegalArgumentException e) {
+ // Expected
+ }
+ }
}
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
index df4b96398f..815ce9b350 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleDeinitTest.java
@@ -136,10 +136,12 @@ public class SubmoduleDeinitTest extends RepositoryTestCase {
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();
-
+ try (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());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
index d30ac840a6..7b31bfa3ad 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
@@ -45,7 +45,7 @@
package org.eclipse.jgit.transport;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -199,7 +199,8 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase {
Ref ref = repo.exactRef(refName);
assertNotNull(ref);
assertEquals(id, ref.getObjectId());
- assertEquals(data, new String(repo.open(id, OBJ_BLOB).getBytes(), CHARSET));
+ assertEquals(data,
+ new String(repo.open(id, OBJ_BLOB).getBytes(), UTF_8));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java
index 4e5d56acb2..2a4e492e3d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java
@@ -42,7 +42,7 @@
package org.eclipse.jgit.transport;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@@ -76,7 +76,7 @@ public class NetRCTest extends RepositoryTestCase {
private void config(String data) throws IOException {
try (OutputStreamWriter fw = new OutputStreamWriter(
- new FileOutputStream(configFile), CHARSET)) {
+ new FileOutputStream(configFile), UTF_8)) {
fw.write(data);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
index abf80ecd4d..19fcbfd7a2 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.transport;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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.assertFalse;
@@ -94,7 +94,7 @@ public class OpenSshConfigTest extends RepositoryTestCase {
long lastMtime = configFile.lastModified();
do {
try (final OutputStreamWriter fw = new OutputStreamWriter(
- new FileOutputStream(configFile), CHARSET)) {
+ new FileOutputStream(configFile), UTF_8)) {
fw.write(data);
}
} while (lastMtime == configFile.lastModified());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
new file mode 100644
index 0000000000..bf67d46d51
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java
@@ -0,0 +1,321 @@
+/*
+ * Copyright (C) 2018, Google LLC.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.transport;
+
+import static org.hamcrest.Matchers.hasItems;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.eclipse.jgit.errors.PackProtocolException;
+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.Config;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class ProtocolV2ParserTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private TestRepository<InMemoryRepository> testRepo;
+
+ @Before
+ public void setUp() throws Exception {
+ testRepo = new TestRepository<>(newRepo("protocol-v2-parser-test"));
+ }
+
+ private static InMemoryRepository newRepo(String name) {
+ return new InMemoryRepository(new DfsRepositoryDescription(name));
+ }
+
+ private static class ConfigBuilder {
+
+ private boolean allowRefInWant;
+
+ private boolean allowFilter;
+
+ private ConfigBuilder() {
+ }
+
+ static ConfigBuilder start() {
+ return new ConfigBuilder();
+ }
+
+ static TransferConfig getDefault() {
+ return start().done();
+ }
+
+ ConfigBuilder allowRefInWant() {
+ allowRefInWant = true;
+ return this;
+ }
+
+ ConfigBuilder allowFilter() {
+ allowFilter = true;
+ return this;
+ }
+
+ TransferConfig done() {
+ Config rc = new Config();
+ rc.setBoolean("uploadpack", null, "allowrefinwant", allowRefInWant);
+ rc.setBoolean("uploadpack", null, "allowfilter", allowFilter);
+ return new TransferConfig(rc);
+ }
+ }
+
+ /*
+ * Convert the input lines to the PacketLine that the parser reads.
+ */
+ private static PacketLineIn formatAsPacketLine(String... inputLines)
+ throws IOException {
+ ByteArrayOutputStream send = new ByteArrayOutputStream();
+ PacketLineOut pckOut = new PacketLineOut(send);
+ for (String line : inputLines) {
+ if (line == PacketLineIn.END) {
+ pckOut.end();
+ } else if (line == PacketLineIn.DELIM) {
+ pckOut.writeDelim();
+ } else {
+ pckOut.writeString(line);
+ }
+ }
+
+ return new PacketLineIn(new ByteArrayInputStream(send.toByteArray()));
+ }
+
+ private static List<String> objIdsAsStrings(Collection<ObjectId> objIds) {
+ // TODO(ifrade) Translate this to a matcher, so it would read as
+ // assertThat(req.wantsIds(), hasObjectIds("...", "..."))
+ return objIds.stream().map(ObjectId::name).collect(Collectors.toList());
+ }
+
+ /*
+ * Succesful fetch with the basic core commands of the protocol.
+ */
+ @Test
+ public void testFetchBasicArguments()
+ throws PackProtocolException, IOException {
+ PacketLineIn pckIn = formatAsPacketLine(
+ PacketLineIn.DELIM,
+ "thin-pack", "no-progress", "include-tag", "ofs-delta",
+ "want 4624442d68ee402a94364191085b77137618633e",
+ "want f900c8326a43303685c46b279b9f70411bff1a4b",
+ "have 554f6e41067b9e3e565b6988a8294fac1cb78f4b",
+ "have abc760ab9ad72f08209943251b36cb886a578f87", "done",
+ PacketLineIn.END);
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.getDefault());
+ FetchV2Request request = parser.parseFetchRequest(pckIn);
+ assertTrue(request.getOptions()
+ .contains(GitProtocolConstants.OPTION_THIN_PACK));
+ assertTrue(request.getOptions()
+ .contains(GitProtocolConstants.OPTION_NO_PROGRESS));
+ assertTrue(request.getOptions()
+ .contains(GitProtocolConstants.OPTION_INCLUDE_TAG));
+ assertTrue(request.getOptions()
+ .contains(GitProtocolConstants.CAPABILITY_OFS_DELTA));
+ assertThat(objIdsAsStrings(request.getWantsIds()),
+ hasItems("4624442d68ee402a94364191085b77137618633e",
+ "f900c8326a43303685c46b279b9f70411bff1a4b"));
+ assertThat(objIdsAsStrings(request.getPeerHas()),
+ hasItems("554f6e41067b9e3e565b6988a8294fac1cb78f4b",
+ "abc760ab9ad72f08209943251b36cb886a578f87"));
+ assertTrue(request.getWantedRefs().isEmpty());
+ assertTrue(request.wasDoneReceived());
+ }
+
+ @Test
+ public void testFetchWithShallow_deepen() throws IOException {
+ PacketLineIn pckIn = formatAsPacketLine(
+ PacketLineIn.DELIM,
+ "deepen 15",
+ "deepen-relative",
+ "shallow 28274d02c489f4c7e68153056e9061a46f62d7a0",
+ "shallow 145e683b229dcab9d0e2ccb01b386f9ecc17d29d",
+ PacketLineIn.END);
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.getDefault());
+ FetchV2Request request = parser.parseFetchRequest(pckIn);
+ assertThat(objIdsAsStrings(request.getClientShallowCommits()),
+ hasItems("28274d02c489f4c7e68153056e9061a46f62d7a0",
+ "145e683b229dcab9d0e2ccb01b386f9ecc17d29d"));
+ assertTrue(request.getDeepenNotRefs().isEmpty());
+ assertEquals(15, request.getDepth());
+ assertTrue(request.getOptions()
+ .contains(GitProtocolConstants.OPTION_DEEPEN_RELATIVE));
+ }
+
+ @Test
+ public void testFetchWithShallow_deepenNot() throws IOException {
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ "shallow 28274d02c489f4c7e68153056e9061a46f62d7a0",
+ "shallow 145e683b229dcab9d0e2ccb01b386f9ecc17d29d",
+ "deepen-not a08595f76159b09d57553e37a5123f1091bb13e7",
+ PacketLineIn.END);
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.getDefault());
+ FetchV2Request request = parser.parseFetchRequest(pckIn);
+ assertThat(objIdsAsStrings(request.getClientShallowCommits()),
+ hasItems("28274d02c489f4c7e68153056e9061a46f62d7a0",
+ "145e683b229dcab9d0e2ccb01b386f9ecc17d29d"));
+ assertThat(request.getDeepenNotRefs(),
+ hasItems("a08595f76159b09d57553e37a5123f1091bb13e7"));
+ }
+
+ @Test
+ public void testFetchWithShallow_deepenSince() throws IOException {
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ "shallow 28274d02c489f4c7e68153056e9061a46f62d7a0",
+ "shallow 145e683b229dcab9d0e2ccb01b386f9ecc17d29d",
+ "deepen-since 123123123",
+ PacketLineIn.END);
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.getDefault());
+ FetchV2Request request = parser.parseFetchRequest(pckIn);
+ assertThat(objIdsAsStrings(request.getClientShallowCommits()),
+ hasItems("28274d02c489f4c7e68153056e9061a46f62d7a0",
+ "145e683b229dcab9d0e2ccb01b386f9ecc17d29d"));
+ assertEquals(123123123, request.getDeepenSince());
+ }
+
+ @Test
+ public void testFetchWithNoneFilter() throws IOException {
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ "filter blob:none",
+ PacketLineIn.END);
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.start().allowFilter().done());
+ FetchV2Request request = parser.parseFetchRequest(pckIn);
+ assertEquals(0, request.getFilterBlobLimit());
+ }
+
+ @Test
+ public void testFetchWithBlobSizeFilter() throws IOException {
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ "filter blob:limit=15",
+ PacketLineIn.END);
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.start().allowFilter().done());
+ FetchV2Request request = parser.parseFetchRequest(pckIn);
+ assertEquals(15, request.getFilterBlobLimit());
+ }
+
+ @Test
+ public void testFetchMustNotHaveMultipleFilters() throws IOException {
+ thrown.expect(PackProtocolException.class);
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ "filter blob:none",
+ "filter blob:limit=12",
+ PacketLineIn.END);
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.start().allowFilter().done());
+ FetchV2Request request = parser.parseFetchRequest(pckIn);
+ assertEquals(0, request.getFilterBlobLimit());
+ }
+
+ @Test
+ public void testFetchFilterWithoutAllowFilter() throws IOException {
+ thrown.expect(PackProtocolException.class);
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ "filter blob:limit=12", PacketLineIn.END);
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.getDefault());
+ parser.parseFetchRequest(pckIn);
+ }
+
+ @Test
+ public void testFetchWithRefInWant() throws Exception {
+ RevCommit one = testRepo.commit().message("1").create();
+ RevCommit two = testRepo.commit().message("2").create();
+ testRepo.update("branchA", one);
+ testRepo.update("branchB", two);
+
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ "want e4980cdc48cfa1301493ca94eb70523f6788b819",
+ "want-ref refs/heads/branchA",
+ PacketLineIn.END);
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.start().allowRefInWant().done());
+
+ FetchV2Request request = parser.parseFetchRequest(pckIn);
+ assertEquals(1, request.getWantedRefs().size());
+ assertThat(request.getWantedRefs(), hasItems("refs/heads/branchA"));
+ assertEquals(1, request.getWantsIds().size());
+ assertThat(objIdsAsStrings(request.getWantsIds()),
+ hasItems("e4980cdc48cfa1301493ca94eb70523f6788b819"));
+ }
+
+ @Test
+ public void testFetchWithRefInWantUnknownRef() throws Exception {
+ PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM,
+ "want e4980cdc48cfa1301493ca94eb70523f6788b819",
+ "want-ref refs/heads/branchC",
+ PacketLineIn.END);
+ ProtocolV2Parser parser = new ProtocolV2Parser(
+ ConfigBuilder.start().allowRefInWant().done());
+
+ RevCommit one = testRepo.commit().message("1").create();
+ RevCommit two = testRepo.commit().message("2").create();
+ testRepo.update("branchA", one);
+ testRepo.update("branchB", two);
+
+ FetchV2Request request = parser.parseFetchRequest(pckIn);
+ assertEquals(1, request.getWantedRefs().size());
+ assertThat(request.getWantedRefs(), hasItems("refs/heads/branchC"));
+ }
+
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
index 0ffbe65786..c959f6c497 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
@@ -259,6 +259,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
try (TransportLocal t = newTransportLocalWithStrictValidation()) {
t.setPushThin(true);
r = t.push(PM, Collections.singleton(u));
+ dst.close();
}
assertNotNull("have result", r);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java
index 86c92bb528..953c9fc30a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java
@@ -77,6 +77,7 @@ public class TestProtocolTest {
"+refs/heads/master:refs/heads/master");
private static final int HAVES_PER_ROUND = 32;
+ private static final int MAX_HAVES = 256;
private static class User {
private final String name;
@@ -187,7 +188,7 @@ public class TestProtocolTest {
}
@Test
- public void testMinimalNegotiation() throws Exception {
+ public void testMaxHaves() throws Exception {
TestProtocol<User> proto = registerDefault();
URIish uri = proto.register(new User("user"), remote.getRepository());
@@ -200,28 +201,13 @@ public class TestProtocolTest {
RevCommit master = remote.branch("master").commit()
.add("readme.txt", "unique commit").create();
- TestProtocol.setFetchConfig(new FetchConfig(true, true));
+ TestProtocol.setFetchConfig(new FetchConfig(true, MAX_HAVES));
try (Git git = new Git(local.getRepository())) {
assertNull(local.getRepository().exactRef("refs/heads/master"));
git.fetch().setRemote(uri.toString()).setRefSpecs(MASTER).call();
assertEquals(master, local.getRepository()
.exactRef("refs/heads/master").getObjectId());
- assertTrue(havesCount <= 2 * HAVES_PER_ROUND);
-
- // Update the remote master and add local branches for 5 more rounds
- // of negotiation, where the local branch commits have newer
- // timestamps. Negotiation should send 5 rounds for those newer
- // branches before getting to the round that sends its stale version
- // of master.
- master = remote.branch("master").commit().parent(master).create();
- local.tick(2 * HAVES_PER_ROUND);
- for (int i = 0; i < 5 * HAVES_PER_ROUND; i++) {
- local.branch("local-" + i).commit().create();
- }
- git.fetch().setRemote(uri.toString()).setRefSpecs(MASTER).call();
- assertEquals(master, local.getRepository()
- .exactRef("refs/heads/master").getObjectId());
- assertEquals(6 * HAVES_PER_ROUND, havesCount);
+ assertTrue(havesCount <= MAX_HAVES);
}
}
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 ef083da183..317ac32e6d 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
@@ -1,20 +1,25 @@
package org.eclipse.jgit.transport;
+import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.theInstance;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector;
@@ -29,8 +34,8 @@ import org.eclipse.jgit.lib.Sets;
import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.revwalk.RevTag;
+import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.transport.UploadPack.RequestPolicy;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
@@ -227,6 +232,44 @@ public class UploadPackTest {
}
@Test
+ public void testFetchExplicitBlobWithFilter() throws Exception {
+ InMemoryRepository server2 = newRepo("server2");
+ TestRepository<InMemoryRepository> remote2 =
+ new TestRepository<>(server2);
+ RevBlob blob1 = remote2.blob("foobar");
+ RevBlob blob2 = remote2.blob("fooba");
+ RevTree tree = remote2.tree(remote2.file("1", blob1),
+ remote2.file("2", blob2));
+ RevCommit commit = remote2.commit(tree);
+ remote2.update("master", commit);
+ remote2.update("a_blob", blob1);
+
+ server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ testProtocol = new TestProtocol<>(
+ new UploadPackFactory<Object>() {
+ @Override
+ public UploadPack create(Object req, Repository db)
+ throws ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ UploadPack up = new UploadPack(db);
+ return up;
+ }
+ }, null);
+ uri = testProtocol.register(ctx, server2);
+
+ try (Transport tn = testProtocol.open(uri, client, "server2")) {
+ tn.setFilterBlobLimit(0);
+ tn.fetch(NullProgressMonitor.INSTANCE, Arrays.asList(
+ new RefSpec(commit.name()),
+ new RefSpec(blob1.name())));
+ assertTrue(client.hasObject(tree.toObjectId()));
+ assertTrue(client.hasObject(blob1.toObjectId()));
+ assertFalse(client.hasObject(blob2.toObjectId()));
+ }
+ }
+
+ @Test
public void testFetchWithBlobLimitFilter() throws Exception {
InMemoryRepository server2 = newRepo("server2");
TestRepository<InMemoryRepository> remote2 =
@@ -262,6 +305,47 @@ public class UploadPackTest {
}
@Test
+ public void testFetchExplicitBlobWithFilterAndBitmaps() throws Exception {
+ InMemoryRepository server2 = newRepo("server2");
+ TestRepository<InMemoryRepository> remote2 =
+ new TestRepository<>(server2);
+ RevBlob blob1 = remote2.blob("foobar");
+ RevBlob blob2 = remote2.blob("fooba");
+ RevTree tree = remote2.tree(remote2.file("1", blob1),
+ remote2.file("2", blob2));
+ RevCommit commit = remote2.commit(tree);
+ remote2.update("master", commit);
+ remote2.update("a_blob", blob1);
+
+ server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ // generate bitmaps
+ new DfsGarbageCollector(server2).pack(null);
+ server2.scanForRepoChanges();
+
+ testProtocol = new TestProtocol<>(
+ new UploadPackFactory<Object>() {
+ @Override
+ public UploadPack create(Object req, Repository db)
+ throws ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ UploadPack up = new UploadPack(db);
+ return up;
+ }
+ }, null);
+ uri = testProtocol.register(ctx, server2);
+
+ try (Transport tn = testProtocol.open(uri, client, "server2")) {
+ tn.setFilterBlobLimit(0);
+ tn.fetch(NullProgressMonitor.INSTANCE, Arrays.asList(
+ new RefSpec(commit.name()),
+ new RefSpec(blob1.name())));
+ assertTrue(client.hasObject(blob1.toObjectId()));
+ assertFalse(client.hasObject(blob2.toObjectId()));
+ }
+ }
+
+ @Test
public void testFetchWithBlobLimitFilterAndBitmaps() throws Exception {
InMemoryRepository server2 = newRepo("server2");
TestRepository<InMemoryRepository> remote2 =
@@ -340,7 +424,8 @@ public class UploadPackTest {
* and returns UploadPack's output stream.
*/
private ByteArrayInputStream uploadPackV2Setup(RequestPolicy requestPolicy,
- RefFilter refFilter, String... inputLines) throws Exception {
+ RefFilter refFilter, ProtocolV2Hook hook, String... inputLines)
+ throws Exception {
ByteArrayOutputStream send = new ByteArrayOutputStream();
PacketLineOut pckOut = new PacketLineOut(send);
@@ -361,6 +446,9 @@ public class UploadPackTest {
if (refFilter != null)
up.setRefFilter(refFilter);
up.setExtraParameters(Sets.of("version=2"));
+ if (hook != null) {
+ up.setProtocolV2Hook(hook);
+ }
ByteArrayOutputStream recv = new ByteArrayOutputStream();
up.upload(new ByteArrayInputStream(send.toByteArray()), recv, null);
@@ -374,9 +462,10 @@ public class UploadPackTest {
* advertisement by the server.
*/
private ByteArrayInputStream uploadPackV2(RequestPolicy requestPolicy,
- RefFilter refFilter, String... inputLines) throws Exception {
+ RefFilter refFilter, ProtocolV2Hook hook, String... inputLines)
+ throws Exception {
ByteArrayInputStream recvStream =
- uploadPackV2Setup(requestPolicy, refFilter, inputLines);
+ uploadPackV2Setup(requestPolicy, refFilter, hook, inputLines);
PacketLineIn pckIn = new PacketLineIn(recvStream);
// drain capabilities
@@ -387,15 +476,33 @@ public class UploadPackTest {
}
private ByteArrayInputStream uploadPackV2(String... inputLines) throws Exception {
- return uploadPackV2(null, null, inputLines);
+ return uploadPackV2(null, null, null, inputLines);
+ }
+
+ private static class TestV2Hook implements ProtocolV2Hook {
+ private CapabilitiesV2Request capabilitiesRequest;
+
+ private LsRefsV2Request lsRefsRequest;
+
+ @Override
+ public void onCapabilities(CapabilitiesV2Request req) {
+ capabilitiesRequest = req;
+ }
+
+ @Override
+ public void onLsRefs(LsRefsV2Request req) {
+ lsRefsRequest = req;
+ }
}
@Test
public void testV2Capabilities() throws Exception {
+ TestV2Hook hook = new TestV2Hook();
ByteArrayInputStream recvStream =
- uploadPackV2Setup(null, null, PacketLineIn.END);
+ uploadPackV2Setup(null, null, hook, PacketLineIn.END);
PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(hook.capabilitiesRequest, notNullValue());
assertThat(pckIn.readString(), is("version 2"));
assertThat(
Arrays.asList(pckIn.readString(), pckIn.readString()),
@@ -413,7 +520,7 @@ public class UploadPackTest {
public void testV2CapabilitiesAllowFilter() throws Exception {
server.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
ByteArrayInputStream recvStream =
- uploadPackV2Setup(null, null, PacketLineIn.END);
+ uploadPackV2Setup(null, null, null, PacketLineIn.END);
PacketLineIn pckIn = new PacketLineIn(recvStream);
assertThat(pckIn.readString(), is("version 2"));
@@ -426,12 +533,56 @@ public class UploadPackTest {
}
@Test
- @SuppressWarnings("boxing")
+ public void testV2CapabilitiesRefInWant() throws Exception {
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", true);
+ ByteArrayInputStream recvStream =
+ uploadPackV2Setup(null, null, null, PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("version 2"));
+ assertThat(
+ Arrays.asList(pckIn.readString(), pckIn.readString()),
+ // TODO(jonathantanmy) This check overspecifies the
+ // order of the capabilities of "fetch".
+ hasItems("ls-refs", "fetch=ref-in-want shallow"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2CapabilitiesRefInWantNotAdvertisedIfUnallowed() throws Exception {
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", false);
+ ByteArrayInputStream recvStream =
+ uploadPackV2Setup(null, null, null, PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("version 2"));
+ assertThat(
+ Arrays.asList(pckIn.readString(), pckIn.readString()),
+ hasItems("ls-refs", "fetch=shallow"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
+ public void testV2CapabilitiesRefInWantNotAdvertisedIfAdvertisingForbidden() throws Exception {
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", true);
+ server.getConfig().setBoolean("uploadpack", null, "advertiserefinwant", false);
+ ByteArrayInputStream recvStream =
+ uploadPackV2Setup(null, null, null, PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("version 2"));
+ assertThat(
+ Arrays.asList(pckIn.readString(), pckIn.readString()),
+ hasItems("ls-refs", "fetch=shallow"));
+ assertTrue(pckIn.readString() == PacketLineIn.END);
+ }
+
+ @Test
public void testV2EmptyRequest() throws Exception {
ByteArrayInputStream recvStream = uploadPackV2(PacketLineIn.END);
// Verify that there is nothing more after the capability
// advertisement.
- assertThat(recvStream.available(), is(0));
+ assertEquals(0, recvStream.available());
}
@Test
@@ -442,9 +593,12 @@ public class UploadPackTest {
RevTag tag = remote.tag("tag", tip);
remote.update("refs/tags/tag", tag);
- ByteArrayInputStream recvStream = uploadPackV2("command=ls-refs\n", PacketLineIn.END);
+ TestV2Hook hook = new TestV2Hook();
+ ByteArrayInputStream recvStream = uploadPackV2(null, null, hook,
+ "command=ls-refs\n", PacketLineIn.END);
PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(hook.lsRefsRequest, notNullValue());
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD"));
assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master"));
assertThat(pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag"));
@@ -579,6 +733,10 @@ public class UploadPackTest {
new StringWriter(), NullOutputStream.INSTANCE);
PackParser pp = client.newObjectInserter().newPackParser(sb);
pp.parse(NullProgressMonitor.INSTANCE);
+
+ // Ensure that there is nothing left in the stream.
+ assertEquals(-1, recvStream.read());
+
return pp.getReceivedPackStatistics();
}
@@ -592,6 +750,7 @@ public class UploadPackTest {
uploadPackV2(
RequestPolicy.ADVERTISED,
null,
+ null,
"command=fetch\n",
PacketLineIn.DELIM,
"want " + advertized.name() + "\n",
@@ -604,6 +763,7 @@ public class UploadPackTest {
uploadPackV2(
RequestPolicy.ADVERTISED,
null,
+ null,
"command=fetch\n",
PacketLineIn.DELIM,
"want " + unadvertized.name() + "\n",
@@ -621,6 +781,7 @@ public class UploadPackTest {
uploadPackV2(
RequestPolicy.REACHABLE_COMMIT,
null,
+ null,
"command=fetch\n",
PacketLineIn.DELIM,
"want " + reachable.name() + "\n",
@@ -633,6 +794,7 @@ public class UploadPackTest {
uploadPackV2(
RequestPolicy.REACHABLE_COMMIT,
null,
+ null,
"command=fetch\n",
PacketLineIn.DELIM,
"want " + unreachable.name() + "\n",
@@ -649,6 +811,7 @@ public class UploadPackTest {
uploadPackV2(
RequestPolicy.TIP,
new RejectAllRefFilter(),
+ null,
"command=fetch\n",
PacketLineIn.DELIM,
"want " + tip.name() + "\n",
@@ -661,6 +824,7 @@ public class UploadPackTest {
uploadPackV2(
RequestPolicy.TIP,
new RejectAllRefFilter(),
+ null,
"command=fetch\n",
PacketLineIn.DELIM,
"want " + parentOfTip.name() + "\n",
@@ -678,6 +842,7 @@ public class UploadPackTest {
uploadPackV2(
RequestPolicy.REACHABLE_COMMIT_TIP,
new RejectAllRefFilter(),
+ null,
"command=fetch\n",
PacketLineIn.DELIM,
"want " + parentOfTip.name() + "\n",
@@ -690,6 +855,7 @@ public class UploadPackTest {
uploadPackV2(
RequestPolicy.REACHABLE_COMMIT_TIP,
new RejectAllRefFilter(),
+ null,
"command=fetch\n",
PacketLineIn.DELIM,
"want " + unreachable.name() + "\n",
@@ -704,6 +870,7 @@ public class UploadPackTest {
uploadPackV2(
RequestPolicy.ANY,
null,
+ null,
"command=fetch\n",
PacketLineIn.DELIM,
"want " + unreachable.name() + "\n",
@@ -1078,6 +1245,216 @@ public class UploadPackTest {
PacketLineIn.END);
}
+ @Test
+ public void testV2FetchWantRefIfNotAllowed() throws Exception {
+ RevCommit one = remote.commit().message("1").create();
+ remote.update("one", one);
+
+ try {
+ uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want-ref refs/heads/one\n",
+ "done\n",
+ PacketLineIn.END);
+ } catch (PackProtocolException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("unexpected want-ref refs/heads/one"));
+ return;
+ }
+ fail("expected PackProtocolException");
+ }
+
+ @Test
+ public void testV2FetchWantRef() throws Exception {
+ RevCommit one = remote.commit().message("1").create();
+ RevCommit two = remote.commit().message("2").create();
+ RevCommit three = remote.commit().message("3").create();
+ remote.update("one", one);
+ remote.update("two", two);
+ remote.update("three", three);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", true);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want-ref refs/heads/one\n",
+ "want-ref refs/heads/two\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("wanted-refs"));
+ assertThat(
+ Arrays.asList(pckIn.readString(), pckIn.readString()),
+ hasItems(
+ one.toObjectId().getName() + " refs/heads/one",
+ two.toObjectId().getName() + " refs/heads/two"));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+
+ assertTrue(client.hasObject(one.toObjectId()));
+ assertTrue(client.hasObject(two.toObjectId()));
+ assertFalse(client.hasObject(three.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchBadWantRef() throws Exception {
+ RevCommit one = remote.commit().message("1").create();
+ remote.update("one", one);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", true);
+
+ try {
+ uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want-ref refs/heads/one\n",
+ "want-ref refs/heads/nonExistentRef\n",
+ "done\n",
+ PacketLineIn.END);
+ } catch (PackProtocolException e) {
+ assertThat(
+ e.getMessage(),
+ containsString("Invalid ref name: refs/heads/nonExistentRef"));
+ return;
+ }
+ fail("expected PackProtocolException");
+ }
+
+ @Test
+ public void testV2FetchMixedWantRef() throws Exception {
+ RevCommit one = remote.commit().message("1").create();
+ RevCommit two = remote.commit().message("2").create();
+ RevCommit three = remote.commit().message("3").create();
+ remote.update("one", one);
+ remote.update("two", two);
+ remote.update("three", three);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", true);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want-ref refs/heads/one\n",
+ "want " + two.toObjectId().getName() + "\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+ assertThat(pckIn.readString(), is("wanted-refs"));
+ assertThat(
+ pckIn.readString(),
+ is(one.toObjectId().getName() + " refs/heads/one"));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+
+ assertTrue(client.hasObject(one.toObjectId()));
+ assertTrue(client.hasObject(two.toObjectId()));
+ assertFalse(client.hasObject(three.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchWantRefWeAlreadyHave() throws Exception {
+ RevCommit one = remote.commit().message("1").create();
+ remote.update("one", one);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", true);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want-ref refs/heads/one\n",
+ "have " + one.toObjectId().getName(),
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ // The client still needs to know the hash of the object that
+ // refs/heads/one points to, even though it already has the
+ // object ...
+ assertThat(pckIn.readString(), is("wanted-refs"));
+ assertThat(
+ pckIn.readString(),
+ is(one.toObjectId().getName() + " refs/heads/one"));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+
+ // ... but the client does not need the object itself.
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ assertFalse(client.hasObject(one.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchWantRefAndDeepen() throws Exception {
+ RevCommit parent = remote.commit().message("parent").create();
+ RevCommit child = remote.commit().message("x").parent(parent).create();
+ remote.update("branch1", child);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", true);
+
+ ByteArrayInputStream recvStream = uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "want-ref refs/heads/branch1\n",
+ "deepen 1\n",
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ // shallow-info appears first, then wanted-refs.
+ assertThat(pckIn.readString(), is("shallow-info"));
+ assertThat(pckIn.readString(), is("shallow " + child.toObjectId().getName()));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertThat(pckIn.readString(), is("wanted-refs"));
+ assertThat(pckIn.readString(), is(child.toObjectId().getName() + " refs/heads/branch1"));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+ assertTrue(client.hasObject(child.toObjectId()));
+ assertFalse(client.hasObject(parent.toObjectId()));
+ }
+
+ @Test
+ public void testV2FetchMissingShallow() throws Exception {
+ RevCommit one = remote.commit().message("1").create();
+ RevCommit two = remote.commit().message("2").parent(one).create();
+ RevCommit three = remote.commit().message("3").parent(two).create();
+ remote.update("three", three);
+
+ server.getConfig().setBoolean("uploadpack", null, "allowrefinwant",
+ true);
+
+ ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n",
+ PacketLineIn.DELIM,
+ "want-ref refs/heads/three\n",
+ "deepen 3",
+ "shallow 0123012301230123012301230123012301230123",
+ "shallow " + two.getName() + '\n',
+ "done\n",
+ PacketLineIn.END);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(), is("shallow-info"));
+ assertThat(pckIn.readString(),
+ is("shallow " + one.toObjectId().getName()));
+ assertThat(pckIn.readString(),
+ is("unshallow " + two.toObjectId().getName()));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertThat(pckIn.readString(), is("wanted-refs"));
+ assertThat(pckIn.readString(),
+ is(three.toObjectId().getName() + " refs/heads/three"));
+ assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM));
+ assertThat(pckIn.readString(), is("packfile"));
+ parsePack(recvStream);
+
+ assertTrue(client.hasObject(one.toObjectId()));
+ assertTrue(client.hasObject(two.toObjectId()));
+ assertTrue(client.hasObject(three.toObjectId()));
+ }
+
private static class RejectAllRefFilter implements RefFilter {
@Override
public Map<String, Ref> filter(Map<String, Ref> refs) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
index 33e2529731..f2fb0224ef 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.transport;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListPBE;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListTrans;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.folderDelete;
@@ -360,7 +360,7 @@ public class WalkEncryptionTest {
* @throws Exception
*/
static String textRead(File file) throws Exception {
- return new String(Files.readAllBytes(file.toPath()), CHARSET);
+ return new String(Files.readAllBytes(file.toPath()), UTF_8);
}
/**
@@ -371,7 +371,7 @@ public class WalkEncryptionTest {
* @throws Exception
*/
static void textWrite(File file, String text) throws Exception {
- Files.write(file.toPath(), text.getBytes(CHARSET));
+ Files.write(file.toPath(), text.getBytes(UTF_8));
}
static void verifyFileContent(File fileOne, File fileTwo)
@@ -420,7 +420,7 @@ public class WalkEncryptionTest {
c.setConnectTimeout(500);
c.setReadTimeout(500);
try (BufferedReader reader = new BufferedReader(
- new InputStreamReader(c.getInputStream()))) {
+ new InputStreamReader(c.getInputStream(), UTF_8))) {
return reader.readLine();
}
} catch (UnknownHostException | SocketTimeoutException e) {
@@ -738,7 +738,7 @@ public class WalkEncryptionTest {
AmazonS3 s3 = new AmazonS3(props);
String file = JGIT_USER + "-" + UUID.randomUUID().toString();
String path = JGIT_REMOTE_DIR + "/" + file;
- s3.put(bucket, path, file.getBytes(CHARSET));
+ s3.put(bucket, path, file.getBytes(UTF_8));
s3.delete(bucket, path);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java
index 6195e640fb..41bd355a2f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.treewalk;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.FileMode.REGULAR_FILE;
import static org.eclipse.jgit.lib.FileMode.SYMLINK;
import static org.junit.Assert.assertEquals;
@@ -110,7 +111,7 @@ public class CanonicalTreeParserTest {
}
private String path() {
- return RawParseUtils.decode(Constants.CHARSET, ctp.path,
+ return RawParseUtils.decode(UTF_8, ctp.path,
ctp.pathOffset, ctp.pathLen);
}
@@ -370,7 +371,7 @@ public class CanonicalTreeParserTest {
final String name = b.toString();
ctp.reset(entry(m644, name, hash_a));
assertFalse(ctp.eof());
- assertEquals(name, RawParseUtils.decode(Constants.CHARSET, ctp.path,
+ assertEquals(name, RawParseUtils.decode(UTF_8, ctp.path,
ctp.pathOffset, ctp.pathLen));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
index 0e009b9540..33e32cd813 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.treewalk;
+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;
@@ -331,7 +332,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
DirCacheEntry dce = db.readDirCache().getEntry("symlink");
dce.setFileMode(FileMode.SYMLINK);
try (ObjectReader objectReader = db.newObjectReader()) {
- DirCacheCheckout.checkoutEntry(db, dce, objectReader);
+ DirCacheCheckout.checkoutEntry(db, dce, objectReader, false, null);
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(),
db.getConfig().get(WorkingTreeOptions.KEY));
@@ -822,6 +823,6 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
}
private static String nameOf(AbstractTreeIterator i) {
- return RawParseUtils.decode(Constants.CHARSET, i.path, 0, i.pathLen);
+ return RawParseUtils.decode(UTF_8, i.path, 0, i.pathLen);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
index 71a2f327c8..15d03d38e7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathFilterGroupTest.java
@@ -231,8 +231,8 @@ public class PathFilterGroupTest {
}
}
- String[] e = expect.toArray(new String[expect.size()]);
- String[] a = actual.toArray(new String[actual.size()]);
+ String[] e = expect.toArray(new String[0]);
+ String[] a = actual.toArray(new String[0]);
Arrays.sort(e);
Arrays.sort(a);
assertArrayEquals(e, a);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java
index 0d31811257..8dfdd0fc7c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FilterCommandsTest.java
@@ -85,6 +85,8 @@ public class FilterCommandsTest extends RepositoryTestCase {
public int run() throws IOException {
int b = in.read();
if (b == -1) {
+ in.close();
+ out.close();
return b;
}
out.write(prefix);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtilsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtilsTest.java
index 7bd9adb90c..3aae59e908 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtilsTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawParseUtilsTest.java
@@ -52,7 +52,24 @@ import java.nio.charset.UnsupportedCharsetException;
import org.eclipse.jgit.lib.Constants;
import org.junit.Test;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
public class RawParseUtilsTest {
+ String commit = "tree e3a1035abd2b319bb01e57d69b0ba6cab289297e\n" +
+ "parent 54e895b87c0768d2317a2b17062e3ad9f76a8105\n" +
+ "committer A U Thor <author@xample.com 1528968566 +0200\n" +
+ "gpgsig -----BEGIN PGP SIGNATURE-----\n" +
+ " \n" +
+ " wsBcBAABCAAQBQJbGB4pCRBK7hj4Ov3rIwAAdHIIAENrvz23867ZgqrmyPemBEZP\n" +
+ " U24B1Tlq/DWvce2buaxmbNQngKZ0pv2s8VMc11916WfTIC9EKvioatmpjduWvhqj\n" +
+ " znQTFyiMor30pyYsfrqFuQZvqBW01o8GEWqLg8zjf9Rf0R3LlOEw86aT8CdHRlm6\n" +
+ " wlb22xb8qoX4RB+LYfz7MhK5F+yLOPXZdJnAVbuyoMGRnDpwdzjL5Hj671+XJxN5\n" +
+ " SasRdhxkkfw/ZnHxaKEc4juMz8Nziz27elRwhOQqlTYoXNJnsV//wy5Losd7aKi1\n" +
+ " xXXyUpndEOmT0CIcKHrN/kbYoVL28OJaxoBuva3WYQaRrzEe3X02NMxZe9gkSqA=\n" +
+ " =TClh\n" +
+ " -----END PGP SIGNATURE-----\n" +
+ "some other header\n\n" +
+ "commit message";
@Test
public void testParseEncoding_ISO8859_1_encoding() {
@@ -79,4 +96,30 @@ public class RawParseUtilsTest {
}
}
+ @Test
+ public void testHeaderStart() {
+ byte[] headerName = "some".getBytes(UTF_8);
+ byte[] commitBytes = commit.getBytes(UTF_8);
+ assertEquals(625, RawParseUtils.headerStart(headerName, commitBytes, 0));
+ assertEquals(625, RawParseUtils.headerStart(headerName, commitBytes, 4));
+
+ byte[] missingHeaderName = "missing".getBytes(UTF_8);
+ assertEquals(-1, RawParseUtils.headerStart(missingHeaderName,
+ commitBytes, 0));
+
+ byte[] fauxHeaderName = "other".getBytes(UTF_8);
+ assertEquals(-1, RawParseUtils.headerStart(fauxHeaderName, commitBytes, 625 + 4));
+ }
+
+ @Test
+ public void testHeaderEnd() {
+ byte[] commitBytes = commit.getBytes(UTF_8);
+ int[] expected = new int[] {45, 93, 148, 619, 637};
+ int start = 0;
+ for (int i = 0; i < expected.length; i++) {
+ start = RawParseUtils.headerEnd(commitBytes, start);
+ assertEquals(expected[i], start);
+ start += 1;
+ }
+ }
}
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 a748b52215..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,7 +42,7 @@
*/
package org.eclipse.jgit.util;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -93,7 +93,7 @@ public class RawSubStringPatternTest extends RepositoryTestCase {
}
private static RawCharSequence raw(String text) {
- byte[] bytes = text.getBytes(CHARSET);
+ 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 5058165802..37ca951f67 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,7 +44,7 @@
package org.eclipse.jgit.util.io;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
@@ -132,6 +132,6 @@ public class AutoLFInputStreamTest {
}
private static byte[] asBytes(String in) {
- return in.getBytes(CHARSET);
+ 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 3c612e1bdd..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,7 +43,7 @@
package org.eclipse.jgit.util.sha1;
-import static org.eclipse.jgit.lib.Constants.CHARSET;
+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;
@@ -95,15 +95,15 @@ public class SHA1Test {
.fromString("a9993e364706816aba3e25717850c26c9cd0d89d");
MessageDigest m = MessageDigest.getInstance("SHA-1");
- m.update(TEST1.getBytes(CHARSET));
+ m.update(TEST1.getBytes(UTF_8));
ObjectId m1 = ObjectId.fromRaw(m.digest());
SHA1 s = SHA1.newInstance();
- s.update(TEST1.getBytes(CHARSET));
+ s.update(TEST1.getBytes(UTF_8));
ObjectId s1 = ObjectId.fromRaw(s.digest());
s.reset();
- s.update(TEST1.getBytes(CHARSET));
+ 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(CHARSET));
+ m.update(TEST2.getBytes(UTF_8));
ObjectId m1 = ObjectId.fromRaw(m.digest());
SHA1 s = SHA1.newInstance();
- s.update(TEST2.getBytes(CHARSET));
+ s.update(TEST2.getBytes(UTF_8));
ObjectId s1 = ObjectId.fromRaw(s.digest());
s.reset();
- s.update(TEST2.getBytes(CHARSET));
+ s.update(TEST2.getBytes(UTF_8));
ObjectId s2 = s.toObjectId();
assertEquals(m1, s1);