aboutsummaryrefslogtreecommitdiffstats
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/internal/revwalk/ReachabilityCheckerTestCase.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java103
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java22
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ObjectIdMatcher.java2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java47
5 files changed, 173 insertions, 3 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/ReachabilityCheckerTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/ReachabilityCheckerTestCase.java
index 1ff6e7defb..7679c11098 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/ReachabilityCheckerTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/ReachabilityCheckerTestCase.java
@@ -57,7 +57,7 @@ public abstract class ReachabilityCheckerTestCase
assertReachable("reachable from another tip",
checker.areAllReachable(Arrays.asList(a), Stream.of(b2)));
assertReachable("reachable from itself",
- checker.areAllReachable(Arrays.asList(a), Stream.of(b2)));
+ checker.areAllReachable(Arrays.asList(a), Stream.of(a)));
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index 327b554b48..fe3c1db502 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
@@ -34,6 +34,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.text.MessageFormat;
@@ -50,6 +51,7 @@ import java.util.function.Consumer;
import org.eclipse.jgit.api.MergeCommand.FastForwardMode;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.internal.JGitText;
+import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.merge.MergeConfig;
import org.eclipse.jgit.storage.file.FileBasedConfig;
@@ -1463,6 +1465,107 @@ public class ConfigTest {
assertEquals("tr ue", parseEscapedValue("tr \\\r\n ue"));
}
+ @Test
+ public void testCommitTemplateEmptyConfig()
+ throws ConfigInvalidException, IOException {
+ // no values defined nowhere
+ Config config = new Config(null);
+ assertNull(config.get(CommitConfig.KEY).getCommitTemplatePath());
+ assertNull(config.get(CommitConfig.KEY).getCommitTemplateContent());
+ }
+
+ @Test
+ public void testCommitTemplateConfig()
+ throws ConfigInvalidException, IOException {
+
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ String expectedTemplatePath = tempFile.getPath();
+
+ Config config = parse(
+ "[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+
+ String templatePath = config.get(CommitConfig.KEY)
+ .getCommitTemplatePath();
+ String commitEncoding = config.get(CommitConfig.KEY)
+ .getCommitEncoding();
+ assertEquals(expectedTemplatePath, templatePath);
+ assertEquals(templateContent,
+ config.get(CommitConfig.KEY).getCommitTemplateContent());
+ assertNull("no commitEncoding has been set so it must be null",
+ commitEncoding);
+ }
+
+ @Test
+ public void testCommitTemplateEncoding()
+ throws ConfigInvalidException, IOException {
+ Config config = new Config(null);
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ String expectedTemplatePath = tempFile.getPath();
+ config = parse("[i18n]\n\tcommitEncoding = utf-8\n"
+ + "[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+ assertEquals(templateContent,
+ config.get(CommitConfig.KEY).getCommitTemplateContent());
+ String commitEncoding = config.get(CommitConfig.KEY)
+ .getCommitEncoding();
+ assertEquals("commitEncoding has been set to utf-8 it must be utf-8",
+ "utf-8", commitEncoding);
+ }
+
+ @Test
+ public void testCommitTemplatePathInHomeDirecory()
+ throws ConfigInvalidException, IOException {
+ Config config = new Config(null);
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ // proper evaluation of the ~/ directory
+ String homeDir = System.getProperty("user.home");
+ File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder",
+ ".tmp", new File(homeDir));
+ tempFileInHomeDirectory.deleteOnExit();
+ JGitTestUtil.write(tempFileInHomeDirectory, templateContent);
+ String expectedTemplatePath = tempFileInHomeDirectory.getPath()
+ .replace(homeDir, "~");
+ config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+ String templatePath = config.get(CommitConfig.KEY)
+ .getCommitTemplatePath();
+ assertEquals(expectedTemplatePath, templatePath);
+ assertEquals(templateContent,
+ config.get(CommitConfig.KEY).getCommitTemplateContent());
+ }
+
+ @Test(expected = ConfigInvalidException.class)
+ public void testCommitTemplateWithInvalidEncoding()
+ throws ConfigInvalidException, IOException {
+ Config config = new Config(null);
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ config = parse("[i18n]\n\tcommitEncoding = invalidEcoding\n"
+ + "[commit]\n\ttemplate = " + tempFile.getPath() + "\n");
+ config.get(CommitConfig.KEY).getCommitTemplateContent();
+ }
+
+ @Test(expected = FileNotFoundException.class)
+ public void testCommitTemplateWithInvalidPath()
+ throws ConfigInvalidException, IOException {
+ Config config = new Config(null);
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ // commit message encoding
+ String expectedTemplatePath = "nonExistingTemplate";
+ config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+ String templatePath = config.get(CommitConfig.KEY)
+ .getCommitTemplatePath();
+ assertEquals(expectedTemplatePath, templatePath);
+ config.get(CommitConfig.KEY).getCommitTemplateContent();
+ }
+
private static void assertValueRoundTrip(String value)
throws ConfigInvalidException {
assertValueRoundTrip(value, value);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkUtilsReachableTest.java
index d9ed0c1c63..200cb6a4fe 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
@@ -76,6 +76,28 @@ public class RevWalkUtilsReachableTest extends RevWalkTestCase {
}
}
+ @Test
+ public void findBranchesReachableManyTimes() throws Exception {
+ /*
+ * a b
+ * | |
+ * c d
+ */
+ RevCommit a = commit();
+ RevCommit b = commit();
+ RevCommit c = commit(a);
+ RevCommit d = commit(b);
+ Ref branchA = branch("a", a);
+ Ref branchB = branch("b", b);
+ Ref branchC = branch("c", c);
+ Ref branchD = branch("d", d);
+
+ assertContains(a, asList(branchA, branchC));
+ assertContains(b, asList(branchB, branchD));
+ assertContains(c, asList(branchC));
+ assertContains(d, asList(branchD));
+ }
+
private Ref branch(String name, RevCommit dst) throws Exception {
return Git.wrap(db).branchCreate().setName(name)
.setStartPoint(dst.name()).call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ObjectIdMatcher.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ObjectIdMatcher.java
index c3df19a230..77e8afb2b9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ObjectIdMatcher.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ObjectIdMatcher.java
@@ -16,7 +16,6 @@ import java.util.stream.Collectors;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Sets;
import org.hamcrest.Description;
-import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
@@ -59,7 +58,6 @@ class ObjectIdMatcher extends TypeSafeMatcher<Collection<ObjectId>> {
* @return true if examined and specified sets contains exactly the same
* elements.
*/
- @Factory
static Matcher<Collection<ObjectId>> hasOnlyObjectIds(
String... oids) {
return new ObjectIdMatcher(Sets.of(oids));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
index b0b5f68efa..f4bbb4c9f8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
@@ -460,6 +460,8 @@ public class UploadPackTest {
private FetchV2Request fetchRequest;
+ private ObjectInfoRequest objectInfoRequest;
+
@Override
public void onCapabilities(CapabilitiesV2Request req) {
capabilitiesRequest = req;
@@ -474,6 +476,11 @@ public class UploadPackTest {
public void onFetch(FetchV2Request req) {
fetchRequest = req;
}
+
+ @Override
+ public void onObjectInfo(ObjectInfoRequest req) {
+ objectInfoRequest = req;
+ }
}
@Test
@@ -2641,4 +2648,44 @@ public class UploadPackTest {
return refdb;
}
}
+
+ @Test
+ public void testObjectInfo() throws Exception {
+ server.getConfig().setBoolean("uploadpack", null, "advertiseobjectinfo",
+ true);
+
+ RevBlob blob1 = remote.blob("foobar");
+ RevBlob blob2 = remote.blob("fooba");
+ RevTree tree = remote.tree(remote.file("1", blob1),
+ remote.file("2", blob2));
+ RevCommit commit = remote.commit(tree);
+ remote.update("master", commit);
+
+ TestV2Hook hook = new TestV2Hook();
+ ByteArrayInputStream recvStream = uploadPackV2((UploadPack up) -> {
+ up.setProtocolV2Hook(hook);
+ }, "command=object-info\n", "size",
+ "oid " + ObjectId.toString(blob1.getId()),
+ "oid " + ObjectId.toString(blob2.getId()), PacketLineIn.end());
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(hook.objectInfoRequest, notNullValue());
+ assertThat(pckIn.readString(), is("size"));
+ assertThat(pckIn.readString(),
+ is(ObjectId.toString(blob1.getId()) + " 6"));
+ assertThat(pckIn.readString(),
+ is(ObjectId.toString(blob2.getId()) + " 5"));
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
+ }
+
+ @Test
+ public void testObjectInfo_invalidOid() throws Exception {
+ server.getConfig().setBoolean("uploadpack", null, "advertiseobjectinfo",
+ true);
+
+ assertThrows(UploadPackInternalServerErrorException.class,
+ () -> uploadPackV2("command=object-info\n", "size",
+ "oid invalid",
+ PacketLineIn.end()));
+ }
}