Exemplo n.º 1
0
 /// <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;
 }
Exemplo n.º 2
0
		public virtual void SetUp()
		{
			mockSystemReader = new _MockSystemReader_62();
			SystemReader.SetInstance(mockSystemReader);
			ident = RawParseUtils.ParsePersonIdent("A U Thor <*****@*****.**> 1316560165 -0400"
				);
		}
Exemplo n.º 3
0
 /// <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;
 }
Exemplo n.º 4
0
		public virtual void TestSomeCommits()
		{
			// do 4 commits
			Git git = new Git(db);
			git.Commit().SetMessage("initial commit").Call();
			git.Commit().SetMessage("second commit").SetCommitter(committer).Call();
			git.Commit().SetMessage("third commit").SetAuthor(author).Call();
			git.Commit().SetMessage("fourth commit").SetAuthor(author).SetCommitter(committer
				).Call();
			Iterable<RevCommit> commits = git.Log().Call();
			// check that all commits came in correctly
			PersonIdent defaultCommitter = new PersonIdent(db);
			PersonIdent[] expectedAuthors = new PersonIdent[] { defaultCommitter, committer, 
				author, author };
			PersonIdent[] expectedCommitters = new PersonIdent[] { defaultCommitter, committer
				, defaultCommitter, committer };
			string[] expectedMessages = new string[] { "initial commit", "second commit", "third commit"
				, "fourth commit" };
			int l = expectedAuthors.Length - 1;
			foreach (RevCommit c in commits)
			{
				NUnit.Framework.Assert.AreEqual(expectedAuthors[l].GetName(), c.GetAuthorIdent().
					GetName());
				NUnit.Framework.Assert.AreEqual(expectedCommitters[l].GetName(), c.GetCommitterIdent
					().GetName());
				NUnit.Framework.Assert.AreEqual(c.GetFullMessage(), expectedMessages[l]);
				l--;
			}
			NUnit.Framework.Assert.AreEqual(l, -1);
			ReflogReader reader = db.GetReflogReader(Constants.HEAD);
			NUnit.Framework.Assert.IsTrue(reader.GetLastEntry().GetComment().StartsWith("commit:"
				));
		}
Exemplo n.º 5
0
			internal Entry(byte[] raw, int pos)
			{
				oldId = ObjectId.FromString(raw, pos);
				pos += Constants.OBJECT_ID_STRING_LENGTH;
				if (raw[pos++] != ' ')
				{
					throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
				}
				newId = ObjectId.FromString(raw, pos);
				pos += Constants.OBJECT_ID_STRING_LENGTH;
				if (raw[pos++] != ' ')
				{
					throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
				}
				who = RawParseUtils.ParsePersonIdentOnly(raw, pos);
				int p0 = RawParseUtils.Next(raw, pos, '\t');
				if (p0 >= raw.Length)
				{
					comment = string.Empty;
				}
				else
				{
					// personident has no \t, no comment present
					int p1 = RawParseUtils.NextLF(raw, p0);
					comment = p1 > p0 ? RawParseUtils.Decode(raw, p0, p1 - 1) : string.Empty;
				}
			}
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
		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());
		}
Exemplo n.º 8
0
        public static RevCommit commit(this API_NGit nGit, string commitMessage, PersonIdent author, PersonIdent committer)
        {
            if (commitMessage.valid())
            {
                "[API_NGit] commit: {0}".debug(commitMessage);
                var commit_Command = nGit.Git.Commit();
                commit_Command.SetMessage  (commitMessage);
                commit_Command.SetAuthor   (author);
                commit_Command.SetCommitter(committer);
                return commit_Command.Call();
            }

            "[API_NGit] commit was called with no commitMessage".error();
            return null;
        }
Exemplo n.º 9
0
		public static ObjectId CreateCommit (NGit.Repository rep, string message, IList<ObjectId> parents, ObjectId indexTreeId, PersonIdent author, PersonIdent committer)
		{
			try {
				ObjectInserter odi = rep.NewObjectInserter ();
				try {
					// Create a Commit object, populate it and write it
					NGit.CommitBuilder commit = new NGit.CommitBuilder ();
					commit.Committer = committer;
					commit.Author = author;
					commit.Message = message;
					commit.SetParentIds (parents);
					commit.TreeId = indexTreeId;
					ObjectId commitId = odi.Insert (commit);
					odi.Flush ();
					return commitId;
				} 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 ("Commit failed", e);
			}
		}
Exemplo n.º 10
0
 public virtual void RefLogIncludesCommitMessage()
 {
     PersonIdent who = new PersonIdent("user", "*****@*****.**");
     DeleteTrashFile("file.txt");
     RevCommit stashed = git.StashCreate().SetPerson(who).Call();
     NUnit.Framework.Assert.IsNotNull(stashed);
     NUnit.Framework.Assert.AreEqual("content", Read(committedFile));
     ValidateStashedCommit(stashed);
     ReflogReader reader = new ReflogReader(git.GetRepository(), Constants.R_STASH);
     ReflogEntry entry = reader.GetLastEntry();
     NUnit.Framework.Assert.IsNotNull(entry);
     NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entry.GetOldId());
     NUnit.Framework.Assert.AreEqual(stashed, entry.GetNewId());
     NUnit.Framework.Assert.AreEqual(who, entry.GetWho());
     NUnit.Framework.Assert.AreEqual(stashed.GetFullMessage(), entry.GetComment());
 }
Exemplo n.º 11
0
		/// <summary>Write the given ref update to the ref's log</summary>
		/// <param name="update"></param>
		/// <param name="msg"></param>
		/// <param name="deref"></param>
		/// <returns>this writer</returns>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual NGit.Storage.File.ReflogWriter Log(RefUpdate update, string msg, bool
			 deref)
		{
			ObjectId oldId = update.GetOldObjectId();
			ObjectId newId = update.GetNewObjectId();
			Ref @ref = update.GetRef();
			PersonIdent ident = update.GetRefLogIdent();
			if (ident == null)
			{
				ident = new PersonIdent(parent);
			}
			else
			{
				ident = new PersonIdent(ident);
			}
			byte[] rec = Encode(oldId, newId, ident, msg);
			if (deref && @ref.IsSymbolic())
			{
				Log(@ref.GetName(), rec);
				Log(@ref.GetLeaf().GetName(), rec);
			}
			else
			{
				Log(@ref.GetName(), rec);
			}
			return this;
		}
Exemplo n.º 12
0
		/// <summary>Set the identity of the user appearing in the reflog.</summary>
		/// <remarks>
		/// Set the identity of the user appearing in the reflog.
		/// <p>
		/// The timestamp portion of the identity is ignored. A new identity with the
		/// current timestamp will be created automatically when the update occurs
		/// and the log record is written.
		/// </remarks>
		/// <param name="pi">
		/// identity of the user. If null the identity will be
		/// automatically determined based on the repository
		/// configuration.
		/// </param>
		/// <returns>
		/// 
		/// <code>this</code>
		/// .
		/// </returns>
		public virtual NGit.BatchRefUpdate SetRefLogIdent(PersonIdent pi)
		{
			refLogIdent = pi;
			return this;
		}
Exemplo n.º 13
0
 private static Person ToPerson(PersonIdent ident)
 {
     return new Person(ident.GetName(), ident.GetEmailAddress());
 }
Exemplo n.º 14
0
		/// <summary>Set the identity of the user appearing in the reflog.</summary>
		/// <remarks>
		/// Set the identity of the user appearing in the reflog.
		/// <p>
		/// The timestamp portion of the identity is ignored. A new identity with the
		/// current timestamp will be created automatically when the update occurs
		/// and the log record is written.
		/// </remarks>
		/// <param name="pi">
		/// identity of the user. If null the identity will be
		/// automatically determined based on the repository
		/// configuration.
		/// </param>
		public virtual void SetRefLogIdent(PersonIdent pi)
		{
			refLogIdent = pi;
		}
Exemplo n.º 15
0
 /// <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)
 {
 }
Exemplo n.º 16
0
 /// <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()
                                                )
 {
 }
Exemplo n.º 17
0
 /// <summary>Set the identity of the user appearing in the reflog.</summary>
 /// <remarks>
 /// Set the identity of the user appearing in the reflog.
 /// <p>
 /// The timestamp portion of the identity is ignored. A new identity with the
 /// current timestamp will be created automatically when the update occurs
 /// and the log record is written.
 /// </remarks>
 /// <param name="pi">
 /// identity of the user. If null the identity will be
 /// automatically determined based on the repository
 /// configuration.
 /// </param>
 /// <returns>
 ///
 /// <code>this</code>
 /// .
 /// </returns>
 public virtual NGit.BatchRefUpdate SetRefLogIdent(PersonIdent pi)
 {
     refLogIdent = pi;
     return(this);
 }
Exemplo n.º 18
0
		/// <exception cref="System.IO.IOException"></exception>
		private void Commit(string commitMsg, PersonIdent author, PersonIdent committer)
		{
			NGit.CommitBuilder commit = new NGit.CommitBuilder();
			commit.Author = author;
			commit.Committer = committer;
			commit.Message = commitMsg;
			ObjectInserter inserter = db.NewObjectInserter();
			ObjectId id;
			try
			{
				commit.TreeId = inserter.Insert(new TreeFormatter());
				id = inserter.Insert(commit);
				inserter.Flush();
			}
			finally
			{
				inserter.Release();
			}
			int nl = commitMsg.IndexOf('\n');
			RefUpdate ru = db.UpdateRef(Constants.HEAD);
			ru.SetNewObjectId(id);
			ru.SetRefLogMessage("commit : " + ((nl == -1) ? commitMsg : Sharpen.Runtime.Substring
				(commitMsg, 0, nl)), false);
			ru.ForceUpdate();
		}
Exemplo n.º 19
0
        //
        //
        //
        //
        //
        //
        /// <summary>Compute a Change-Id.</summary>
        /// <remarks>Compute a Change-Id.</remarks>
        /// <param name="treeId">The id of the tree that would be committed</param>
        /// <param name="firstParentId">parent id of previous commit or null</param>
        /// <param name="author">
        /// the
        /// <see cref="NGit.PersonIdent">NGit.PersonIdent</see>
        /// for the presumed author and time
        /// </param>
        /// <param name="committer">
        /// the
        /// <see cref="NGit.PersonIdent">NGit.PersonIdent</see>
        /// for the presumed committer and time
        /// </param>
        /// <param name="message">The commit message</param>
        /// <returns>
        /// the change id SHA1 string (without the 'I') or null if the
        /// message is not complete enough
        /// </returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public static ObjectId ComputeChangeId(ObjectId treeId, ObjectId firstParentId, PersonIdent
			 author, PersonIdent committer, string message)
        {
            string cleanMessage = Clean(message);
            if (cleanMessage.Length == 0)
            {
                return null;
            }
            StringBuilder b = new StringBuilder();
            b.Append("tree ");
            b.Append(ObjectId.ToString(treeId));
            b.Append("\n");
            if (firstParentId != null)
            {
                b.Append("parent ");
                b.Append(ObjectId.ToString(firstParentId));
                b.Append("\n");
            }
            b.Append("author ");
            b.Append(author.ToExternalString());
            b.Append("\n");
            b.Append("committer ");
            b.Append(committer.ToExternalString());
            b.Append("\n\n");
            b.Append(cleanMessage);
            return new ObjectInserter.Formatter().IdFor(Constants.OBJ_COMMIT, Sharpen.Runtime.GetBytesForString
                (b.ToString(), Constants.CHARACTER_ENCODING));
        }
Exemplo n.º 20
0
        private void Commit_Button(object sender, System.Windows.RoutedEventArgs e)
        {
            var author = new PersonIdent("Michael", "*****@*****.**");
            string message = FolderPathTextBox1.Text;

            if (terminalMode)
            {
                //openActivePath();
                autoIt.WinActivate("cmd.exe");
                autoIt.Send("git commit -m \"" + activeRepoPath + "\"" + "\r");
                autoIt.WinActivate("MainWindow");
            }
            else
            {
                var commit = repository.Commit()
                    .SetMessage(message)
                    .SetAuthor(author)
                    .SetAll(true) // This automatically stages modified and deleted files
                    .Call();

                // Our new commit's hash
                var hash = commit.Id;
                //using (var repo = new Repository(activeRepoPath))
                //{

                // Create the committer's signature and commit
                //Signature author = new Signature("Default User", "*****@*****.**", DateTime.Now);
                //Signature committer = author;

                // Commit to the repository
                //Commit commit = repo.Commit(message, author, committer);
                //}
            }
            Go_To_RepositoryMainGrid(sender, e);
        }
Exemplo n.º 21
0
		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
				());
		}
Exemplo n.º 22
0
		//
		//
		//
		/// <summary>
		/// Increment the
		/// <see cref="author">author</see>
		/// and
		/// <see cref="committer">committer</see>
		/// times.
		/// </summary>
		protected internal virtual void Tick()
		{
			long delta = TimeUnit.MILLISECONDS.Convert(5 * 60, TimeUnit.SECONDS);
			long now = author.GetWhen().GetTime() + delta;
			author = new PersonIdent(author, now, tz);
			committer = new PersonIdent(committer, now, tz);
		}
Exemplo n.º 23
0
 /// <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)
 {
 }
Exemplo n.º 24
0
		public virtual void TestTimeAltersId()
		{
			PersonIdent oldAuthor = author;
			PersonIdent oldCommitter = committer;
			
			NUnit.Framework.Assert.AreEqual("a\n" + "\n" + "Change-Id: I7fc3876fee63c766a2063df97fbe04a2dddd8d7c\n"
				, Call("a\n"));
			//
			//
			//
			Tick();
			NUnit.Framework.Assert.AreEqual("a\n" + "\n" + "Change-Id: I3251906b99dda598a58a6346d8126237ee1ea800\n"
				, Call("a\n"));
			//
			//
			//
			Tick();
			NUnit.Framework.Assert.AreEqual("a\n" + "\n" + "Change-Id: I69adf9208d828f41a3d7e41afbca63aff37c0c5c\n"
				, Call("a\n"));
			
			author = oldAuthor;
			committer = oldCommitter;
		}
Exemplo n.º 25
0
		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);
			}
		}		
Exemplo n.º 26
0
 /// <summary>Set the creator of this tag.</summary>
 /// <remarks>Set the creator of this tag.</remarks>
 /// <param name="taggerIdent">the creator. May be null.</param>
 public virtual void SetTagger(PersonIdent taggerIdent)
 {
     tagger = taggerIdent;
 }
Exemplo n.º 27
0
 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
         ());
 }
Exemplo n.º 28
0
        /// <summary>
        /// Format committer, author or tagger ident according to this formatter's
        /// specification.
        /// </summary>
        /// <remarks>
        /// Format committer, author or tagger ident according to this formatter's
        /// specification.
        /// </remarks>
        /// <param name="ident"></param>
        /// <returns>formatted version of date, time and time zone</returns>
        public virtual string FormatDate(PersonIdent ident)
        {
            switch (format)
            {
                case GitDateFormatter.Format.RAW:
                {
                    int offset = ident.GetTimeZoneOffset();
                    string sign = offset < 0 ? "-" : "+";
                    int offset2;
                    if (offset < 0)
                    {
                        offset2 = -offset;
                    }
                    else
                    {
                        offset2 = offset;
                    }
                    int hours = offset2 / 60;
                    int minutes = offset2 % 60;
                    return string.Format("%d %s%02d%02d", ident.GetWhen().GetTime() / 1000, sign, hours
                        , minutes);
                }

                case GitDateFormatter.Format.RELATIVE:
                {
                    return RelativeDateFormatter.Format(ident.GetWhen());
                }

                case GitDateFormatter.Format.LOCALELOCAL:
                case GitDateFormatter.Format.LOCAL:
                {
                    dateTimeInstance.SetTimeZone(SystemReader.GetInstance().GetTimeZone());
                    return dateTimeInstance.Format(ident.GetWhen());
                }

                case GitDateFormatter.Format.LOCALE:
                {
                    TimeZoneInfo tz = ident.GetTimeZone();
                    if (tz == null)
                    {
                        tz = SystemReader.GetInstance().GetTimeZone();
                    }
                    dateTimeInstance.SetTimeZone(tz);
                    dateTimeInstance2.SetTimeZone(tz);
                    return dateTimeInstance.Format(ident.GetWhen()) + " " + dateTimeInstance2.Format(
                        ident.GetWhen());
                }

                default:
                {
                    tz = ident.GetTimeZone();
                    if (tz == null)
                    {
                        tz = SystemReader.GetInstance().GetTimeZone();
                    }
                    dateTimeInstance.SetTimeZone(ident.GetTimeZone());
                    return dateTimeInstance.Format(ident.GetWhen());
                    break;
                }
            }
        }
Exemplo n.º 29
0
 /// <summary>Set the identity of the user appearing in the reflog.</summary>
 /// <remarks>
 /// Set the identity of the user appearing in the reflog.
 /// <p>
 /// The timestamp portion of the identity is ignored. A new identity with the
 /// current timestamp will be created automatically when the rename occurs
 /// and the log record is written.
 /// </remarks>
 /// <param name="pi">
 /// identity of the user. If null the identity will be
 /// automatically determined based on the repository
 /// configuration.
 /// </param>
 public virtual void SetRefLogIdent(PersonIdent pi)
 {
     destination.SetRefLogIdent(pi);
 }
Exemplo n.º 30
0
		/// <summary>Write the given entry information to the ref's log</summary>
		/// <param name="refName"></param>
		/// <param name="oldId"></param>
		/// <param name="newId"></param>
		/// <param name="ident"></param>
		/// <param name="message"></param>
		/// <returns>this writer</returns>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual NGit.Storage.File.ReflogWriter Log(string refName, ObjectId oldId, 
			ObjectId newId, PersonIdent ident, string message)
		{
			byte[] encoded = Encode(oldId, newId, ident, message);
			return Log(refName, encoded);
		}
		private void AssertPersonIdent(string line, PersonIdent expected)
		{
			PersonIdent actual = RawParseUtils.ParsePersonIdent(line);
			NUnit.Framework.Assert.AreEqual(expected, actual);
		}
Exemplo n.º 32
0
		private byte[] Encode(ObjectId oldId, ObjectId newId, PersonIdent ident, string message
			)
		{
			StringBuilder r = new StringBuilder();
			r.Append(ObjectId.ToString(oldId));
			r.Append(' ');
			r.Append(ObjectId.ToString(newId));
			r.Append(' ');
			r.Append(ident.ToExternalString());
			r.Append('\t');
			r.Append(message);
			r.Append('\n');
			return Constants.Encode(r.ToString());
		}
Exemplo n.º 33
0
 /// <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)
 {
 }
Exemplo n.º 34
0
		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();
		}
Exemplo n.º 35
0
		public ChangeIdUtilTest()
		{
			when = mockSystemReader.GetCurrentTime();
			tz = new MockSystemReader().GetTimezone(when);
			{
				author = new PersonIdent(author, when, tz);
			}
			{
				committer = new PersonIdent(committer, when, tz);
			}
		}
Exemplo n.º 36
0
		/// <summary>Set the identity of the user appearing in the reflog.</summary>
		/// <remarks>
		/// Set the identity of the user appearing in the reflog.
		/// <p>
		/// The timestamp portion of the identity is ignored. A new identity with the
		/// current timestamp will be created automatically when the rename occurs
		/// and the log record is written.
		/// </remarks>
		/// <param name="pi">
		/// identity of the user. If null the identity will be
		/// automatically determined based on the repository
		/// configuration.
		/// </param>
		public virtual void SetRefLogIdent(PersonIdent pi)
		{
			destination.SetRefLogIdent(pi);
		}
Exemplo n.º 37
0
 public API_NGit()
 {
     Author    = new PersonIdent(NGit_Consts.DEFAULT_COMMIT_NAME, NGit_Consts.DEFAULT_COMMIT_EMAIL);
     Committer = new PersonIdent("FluentSharp NGit", "*****@*****.**");
 }
Exemplo n.º 38
0
		private string Iso(PersonIdent id)
		{
			SimpleDateFormat fmt;
			fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
			fmt.SetTimeZone(id.GetTimeZone());
			return fmt.Format(id.GetWhen());
		}
Exemplo n.º 39
0
 /// <summary>Set the identity of the user appearing in the reflog.</summary>
 /// <remarks>
 /// Set the identity of the user appearing in the reflog.
 /// <p>
 /// The timestamp portion of the identity is ignored. A new identity with the
 /// current timestamp will be created automatically when the update occurs
 /// and the log record is written.
 /// </remarks>
 /// <param name="pi">
 /// identity of the user. If null the identity will be
 /// automatically determined based on the repository
 /// configuration.
 /// </param>
 public virtual void SetRefLogIdent(PersonIdent pi)
 {
     refLogIdent = pi;
 }
Exemplo n.º 40
0
 public virtual void TestCommitRange()
 {
     // do 4 commits and set the range to the second and fourth one
     Git git = new Git(db);
     git.Commit().SetMessage("first commit").Call();
     RevCommit second = git.Commit().SetMessage("second commit").SetCommitter(committer
         ).Call();
     git.Commit().SetMessage("third commit").SetAuthor(author).Call();
     RevCommit last = git.Commit().SetMessage("fourth commit").SetAuthor(author).SetCommitter
         (committer).Call();
     Iterable<RevCommit> commits = git.Log().AddRange(second.Id, last.Id).Call();
     // check that we have the third and fourth commit
     PersonIdent defaultCommitter = new PersonIdent(db);
     PersonIdent[] expectedAuthors = new PersonIdent[] { author, author };
     PersonIdent[] expectedCommitters = new PersonIdent[] { defaultCommitter, committer
          };
     string[] expectedMessages = new string[] { "third commit", "fourth commit" };
     int l = expectedAuthors.Length - 1;
     foreach (RevCommit c in commits)
     {
         NUnit.Framework.Assert.AreEqual(expectedAuthors[l].GetName(), c.GetAuthorIdent().
             GetName());
         NUnit.Framework.Assert.AreEqual(expectedCommitters[l].GetName(), c.GetCommitterIdent
             ().GetName());
         NUnit.Framework.Assert.AreEqual(c.GetFullMessage(), expectedMessages[l]);
         l--;
     }
     NUnit.Framework.Assert.AreEqual(l, -1);
 }
Exemplo n.º 41
0
		/// <summary>Set the creator of this tag.</summary>
		/// <remarks>Set the creator of this tag.</remarks>
		/// <param name="taggerIdent">the creator. May be null.</param>
		public virtual void SetTagger(PersonIdent taggerIdent)
		{
			tagger = taggerIdent;
		}