diff options
author | Shawn Pearce <spearce@spearce.org> | 2015-12-29 18:21:19 -0800 |
---|---|---|
committer | Shawn Pearce <spearce@spearce.org> | 2015-12-30 15:19:09 -0800 |
commit | ac41920a430941b9385889d19e0fc2764ba23474 (patch) | |
tree | 638a92eae172cd3ed36c256160b7e39a409ece35 /org.eclipse.jgit.test | |
parent | fa7ce0e0f3a8973667b0d51966fc9bcb4fdbe505 (diff) | |
download | jgit-ac41920a430941b9385889d19e0fc2764ba23474.tar.gz jgit-ac41920a430941b9385889d19e0fc2764ba23474.zip |
ObjectChecker: honor some git-core fsck.* options
Accept some of the same section keys that fsck does in git-core,
allowing repositories to skip over specific kinds of acceptable
broken objects, e.g.:
[fsck]
duplicateEntries = ignore
zeroPaddedFilemode = ignore
The zeroPaddedFilemode = ignore is a synonym for the JGit specific
allowLeadingZeroFileMode = true. Only accept the JGit key if git-core
key was not specified.
Change-Id: Idaed9310e2a5ce5511670ead1aaea2b30aac903c
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java | 148 |
1 files changed, 121 insertions, 27 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 9519303095..80230dccfa 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 @@ -53,7 +53,17 @@ import static org.eclipse.jgit.lib.Constants.OBJ_TAG; import static org.eclipse.jgit.lib.Constants.OBJ_TREE; import static org.eclipse.jgit.lib.Constants.encode; import static org.eclipse.jgit.lib.Constants.encodeASCII; +import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.DUPLICATE_ENTRIES; +import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.EMPTY_NAME; +import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.FULL_PATHNAME; +import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.HAS_DOT; +import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.HAS_DOTDOT; +import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.HAS_DOTGIT; +import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.NULL_SHA1; +import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.TREE_NOT_SORTED; +import static org.eclipse.jgit.lib.ObjectChecker.ErrorType.ZERO_PADDED_FILEMODE; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; import java.io.UnsupportedEncodingException; @@ -130,7 +140,7 @@ public class ObjectCheckerTest { b.append("committer <> 0 +0000\n"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid author", OBJ_COMMIT, data); + assertCorrupt("bad date", OBJ_COMMIT, data); checker.setAllowInvalidPersonIdent(true); checker.checkCommit(data); @@ -146,7 +156,7 @@ public class ObjectCheckerTest { b.append("committer b <b@c> <b@c> 0 +0000\n"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid committer", OBJ_COMMIT, data); + assertCorrupt("bad date", OBJ_COMMIT, data); checker.setAllowInvalidPersonIdent(true); checker.checkCommit(data); @@ -300,7 +310,6 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid tree", OBJ_COMMIT, data); - assertSkipListRejects("invalid tree", OBJ_COMMIT, data); } @Test @@ -425,7 +434,7 @@ public class ObjectCheckerTest { b.append("author A. U. Thor <foo 1 +0000\n"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid author", OBJ_COMMIT, data); + assertCorrupt("bad email", OBJ_COMMIT, data); assertSkipListAccepts(OBJ_COMMIT, data); } @@ -439,7 +448,7 @@ public class ObjectCheckerTest { b.append("author A. U. Thor foo> 1 +0000\n"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid author", OBJ_COMMIT, data); + assertCorrupt("missing email", OBJ_COMMIT, data); assertSkipListAccepts(OBJ_COMMIT, data); } @@ -453,7 +462,7 @@ public class ObjectCheckerTest { b.append("author 1 +0000\n"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid author", OBJ_COMMIT, data); + assertCorrupt("missing email", OBJ_COMMIT, data); assertSkipListAccepts(OBJ_COMMIT, data); } @@ -467,7 +476,7 @@ public class ObjectCheckerTest { b.append("author a <b> +0000\n"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid author", OBJ_COMMIT, data); + assertCorrupt("bad date", OBJ_COMMIT, data); assertSkipListAccepts(OBJ_COMMIT, data); } @@ -481,7 +490,7 @@ public class ObjectCheckerTest { b.append("author a <b>\n"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid author", OBJ_COMMIT, data); + assertCorrupt("bad date", OBJ_COMMIT, data); assertSkipListAccepts(OBJ_COMMIT, data); } @@ -495,7 +504,7 @@ public class ObjectCheckerTest { b.append("author a <b> z"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid author", OBJ_COMMIT, data); + assertCorrupt("bad date", OBJ_COMMIT, data); assertSkipListAccepts(OBJ_COMMIT, data); } @@ -509,7 +518,7 @@ public class ObjectCheckerTest { b.append("author a <b> 1 z"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid author", OBJ_COMMIT, data); + assertCorrupt("bad time zone", OBJ_COMMIT, data); assertSkipListAccepts(OBJ_COMMIT, data); } @@ -524,7 +533,7 @@ public class ObjectCheckerTest { b.append("committer a <"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid committer", OBJ_COMMIT, data); + assertCorrupt("bad email", OBJ_COMMIT, data); assertSkipListAccepts(OBJ_COMMIT, data); } @@ -686,7 +695,7 @@ public class ObjectCheckerTest { b.append("tagger \n"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid tagger", OBJ_TAG, data); + assertCorrupt("missing email", OBJ_TAG, data); checker.setAllowInvalidPersonIdent(true); checker.checkTag(data); @@ -706,7 +715,7 @@ public class ObjectCheckerTest { b.append("tagger a < 1 +000\n"); byte[] data = encodeASCII(b.toString()); - assertCorrupt("invalid tagger", OBJ_TAG, data); + assertCorrupt("bad email", OBJ_TAG, data); assertSkipListAccepts(OBJ_TAG, data); } @@ -759,6 +768,17 @@ public class ObjectCheckerTest { } @Test + public void testNullSha1InTreeEntry() throws CorruptObjectException { + byte[] data = concat( + encodeASCII("100644 A"), new byte[] { '\0' }, + new byte[OBJECT_ID_LENGTH]); + assertCorrupt("entry points to null SHA-1", OBJ_TREE, data); + assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(NULL_SHA1, true); + checker.checkTree(data); + } + + @Test public void testValidPosixTree() throws CorruptObjectException { checkOneName("a<b>c:d|e"); checkOneName("test "); @@ -842,6 +862,9 @@ public class ObjectCheckerTest { checker.setAllowLeadingZeroFileMode(false); assertSkipListAccepts(OBJ_TREE, data); + + checker.setIgnore(ZERO_PADDED_FILEMODE, true); + checker.checkTree(data); } @Test @@ -905,39 +928,48 @@ public class ObjectCheckerTest { } @Test - public void testInvalidTreeNameContainsSlash() { + public void testInvalidTreeNameContainsSlash() + throws CorruptObjectException { StringBuilder b = new StringBuilder(); entry(b, "100644 a/b"); byte[] data = encodeASCII(b.toString()); assertCorrupt("name contains '/'", OBJ_TREE, data); - assertSkipListRejects("name contains '/'", OBJ_TREE, data); + assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(FULL_PATHNAME, true); + checker.checkTree(data); } @Test - public void testInvalidTreeNameIsEmpty() { + public void testInvalidTreeNameIsEmpty() throws CorruptObjectException { StringBuilder b = new StringBuilder(); entry(b, "100644 "); byte[] data = encodeASCII(b.toString()); assertCorrupt("zero length name", OBJ_TREE, data); - assertSkipListRejects("zero length name", OBJ_TREE, data); + assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(EMPTY_NAME, true); + checker.checkTree(data); } @Test - public void testInvalidTreeNameIsDot() { + public void testInvalidTreeNameIsDot() throws CorruptObjectException { StringBuilder b = new StringBuilder(); entry(b, "100644 ."); byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid name '.'", OBJ_TREE, data); - assertSkipListRejects("invalid name '.'", OBJ_TREE, data); + assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOT, true); + checker.checkTree(data); } @Test - public void testInvalidTreeNameIsDotDot() { + public void testInvalidTreeNameIsDotDot() throws CorruptObjectException { StringBuilder b = new StringBuilder(); entry(b, "100644 .."); byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid name '..'", OBJ_TREE, data); - assertSkipListRejects("invalid name '..'", OBJ_TREE, data); + assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTDOT, true); + checker.checkTree(data); } @Test @@ -947,6 +979,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid name '.git'", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } @Test @@ -957,6 +991,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid name '.GiT'", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } @Test @@ -974,6 +1010,8 @@ public class ObjectCheckerTest { "invalid name '.gi\u200Ct' contains ignorable Unicode characters", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } @Test @@ -992,6 +1030,8 @@ public class ObjectCheckerTest { "invalid name '\u206B.git' contains ignorable Unicode characters", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } @Test @@ -1010,12 +1050,22 @@ public class ObjectCheckerTest { "invalid name '.git\uFEFF' contains ignorable Unicode characters", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } - private static byte[] concat(byte[] b1, byte[] b2) { - byte[] data = new byte[b1.length + b2.length]; - System.arraycopy(b1, 0, data, 0, b1.length); - System.arraycopy(b2, 0, data, b1.length, b2.length); + private static byte[] concat(byte[]... b) { + int n = 0; + for (byte[] a : b) { + n += a.length; + } + + byte[] data = new byte[n]; + n = 0; + for (byte[] a : b) { + System.arraycopy(a, 0, data, n, a.length); + n += a.length; + } return data; } @@ -1096,6 +1146,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid name '.git.'", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } @Test @@ -1114,6 +1166,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid name '.git '", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } @Test @@ -1160,6 +1214,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid name '.git. '", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } @Test @@ -1170,6 +1226,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid name '.git . '", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } @Test @@ -1179,6 +1237,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid name 'GIT~1'", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } @Test @@ -1188,6 +1248,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("invalid name 'GiT~1'", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(HAS_DOTGIT, true); + checker.checkTree(data); } @Test @@ -1222,8 +1284,22 @@ public class ObjectCheckerTest { entry(b, "100644 foobar"); entry(b, "100644 fooaaa"); byte[] data = encodeASCII(b.toString()); + assertCorrupt("incorrectly sorted", OBJ_TREE, data); + + ObjectId id = idFor(OBJ_TREE, data); + try { + checker.check(id, OBJ_TREE, data); + fail("Did not throw CorruptObjectException"); + } catch (CorruptObjectException e) { + assertSame(TREE_NOT_SORTED, e.getErrorType()); + assertEquals("treeNotSorted: object " + id.name() + + ": incorrectly sorted", e.getMessage()); + } + assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(TREE_NOT_SORTED, true); + checker.checkTree(data); } @Test @@ -1234,6 +1310,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("incorrectly sorted", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(TREE_NOT_SORTED, true); + checker.checkTree(data); } @Test @@ -1244,6 +1322,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("incorrectly sorted", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(TREE_NOT_SORTED, true); + checker.checkTree(data); } @Test @@ -1254,6 +1334,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("duplicate entry names", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(DUPLICATE_ENTRIES, true); + checker.checkTree(data); } @Test @@ -1264,6 +1346,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("duplicate entry names", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(DUPLICATE_ENTRIES, true); + checker.checkTree(data); } @Test @@ -1274,6 +1358,8 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("duplicate entry names", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(DUPLICATE_ENTRIES, true); + checker.checkTree(data); } @Test @@ -1288,30 +1374,36 @@ public class ObjectCheckerTest { byte[] data = encodeASCII(b.toString()); assertCorrupt("duplicate entry names", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(DUPLICATE_ENTRIES, true); + checker.checkTree(data); } @Test public void testInvalidTreeDuplicateNames5() throws UnsupportedEncodingException, CorruptObjectException { StringBuilder b = new StringBuilder(); - entry(b, "100644 a"); entry(b, "100644 A"); + entry(b, "100644 a"); byte[] data = b.toString().getBytes("UTF-8"); checker.setSafeForWindows(true); assertCorrupt("duplicate entry names", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(DUPLICATE_ENTRIES, true); + checker.checkTree(data); } @Test public void testInvalidTreeDuplicateNames6() throws UnsupportedEncodingException, CorruptObjectException { StringBuilder b = new StringBuilder(); - entry(b, "100644 a"); entry(b, "100644 A"); + entry(b, "100644 a"); byte[] data = b.toString().getBytes("UTF-8"); checker.setSafeForMacOS(true); assertCorrupt("duplicate entry names", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(DUPLICATE_ENTRIES, true); + checker.checkTree(data); } @Test @@ -1324,6 +1416,8 @@ public class ObjectCheckerTest { checker.setSafeForMacOS(true); assertCorrupt("duplicate entry names", OBJ_TREE, data); assertSkipListAccepts(OBJ_TREE, data); + checker.setIgnore(DUPLICATE_ENTRIES, true); + checker.checkTree(data); } @Test |