private RevCommit Parse(string msg) { var buf = new StringBuilder(); buf.Append("tree " + ObjectId.ZeroId.Name + "\n"); buf.Append("author A. U. Thor <*****@*****.**> 1 +0000\n"); buf.Append("committer A. U. Thor <*****@*****.**> 1 +0000\n"); buf.Append("\n"); buf.Append(msg); var walk = new GitSharp.RevWalk.RevWalk(db); walk.setRetainBody(true); var c = new RevCommit(ObjectId.ZeroId); c.parseCanonical(walk, Constants.encode(buf.ToString())); return c; }
public void testParse_explicit_bad_encoded() { RevCommit c; using (var b = new BinaryWriter(new MemoryStream())) { b.Write(_utf8Enc.GetBytes("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n")); b.Write(_isoEnc.GetBytes("author F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n")); b.Write(_utf8Enc.GetBytes("committer C O. Miter <*****@*****.**> 1218123390 -0500\n")); b.Write(_utf8Enc.GetBytes("encoding EUC-JP\n")); b.Write(_utf8Enc.GetBytes("\n")); b.Write(_utf8Enc.GetBytes("\u304d\u308c\u3044\n")); b.Write(_utf8Enc.GetBytes("\n")); b.Write(_utf8Enc.GetBytes("Hi\n")); c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new GitSharp.RevWalk.RevWalk(db), ((MemoryStream) b.BaseStream).ToArray()); } Assert.AreEqual("F\u00f6r fattare", c.getAuthorIdent().Name); Assert.AreEqual("\u304d\u308c\u3044", c.getShortMessage()); Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.getFullMessage()); }
public void testParse_WeirdHeaderOnlyCommit() { var b = new StringBuilder(); b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"); b.Append("author A U. Thor <*****@*****.**> 1218123387 +0700\n"); b.Append("committer C O. Miter <*****@*****.**> 1218123390 -0500\n"); var c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c.parseCanonical(new GitSharp.RevWalk.RevWalk(db), _utf8Enc.GetBytes(b.ToString())); Assert.AreEqual(string.Empty, c.getFullMessage()); Assert.AreEqual(string.Empty, c.getShortMessage()); }
private RevCommit create(string msg) { var b = new StringBuilder(); b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"); b.Append("author A U. Thor <*****@*****.**> 1218123387 +0700\n"); b.Append("committer C O. Miter <*****@*****.**> 1218123390 -0500\n"); b.Append("\n"); b.Append(msg); var c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c.parseCanonical(new GitSharp.RevWalk.RevWalk(db), _utf8Enc.GetBytes(b.ToString())); return c; }
public void testParse_NoParents() { ObjectId treeId = id("9788669ad918b6fcce64af8882fc9a81cb6aba67"); const string authorName = "A U. Thor"; const string authorEmail = "*****@*****.**"; const int authorTime = 1218123387; const string committerName = "C O. Miter"; const string committerEmail = "*****@*****.**"; const int committerTime = 1218123390; var body = new StringBuilder(); body.Append("tree "); body.Append(treeId.Name); body.Append("\n"); body.Append("author "); body.Append(authorName); body.Append(" <"); body.Append(authorEmail); body.Append("> "); body.Append(authorTime); body.Append(" +0700\n"); body.Append("committer "); body.Append(committerName); body.Append(" <"); body.Append(committerEmail); body.Append("> "); body.Append(committerTime); body.Append(" -0500\n"); body.Append("\n"); var rw = new GitSharp.RevWalk.RevWalk(db); var c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); Assert.IsNull(c.Tree); Assert.IsNull(c.Parents); c.parseCanonical(rw, _utf8Enc.GetBytes(body.ToString())); Assert.IsNotNull(c.Tree); Assert.AreEqual(treeId, c.Tree.getId()); Assert.AreSame(rw.lookupTree(treeId), c.Tree); Assert.IsNotNull(c.Parents); Assert.AreEqual(0, c.Parents.Length); Assert.AreEqual(string.Empty, c.getFullMessage()); PersonIdent cAuthor = c.getAuthorIdent(); Assert.IsNotNull(cAuthor); Assert.AreEqual(authorName, cAuthor.Name); Assert.AreEqual(authorEmail, cAuthor.EmailAddress); PersonIdent cCommitter = c.getCommitterIdent(); Assert.IsNotNull(cCommitter); Assert.AreEqual(committerName, cCommitter.Name); Assert.AreEqual(committerEmail, cCommitter.EmailAddress); }