internal Stash(string prevStashCommitId, string commitId, PersonIdent author, string comment) { this.PrevStashCommitId = prevStashCommitId; this.CommitId = commitId; this.Author = author; this.DateTime = DateTimeOffset.Now; // Skip "WIP on master: " int i = comment.IndexOf(':'); this.Comment = comment.Substring(i + 2); // Create the text line to be written in the stash log int secs = (int)(this.DateTime - new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero)).TotalSeconds; TimeSpan ofs = this.DateTime.Offset; string tz = string.Format("{0}{1:00}{2:00}", (ofs.Hours >= 0 ? '+':'-'), Math.Abs(ofs.Hours), Math.Abs(ofs.Minutes)); StringBuilder sb = new StringBuilder(); sb.Append(prevStashCommitId ?? new string ('0', 40)).Append(' '); sb.Append(commitId).Append(' '); sb.Append(author.GetName()).Append(" <").Append(author.GetEmailAddress()).Append("> "); sb.Append(secs).Append(' ').Append(tz).Append('\t'); sb.Append(comment); FullLine = sb.ToString(); }
public static string email(this PersonIdent personIdent) { if (personIdent.notNull()) { return(personIdent.GetEmailAddress()); } return(null); }
private static void PutPersonIdent(IDictionary <string, string> env, string type, PersonIdent who) { string ident = who.ToExternalString(); string date = Sharpen.Runtime.Substring(ident, ident.IndexOf("> ") + 2); env.Put("GIT_" + type + "_NAME", who.GetName()); env.Put("GIT_" + type + "_EMAIL", who.GetEmailAddress()); env.Put("GIT_" + type + "_DATE", date); }
private string ToString(PersonIdent author) { StringBuilder a = new StringBuilder(); a.Append("Author: "); a.Append(author.GetName()); a.Append(" <"); a.Append(author.GetEmailAddress()); a.Append(">\n"); a.Append("Date: "); a.Append(dateFormatter.FormatDate(author)); a.Append("\n"); return(a.ToString()); }
public virtual void TestAuthorScriptConverter() { // -1 h timezone offset PersonIdent ident = new PersonIdent("Author name", "*****@*****.**", 123456789123L , -60); string convertedAuthor = git.Rebase().ToAuthorScript(ident); string[] lines = convertedAuthor.Split("\n"); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_NAME='Author name'", lines[0]); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_EMAIL='*****@*****.**'", lines[1]); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_DATE='123456789 -0100'", lines[2]); PersonIdent parsedIdent = git.Rebase().ParseAuthor(Sharpen.Runtime.GetBytesForString (convertedAuthor, "UTF-8")); NUnit.Framework.Assert.AreEqual(ident.GetName(), parsedIdent.GetName()); NUnit.Framework.Assert.AreEqual(ident.GetEmailAddress(), parsedIdent.GetEmailAddress ()); // this is rounded to the last second NUnit.Framework.Assert.AreEqual(123456789000L, parsedIdent.GetWhen().GetTime()); NUnit.Framework.Assert.AreEqual(ident.GetTimeZoneOffset(), parsedIdent.GetTimeZoneOffset ()); // + 9.5h timezone offset ident = new PersonIdent("Author name", "*****@*****.**", 123456789123L, +570); convertedAuthor = git.Rebase().ToAuthorScript(ident); lines = convertedAuthor.Split("\n"); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_NAME='Author name'", lines[0]); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_EMAIL='*****@*****.**'", lines[1]); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_DATE='123456789 +0930'", lines[2]); parsedIdent = git.Rebase().ParseAuthor(Sharpen.Runtime.GetBytesForString(convertedAuthor , "UTF-8")); NUnit.Framework.Assert.AreEqual(ident.GetName(), parsedIdent.GetName()); NUnit.Framework.Assert.AreEqual(ident.GetEmailAddress(), parsedIdent.GetEmailAddress ()); NUnit.Framework.Assert.AreEqual(123456789000L, parsedIdent.GetWhen().GetTime()); NUnit.Framework.Assert.AreEqual(ident.GetTimeZoneOffset(), parsedIdent.GetTimeZoneOffset ()); }
public virtual void CommitAmendWithAuthorShouldUseIt() { Git git = new Git(db); WriteTrashFile("file1", "file1"); git.Add().AddFilepattern("file1").Call(); git.Commit().SetMessage("initial commit").Call(); RevCommit amended = git.Commit().SetAmend(true).SetAuthor("New Author", "*****@*****.**" ).SetMessage("amend commit").Call(); PersonIdent amendedAuthor = amended.GetAuthorIdent(); NUnit.Framework.Assert.AreEqual("New Author", amendedAuthor.GetName()); NUnit.Framework.Assert.AreEqual("*****@*****.**", amendedAuthor.GetEmailAddress ()); }
public virtual void TestParseAllFields() { ObjectId treeId = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67"); string name = "v1.2.3.4.5"; string taggerName = "A U. Thor"; string taggerEmail = "*****@*****.**"; int taggerTime = 1218123387; StringBuilder body = new StringBuilder(); body.Append("object "); body.Append(treeId.Name); body.Append("\n"); body.Append("type tree\n"); body.Append("tag "); body.Append(name); body.Append("\n"); body.Append("tagger "); body.Append(taggerName); body.Append(" <"); body.Append(taggerEmail); body.Append("> "); body.Append(taggerTime); body.Append(" +0700\n"); body.Append("\n"); RevWalk rw = new RevWalk(db); RevTag c; c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); NUnit.Framework.Assert.IsNull(c.GetObject()); NUnit.Framework.Assert.IsNull(c.GetTagName()); c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8")); NUnit.Framework.Assert.IsNotNull(c.GetObject()); NUnit.Framework.Assert.AreEqual(treeId, c.GetObject().Id); NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.GetObject()); NUnit.Framework.Assert.IsNotNull(c.GetTagName()); NUnit.Framework.Assert.AreEqual(name, c.GetTagName()); NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage()); PersonIdent cTagger = c.GetTaggerIdent(); NUnit.Framework.Assert.IsNotNull(cTagger); NUnit.Framework.Assert.AreEqual(taggerName, cTagger.GetName()); NUnit.Framework.Assert.AreEqual(taggerEmail, cTagger.GetEmailAddress()); }
public virtual void CommitAmendWithoutAuthorShouldSetOriginalAuthorAndAuthorTime( ) { Git git = new Git(db); WriteTrashFile("file1", "file1"); git.Add().AddFilepattern("file1").Call(); string authorName = "First Author"; string authorEmail = "*****@*****.**"; DateTime authorDate = Sharpen.Extensions.CreateDate(1349621117000L); PersonIdent firstAuthor = new PersonIdent(authorName, authorEmail, authorDate, Sharpen.Extensions.GetTimeZone ("UTC")); git.Commit().SetMessage("initial commit").SetAuthor(firstAuthor).Call(); RevCommit amended = git.Commit().SetAmend(true).SetMessage("amend commit").Call(); PersonIdent amendedAuthor = amended.GetAuthorIdent(); NUnit.Framework.Assert.AreEqual(authorName, amendedAuthor.GetName()); NUnit.Framework.Assert.AreEqual(authorEmail, amendedAuthor.GetEmailAddress()); NUnit.Framework.Assert.AreEqual(authorDate.GetTime(), amendedAuthor.GetWhen().GetTime ()); }
internal virtual string ToAuthorScript(PersonIdent author) { StringBuilder sb = new StringBuilder(100); sb.Append(GIT_AUTHOR_NAME); sb.Append("='"); sb.Append(author.GetName()); sb.Append("'\n"); sb.Append(GIT_AUTHOR_EMAIL); sb.Append("='"); sb.Append(author.GetEmailAddress()); sb.Append("'\n"); // the command line uses the "external String" // representation for date and timezone sb.Append(GIT_AUTHOR_DATE); sb.Append("='"); string externalString = author.ToExternalString(); sb.Append(Sharpen.Runtime.Substring(externalString, externalString.LastIndexOf('>' ) + 2)); sb.Append("'\n"); return(sb.ToString()); }
private static Person ToPerson(PersonIdent ident) { return(new Person(ident.GetName(), ident.GetEmailAddress())); }
public virtual void TestParse_NoParents() { ObjectId treeId = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67"); string authorName = "A U. Thor"; string authorEmail = "*****@*****.**"; int authorTime = 1218123387; string authorTimeZone = "+0700"; string committerName = "C O. Miter"; string committerEmail = "*****@*****.**"; int committerTime = 1218123390; string committerTimeZone = "-0500"; StringBuilder 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(" "); body.Append(authorTimeZone); body.Append(" \n"); body.Append("committer "); body.Append(committerName); body.Append(" <"); body.Append(committerEmail); body.Append("> "); body.Append(committerTime); body.Append(" "); body.Append(committerTimeZone); body.Append("\n"); body.Append("\n"); RevWalk rw = new RevWalk(db); RevCommit c; c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); NUnit.Framework.Assert.IsNull(c.Tree); NUnit.Framework.Assert.IsNull(c.parents); c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8")); NUnit.Framework.Assert.IsNotNull(c.Tree); NUnit.Framework.Assert.AreEqual(treeId, c.Tree.Id); NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.Tree); NUnit.Framework.Assert.IsNotNull(c.parents); NUnit.Framework.Assert.AreEqual(0, c.parents.Length); NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage()); PersonIdent cAuthor = c.GetAuthorIdent(); NUnit.Framework.Assert.IsNotNull(cAuthor); NUnit.Framework.Assert.AreEqual(authorName, cAuthor.GetName()); NUnit.Framework.Assert.AreEqual(authorEmail, cAuthor.GetEmailAddress()); NUnit.Framework.Assert.AreEqual((long)authorTime * 1000, cAuthor.GetWhen().GetTime ()); NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + authorTimeZone ).BaseUtcOffset, cAuthor.GetTimeZone().BaseUtcOffset); PersonIdent cCommitter = c.GetCommitterIdent(); NUnit.Framework.Assert.IsNotNull(cCommitter); NUnit.Framework.Assert.AreEqual(committerName, cCommitter.GetName()); NUnit.Framework.Assert.AreEqual(committerEmail, cCommitter.GetEmailAddress()); NUnit.Framework.Assert.AreEqual((long)committerTime * 1000, cCommitter.GetWhen(). GetTime()); NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + committerTimeZone ).BaseUtcOffset, cCommitter.GetTimeZone().BaseUtcOffset); }