aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2018-10-06 19:14:35 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2018-10-06 19:28:51 +0200
commit1133faff8ca980b688e79a3fcadd1641ff6b3bcd (patch)
treea0248c0e3571dc98bd26533096ec83e9cbdfad86 /org.eclipse.jgit.test/tst/org/eclipse/jgit/lib
parent569cf1856caf74274744619039fecc81f1856e62 (diff)
parent2078b23ceebc2a021941ab6f7a6e7f7fdb5e34d5 (diff)
downloadjgit-1133faff8ca980b688e79a3fcadd1641ff6b3bcd.tar.gz
jgit-1133faff8ca980b688e79a3fcadd1641ff6b3bcd.zip
Merge branch 'stable-5.1'
* stable-5.1: Prepare 5.1.3-SNAPSHOT builds JGit v5.1.2.201810061102-r Prepare 4.11.5-SNAPSHOT builds JGit v4.11.4.201810060650-r Fix configuration of maven-javadoc-plugin Prepare 4.9.7-SNAPSHOT builds JGit v4.9.6.201810051924-r Prepare 4.7.6-SNAPSHOT builds JGit v4.7.5.201810051826-r BaseReceivePack: Validate incoming .gitmodules files ObjectChecker: Report .gitmodules files found in the pack SubmoduleAddCommand: Reject submodule URIs that look like cli options Revert "Configure WindowCache settings to use in JGit CLI" Change-Id: I833d30d6de75b097377872c000b2ef5a1b96cf89 Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/lib')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java119
1 files changed, 117 insertions, 2 deletions
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 7ea504374c..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
@@ -837,6 +837,112 @@ public class ObjectCheckerTest {
}
@Test
+ public void testValidTreeWithGitmodules() throws CorruptObjectException {
+ ObjectId treeId = ObjectId
+ .fromString("0123012301230123012301230123012301230123");
+ StringBuilder b = new StringBuilder();
+ ObjectId blobId = entry(b, "100644 .gitmodules");
+
+ byte[] data = encodeASCII(b.toString());
+ checker.checkTree(treeId, data);
+ assertEquals(1, checker.getGitsubmodules().size());
+ assertEquals(treeId, checker.getGitsubmodules().get(0).getTreeId());
+ assertEquals(blobId, checker.getGitsubmodules().get(0).getBlobId());
+ }
+
+ /*
+ * Windows case insensitivity and long file name handling
+ * means that .gitmodules has many synonyms.
+ *
+ * Examples inspired by git.git's t/t0060-path-utils.sh, by
+ * Johannes Schindelin and Congyi Wu.
+ */
+ @Test
+ public void testNTFSGitmodules() throws CorruptObjectException {
+ for (String gitmodules : new String[] {
+ ".GITMODULES",
+ ".gitmodules",
+ ".Gitmodules",
+ ".gitmoduleS",
+ "gitmod~1",
+ "GITMOD~1",
+ "gitmod~4",
+ "GI7EBA~1",
+ "gi7eba~9",
+ "GI7EB~10",
+ "GI7E~123",
+ "~1000000",
+ "~9999999"
+ }) {
+ checker = new ObjectChecker(); // Reset the ObjectChecker state.
+ checker.setSafeForWindows(true);
+ ObjectId treeId = ObjectId
+ .fromString("0123012301230123012301230123012301230123");
+ StringBuilder b = new StringBuilder();
+ ObjectId blobId = entry(b, "100644 " + gitmodules);
+
+ byte[] data = encodeASCII(b.toString());
+ checker.checkTree(treeId, data);
+ assertEquals(1, checker.getGitsubmodules().size());
+ assertEquals(treeId, checker.getGitsubmodules().get(0).getTreeId());
+ assertEquals(blobId, checker.getGitsubmodules().get(0).getBlobId());
+ }
+ }
+
+ @Test
+ public void testNotGitmodules() throws CorruptObjectException {
+ for (String notGitmodules : new String[] {
+ ".gitmodu",
+ ".gitmodules oh never mind",
+ }) {
+ checker = new ObjectChecker(); // Reset the ObjectChecker state.
+ checker.setSafeForWindows(true);
+ ObjectId treeId = ObjectId
+ .fromString("0123012301230123012301230123012301230123");
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 " + notGitmodules);
+
+ byte[] data = encodeASCII(b.toString());
+ checker.checkTree(treeId, data);
+ assertEquals(0, checker.getGitsubmodules().size());
+ }
+ }
+
+ /*
+ * TODO HFS: match ".gitmodules" case-insensitively, after stripping out
+ * certain zero-length Unicode code points that HFS+ strips out
+ */
+
+ @Test
+ public void testValidTreeWithGitmodulesUppercase()
+ throws CorruptObjectException {
+ ObjectId treeId = ObjectId
+ .fromString("0123012301230123012301230123012301230123");
+ StringBuilder b = new StringBuilder();
+ ObjectId blobId = entry(b, "100644 .GITMODULES");
+
+ byte[] data = encodeASCII(b.toString());
+ checker.setSafeForWindows(true);
+ checker.checkTree(treeId, data);
+ assertEquals(1, checker.getGitsubmodules().size());
+ assertEquals(treeId, checker.getGitsubmodules().get(0).getTreeId());
+ assertEquals(blobId, checker.getGitsubmodules().get(0).getBlobId());
+ }
+
+ @Test
+ public void testTreeWithInvalidGitmodules() throws CorruptObjectException {
+ ObjectId treeId = ObjectId
+ .fromString("0123012301230123012301230123012301230123");
+ StringBuilder b = new StringBuilder();
+ entry(b, "100644 .gitmodulez");
+
+ byte[] data = encodeASCII(b.toString());
+ checker.checkTree(treeId, data);
+ checker.setSafeForWindows(true);
+ assertEquals(0, checker.getGitsubmodules().size());
+ }
+
+ @Test
public void testNullSha1InTreeEntry() throws CorruptObjectException {
byte[] data = concat(
encodeASCII("100644 A"), new byte[] { '\0' },
@@ -1607,11 +1713,20 @@ public class ObjectCheckerTest {
checker.checkTree(encodeASCII(b.toString()));
}
- private static void entry(StringBuilder b, String modeName) {
+ /*
+ * Returns the id generated for the entry
+ */
+ private static ObjectId entry(StringBuilder b, String modeName) {
+ byte[] id = new byte[OBJECT_ID_LENGTH];
+
b.append(modeName);
b.append('\0');
- for (int i = 0; i < OBJECT_ID_LENGTH; i++)
+ for (int i = 0; i < OBJECT_ID_LENGTH; i++) {
b.append((char) i);
+ id[i] = (byte) i;
+ }
+
+ return ObjectId.fromRaw(id);
}
private void assertCorrupt(String msg, int type, StringBuilder b) {