diff options
author | Shawn Pearce <spearce@spearce.org> | 2015-04-29 21:56:28 -0700 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2015-04-30 10:27:03 -0400 |
commit | 4feffb3bf58d9a42be13624ef8ecb1775a40eb8d (patch) | |
tree | 00d5452b15968618cee7ea9f85ef14d1189a8ce3 /org.eclipse.jgit.test/tst | |
parent | 65423ea1b1e4e396ad5cd68b500b8d5a450713f4 (diff) | |
download | jgit-4feffb3bf58d9a42be13624ef8ecb1775a40eb8d.tar.gz jgit-4feffb3bf58d9a42be13624ef8ecb1775a40eb8d.zip |
Add fsck.allowInvalidPersonIdent to accept invalid author/committers
A larger than expected number of real-world repositories found on
the Internet contain invalid author, committer and tagger lines
in their history. Many of these seem to be caused by users misusing
the user.name and user.email fields, e.g.:
[user]
name = Au Thor <author@example.com>
email = author@example.com
that some version of Git (or a reimplementation thereof) copied
directly into the object header. These headers are not valid and
are rejected by a strict fsck, making it impossible to transfer
the repository with JGit/EGit.
Another form is an invalid committer line with double negative for
the time zone, e.g.
committer Au Thor <a@b> 1288373970 --700
The real world is messy. :(
Allow callers and users to weaken the fsck settings to accept these
sorts of breakages if they really want to work on a repo that has
broken history. Most routines will still function fine, however
commit timestamp sorting in RevWalk may become confused by a corrupt
committer line and sort commits out of order. This is mostly fine if
the corrupted chain is shorter than the slop window.
Change-Id: I6d529542c765c131de590f4f7ef8e7c1c8cb9db9
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java | 41 |
1 files changed, 40 insertions, 1 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 c6578ccfae..274757d95d 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 @@ -121,6 +121,42 @@ public class ObjectCheckerTest { } @Test + public void testCommitCorruptAuthor() throws CorruptObjectException { + StringBuilder b = new StringBuilder(); + b.append("tree be9bfa841874ccc9f2ef7c48d0c76226f89b7189\n"); + b.append("author b <b@c> <b@c> 0 +0000\n"); + b.append("committer <> 0 +0000\n"); + + byte[] data = Constants.encodeASCII(b.toString()); + try { + checker.checkCommit(data); + fail("Did not catch corrupt object"); + } catch (CorruptObjectException e) { + assertEquals("invalid author", e.getMessage()); + } + checker.setAllowInvalidPersonIdent(true); + checker.checkCommit(data); + } + + @Test + public void testCommitCorruptCommitter() throws CorruptObjectException { + StringBuilder b = new StringBuilder(); + b.append("tree be9bfa841874ccc9f2ef7c48d0c76226f89b7189\n"); + b.append("author <> 0 +0000\n"); + b.append("committer b <b@c> <b@c> 0 +0000\n"); + + byte[] data = Constants.encodeASCII(b.toString()); + try { + checker.checkCommit(data); + fail("Did not catch corrupt object"); + } catch (CorruptObjectException e) { + assertEquals("invalid committer", e.getMessage()); + } + checker.setAllowInvalidPersonIdent(true); + checker.checkCommit(data); + } + + @Test public void testValidCommit1Parent() throws CorruptObjectException { final StringBuilder b = new StringBuilder(); @@ -940,7 +976,8 @@ public class ObjectCheckerTest { } @Test - public void testInvalidTagInvalidTaggerHeader1() { + public void testInvalidTagInvalidTaggerHeader1() + throws CorruptObjectException { final StringBuilder b = new StringBuilder(); b.append("object "); @@ -958,6 +995,8 @@ public class ObjectCheckerTest { } catch (CorruptObjectException e) { assertEquals("invalid tagger", e.getMessage()); } + checker.setAllowInvalidPersonIdent(true); + checker.checkTag(data); } @Test |