/// <summary> /// Copy a /// <see cref="PersonIdent">PersonIdent</see> /// , but alter the clone's time stamp /// </summary> /// <param name="pi"> /// original /// <see cref="PersonIdent">PersonIdent</see> /// </param> /// <param name="aWhen">local time</param> public PersonIdent(NGit.PersonIdent pi, DateTime aWhen) { name = pi.GetName(); emailAddress = pi.GetEmailAddress(); when = aWhen.GetTime(); tzOffset = pi.tzOffset; }
/// <summary>Copy a PersonIdent, but alter the clone's time stamp</summary> /// <param name="pi"> /// original /// <see cref="PersonIdent">PersonIdent</see> /// </param> /// <param name="aWhen">local time stamp</param> /// <param name="aTZ">time zone</param> public PersonIdent(NGit.PersonIdent pi, long aWhen, int aTZ) { name = pi.GetName(); emailAddress = pi.GetEmailAddress(); when = aWhen; tzOffset = aTZ; }
public virtual void Test002_NewIdent() { PersonIdent p = new PersonIdent("A U Thor", "*****@*****.**", Sharpen.Extensions.CreateDate (1142878501000L), Sharpen.Extensions.GetTimeZone("GMT+0230")); NUnit.Framework.Assert.AreEqual("A U Thor", p.GetName()); NUnit.Framework.Assert.AreEqual("*****@*****.**", p.GetEmailAddress()); NUnit.Framework.Assert.AreEqual(1142878501000L, p.GetWhen().GetTime()); NUnit.Framework.Assert.AreEqual("A U Thor <*****@*****.**> 1142878501 +0230", p.ToExternalString()); }
public override bool Equals(object o) { if (o is NGit.PersonIdent) { NGit.PersonIdent p = (NGit.PersonIdent)o; return(GetName().Equals(p.GetName()) && GetEmailAddress().Equals(p.GetEmailAddress ()) && when / 1000L == p.when / 1000L); } return(false); }
public virtual void Test001_NewIdent() { var timeZoneId = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Eastern Standard Time" : "EST"; PersonIdent p = new PersonIdent("A U Thor", "*****@*****.**", Sharpen.Extensions.CreateDate (1142878501000L), Sharpen.Extensions.GetTimeZone(timeZoneId)); NUnit.Framework.Assert.AreEqual("A U Thor", p.GetName()); NUnit.Framework.Assert.AreEqual("*****@*****.**", p.GetEmailAddress()); NUnit.Framework.Assert.AreEqual(1142878501000L, p.GetWhen().GetTime()); NUnit.Framework.Assert.AreEqual("A U Thor <*****@*****.**> 1142878501 -0500", p.ToExternalString()); }
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 ()); }
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(); }
private static Person ToPerson(PersonIdent ident) { return new Person(ident.GetName(), ident.GetEmailAddress()); }
/// <summary> /// Copy a /// <see cref="PersonIdent">PersonIdent</see> /// . /// </summary> /// <param name="pi"> /// Original /// <see cref="PersonIdent">PersonIdent</see> /// </param> public PersonIdent(NGit.PersonIdent pi) : this(pi.GetName(), pi.GetEmailAddress() ) { }
/// <summary>Copy a PersonIdent, but alter the clone's time stamp</summary> /// <param name="pi"> /// original /// <see cref="PersonIdent">PersonIdent</see> /// </param> /// <param name="when">local time</param> /// <param name="tz">time zone</param> public PersonIdent(NGit.PersonIdent pi, DateTime when, TimeZoneInfo tz) : this(pi .GetName(), pi.GetEmailAddress(), when, tz) { }
/// <summary>Copy a PersonIdent, but alter the clone's time stamp</summary> /// <param name="pi"> /// original /// <see cref="PersonIdent">PersonIdent</see> /// </param> /// <param name="aWhen">local time stamp</param> /// <param name="aTZ">time zone</param> public PersonIdent(NGit.PersonIdent pi, long aWhen, int aTZ) : this(pi.GetName(), pi.GetEmailAddress(), aWhen, aTZ) { }
/// <summary> /// Copy a /// <see cref="PersonIdent">PersonIdent</see> /// , but alter the clone's time stamp /// </summary> /// <param name="pi"> /// original /// <see cref="PersonIdent">PersonIdent</see> /// </param> /// <param name="aWhen">local time</param> public PersonIdent(NGit.PersonIdent pi, DateTime aWhen) : this(pi.GetName(), pi.GetEmailAddress (), aWhen.GetTime(), pi.tzOffset) { }
public override void Commit (ChangeSet changeSet, IProgressMonitor monitor) { PersonIdent author = new PersonIdent (repo); PersonIdent committer = new PersonIdent (repo); string message = changeSet.GlobalComment; if (string.IsNullOrEmpty (message)) throw new ArgumentException ("Commit message must not be null or empty!", "message"); if (string.IsNullOrEmpty (author.GetName ())) throw new ArgumentException ("Author name must not be null or empty!", "author"); RepositoryState state = repo.GetRepositoryState (); if (!state.CanCommit ()) { throw new WrongRepositoryStateException ("Cannot commit with repository in state: " + state); } try { Ref head = repo.GetRef (Constants.HEAD); if (head == null) throw new InvalidOperationException ("No HEAD"); List<ObjectId> parents = new List<ObjectId>(); // determine the current HEAD and the commit it is referring to ObjectId headId = repo.Resolve (Constants.HEAD + "^{commit}"); if (headId != null) parents.Insert (0, headId); ObjectInserter odi = repo.NewObjectInserter (); try { List<string> filePaths = GetFilesInPaths (changeSet.Items.Select (i => i.LocalPath)); ObjectId indexTreeId = CreateCommitTree (filePaths); ObjectId commitId = GitUtil.CreateCommit (repo, message, parents, indexTreeId, author, committer); RevWalk revWalk = new RevWalk (repo); try { RevCommit revCommit = revWalk.ParseCommit (commitId); RefUpdate ru = repo.UpdateRef (Constants.HEAD); ru.SetNewObjectId (commitId); ru.SetRefLogMessage ("commit : " + revCommit.GetShortMessage (), false); ru.SetExpectedOldObjectId (headId); RefUpdate.Result rc = ru.Update (); switch (rc) { case RefUpdate.Result.NEW: case RefUpdate.Result.FAST_FORWARD: { Unstage (filePaths); if (state == RepositoryState.MERGING_RESOLVED) { // Commit was successful. Now delete the files // used for merge commits repo.WriteMergeCommitMsg (null); repo.WriteMergeHeads (null); } return; } case RefUpdate.Result.REJECTED: case RefUpdate.Result.LOCK_FAILURE: throw new ConcurrentRefUpdateException (JGitText.Get ().couldNotLockHEAD, ru.GetRef (), rc); default: throw new JGitInternalException ("Reference update failed"); } } finally { revWalk.Release (); } } finally { odi.Release (); } } catch (UnmergedPathException) { // since UnmergedPathException is a subclass of IOException // which should not be wrapped by a JGitInternalException we // have to catch and re-throw it here throw; } catch (IOException e) { throw new JGitInternalException (JGitText.Get ().exceptionCaughtDuringExecutionOfCommitCommand, e); } }