예제 #1
0
        public virtual void TestNoCacheObjectIdSubclass()
        {
            string    newRef = "refs/heads/abc";
            RefUpdate ru     = UpdateRef(newRef);

            RefUpdateTest.SubclassedId newid = new RefUpdateTest.SubclassedId(ru.GetNewObjectId
                                                                                  ());
            ru.SetNewObjectId(newid);
            RefUpdate.Result update = ru.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, update);
            Ref r = db.GetAllRefs().Get(newRef);

            NUnit.Framework.Assert.IsNotNull(r);
            NUnit.Framework.Assert.AreEqual(newRef, r.GetName());
            NUnit.Framework.Assert.IsNotNull(r.GetObjectId());
            NUnit.Framework.Assert.AreNotSame(newid, r.GetObjectId());
            NUnit.Framework.Assert.AreSame(typeof(ObjectId), r.GetObjectId().GetType());
            NUnit.Framework.Assert.AreEqual(newid, r.GetObjectId());
            IList <ReflogEntry> reverseEntries1 = db.GetReflogReader("refs/heads/abc").GetReverseEntries
                                                      ();
            ReflogEntry entry1 = reverseEntries1[0];

            NUnit.Framework.Assert.AreEqual(1, reverseEntries1.Count);
            NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entry1.GetOldId());
            NUnit.Framework.Assert.AreEqual(r.GetObjectId(), entry1.GetNewId());
            NUnit.Framework.Assert.AreEqual(new PersonIdent(db).ToString(), entry1.GetWho().ToString
                                                ());
            NUnit.Framework.Assert.AreEqual(string.Empty, entry1.GetComment());
            IList <ReflogEntry> reverseEntries2 = db.GetReflogReader("HEAD").GetReverseEntries
                                                      ();

            NUnit.Framework.Assert.AreEqual(0, reverseEntries2.Count);
        }
예제 #2
0
        public virtual void TestUpdateRefDetachedUnbornHead()
        {
            ObjectId ppid = db.Resolve("refs/heads/master^");

            WriteSymref("HEAD", "refs/heads/unborn");
            RefUpdate updateRef = db.UpdateRef("HEAD", true);

            updateRef.SetForceUpdate(true);
            updateRef.SetNewObjectId(ppid);
            RefUpdate.Result update = updateRef.Update();
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.NEW, update);
            NUnit.Framework.Assert.AreEqual(ppid, db.Resolve("HEAD"));
            Ref @ref = db.GetRef("HEAD");

            NUnit.Framework.Assert.AreEqual("HEAD", @ref.GetName());
            NUnit.Framework.Assert.IsTrue([email protected](), "is detached");
            // the branch HEAD referred to is left untouched
            NUnit.Framework.Assert.IsNull(db.Resolve("refs/heads/unborn"));
            ReflogReader reflogReader = new ReflogReader(db, "HEAD");
            ReflogEntry  e            = reflogReader.GetReverseEntries()[0];

            NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, e.GetOldId());
            NUnit.Framework.Assert.AreEqual(ppid, e.GetNewId());
            NUnit.Framework.Assert.AreEqual("GIT_COMMITTER_EMAIL", e.GetWho().GetEmailAddress
                                                ());
            NUnit.Framework.Assert.AreEqual("GIT_COMMITTER_NAME", e.GetWho().GetName());
            NUnit.Framework.Assert.AreEqual(1250379778000L, e.GetWho().GetWhen().GetTime());
        }
        public virtual void TestSpecificEntryNumber()
        {
            SetupReflog("logs/refs/heads/master", twoLine);
            ReflogReader reader = new ReflogReader(db, "refs/heads/master");
            ReflogEntry  e      = reader.GetReverseEntry(0);

            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("c6734895958052a9dbc396cff4459dc1a25029ab"
                                                                ), e.GetOldId());
            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("54794942a18a237c57a80719afed44bb78172b10"
                                                                ), e.GetNewId());
            NUnit.Framework.Assert.AreEqual("Same A U Thor", e.GetWho().GetName());
            NUnit.Framework.Assert.AreEqual("*****@*****.**", e.GetWho().GetEmailAddress
                                                ());
            NUnit.Framework.Assert.AreEqual(60, e.GetWho().GetTimeZoneOffset());
            NUnit.Framework.Assert.AreEqual("2009-05-22T22:36:42", Iso(e.GetWho()));
            NUnit.Framework.Assert.AreEqual("rebase finished: refs/heads/rr/renamebranch5 onto c6e3b9fe2da0293f11eae202ec35fb343191a82d"
                                            , e.GetComment());
            e = reader.GetReverseEntry(1);
            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("0000000000000000000000000000000000000000"
                                                                ), e.GetOldId());
            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("c6734895958052a9dbc396cff4459dc1a25029ab"
                                                                ), e.GetNewId());
            NUnit.Framework.Assert.AreEqual("A U Thor", e.GetWho().GetName());
            NUnit.Framework.Assert.AreEqual("*****@*****.**", e.GetWho().GetEmailAddress()
                                            );
            NUnit.Framework.Assert.AreEqual(-60, e.GetWho().GetTimeZoneOffset());
            NUnit.Framework.Assert.AreEqual("2009-05-22T20:36:41", Iso(e.GetWho()));
            NUnit.Framework.Assert.AreEqual("branch: Created from rr/renamebranchv4", e.GetComment
                                                ());
            NUnit.Framework.Assert.IsNull(reader.GetReverseEntry(3));
        }
예제 #4
0
		internal CheckoutEntry(ReflogEntry reflogEntry)
		{
			string comment = reflogEntry.GetComment();
			int p1 = CHECKOUT_MOVING_FROM.Length;
			int p2 = comment.IndexOf(" to ", p1);
			int p3 = comment.Length;
			from = Sharpen.Runtime.Substring(comment, p1, p2);
			to = Sharpen.Runtime.Substring(comment, p2 + " to ".Length, p3);
		}
예제 #5
0
        internal CheckoutEntry(ReflogEntry reflogEntry)
        {
            string comment = reflogEntry.GetComment();
            int    p1      = CHECKOUT_MOVING_FROM.Length;
            int    p2      = comment.IndexOf(" to ", p1);
            int    p3      = comment.Length;

            from = Sharpen.Runtime.Substring(comment, p1, p2);
            to   = Sharpen.Runtime.Substring(comment, p2 + " to ".Length, p3);
        }
        public virtual void TestCheckout()
        {
            SetupReflog("logs/HEAD", switchBranch);
            IList <ReflogEntry> entries = db.GetReflogReader(Constants.HEAD).GetReverseEntries
                                              ();

            NUnit.Framework.Assert.AreEqual(1, entries.Count);
            ReflogEntry   entry    = entries[0];
            CheckoutEntry checkout = entry.ParseCheckout();

            NUnit.Framework.Assert.IsNotNull(checkout);
            NUnit.Framework.Assert.AreEqual("master", checkout.GetToBranch());
            NUnit.Framework.Assert.AreEqual("new/work", checkout.GetFromBranch());
        }
        public virtual void TestReadLineWithMissingComment()
        {
            SetupReflog("logs/refs/heads/master", oneLineWithoutComment);
            ReflogReader reader = db.GetReflogReader("master");
            ReflogEntry  e      = reader.GetLastEntry();

            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("da85355dfc525c9f6f3927b876f379f46ccf826e"
                                                                ), e.GetOldId());
            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("3e7549db262d1e836d9bf0af7e22355468f1717c"
                                                                ), e.GetNewId());
            NUnit.Framework.Assert.AreEqual("A O Thor Too", e.GetWho().GetName());
            NUnit.Framework.Assert.AreEqual("*****@*****.**", e.GetWho().GetEmailAddress());
            NUnit.Framework.Assert.AreEqual(120, e.GetWho().GetTimeZoneOffset());
            NUnit.Framework.Assert.AreEqual("2009-05-22T23:36:40", Iso(e.GetWho()));
            NUnit.Framework.Assert.AreEqual(string.Empty, e.GetComment());
        }
        public virtual void TestReadOneLine()
        {
            SetupReflog("logs/refs/heads/master", oneLine);
            ReflogReader reader = new ReflogReader(db, "refs/heads/master");
            ReflogEntry  e      = reader.GetLastEntry();

            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("da85355dfc525c9f6f3927b876f379f46ccf826e"
                                                                ), e.GetOldId());
            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("3e7549db262d1e836d9bf0af7e22355468f1717c"
                                                                ), e.GetNewId());
            NUnit.Framework.Assert.AreEqual("A O Thor Too", e.GetWho().GetName());
            NUnit.Framework.Assert.AreEqual("*****@*****.**", e.GetWho().GetEmailAddress());
            NUnit.Framework.Assert.AreEqual(120, e.GetWho().GetTimeZoneOffset());
            NUnit.Framework.Assert.AreEqual("2009-05-22T23:36:40", Iso(e.GetWho()));
            NUnit.Framework.Assert.AreEqual("commit: Add a toString for debugging to RemoteRefUpdate"
                                            , e.GetComment());
        }
        public virtual void TestReadWhileAppendIsInProgress()
        {
            SetupReflog("logs/refs/heads/master", twoLineWithAppendInProgress);
            ReflogReader        reader         = new ReflogReader(db, "refs/heads/master");
            IList <ReflogEntry> reverseEntries = reader.GetReverseEntries();

            NUnit.Framework.Assert.AreEqual(2, reverseEntries.Count);
            ReflogEntry e = reverseEntries[0];

            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("c6734895958052a9dbc396cff4459dc1a25029ab"
                                                                ), e.GetOldId());
            NUnit.Framework.Assert.AreEqual(ObjectId.FromString("54794942a18a237c57a80719afed44bb78172b10"
                                                                ), e.GetNewId());
            NUnit.Framework.Assert.AreEqual("Same A U Thor", e.GetWho().GetName());
            NUnit.Framework.Assert.AreEqual("*****@*****.**", e.GetWho().GetEmailAddress
                                                ());
            NUnit.Framework.Assert.AreEqual(60, e.GetWho().GetTimeZoneOffset());
            NUnit.Framework.Assert.AreEqual("2009-05-22T22:36:42", Iso(e.GetWho()));
            NUnit.Framework.Assert.AreEqual("rebase finished: refs/heads/rr/renamebranch5 onto c6e3b9fe2da0293f11eae202ec35fb343191a82d"
                                            , e.GetComment());
        }
예제 #10
0
        /// <param name="max">max number of entries to read</param>
        /// <returns>all reflog entries in reverse order</returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual IList <ReflogEntry> GetReverseEntries(int max)
        {
            byte[] log;
            try
            {
                log = IOUtil.ReadFully(logName);
            }
            catch (FileNotFoundException)
            {
                return(Sharpen.Collections.EmptyList <ReflogEntry>());
            }
            int rs = RawParseUtils.PrevLF(log, log.Length);
            IList <ReflogEntry> ret = new AList <ReflogEntry>();

            while (rs >= 0 && max-- > 0)
            {
                rs = RawParseUtils.PrevLF(log, rs);
                ReflogEntry entry = new ReflogEntry(log, rs < 0 ? 0 : rs + 2);
                ret.AddItem(entry);
            }
            return(ret);
        }
예제 #11
0
 /// <summary>
 /// Write the given
 /// <see cref="ReflogEntry">ReflogEntry</see>
 /// entry to the ref's log
 /// </summary>
 /// <param name="refName"></param>
 /// <param name="entry"></param>
 /// <returns>this writer</returns>
 /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 public virtual NGit.Storage.File.ReflogWriter Log(string refName, ReflogEntry entry
                                                   )
 {
     return(Log(refName, entry.GetOldId(), entry.GetNewId(), entry.GetWho(), entry.GetComment
                    ()));
 }
예제 #12
0
		/// <summary>
		/// Write the given
		/// <see cref="ReflogEntry">ReflogEntry</see>
		/// entry to the ref's log
		/// </summary>
		/// <param name="refName"></param>
		/// <param name="entry"></param>
		/// <returns>this writer</returns>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual NGit.Storage.File.ReflogWriter Log(string refName, ReflogEntry entry
			)
		{
			return Log(refName, entry.GetOldId(), entry.GetNewId(), entry.GetWho(), entry.GetComment
				());
		}
예제 #13
0
		/// <param name="max">max number of entries to read</param>
		/// <returns>all reflog entries in reverse order</returns>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual IList<ReflogEntry> GetReverseEntries(int max)
		{
			byte[] log;
			try
			{
				log = IOUtil.ReadFully(logName);
			}
			catch (FileNotFoundException)
			{
				return Sharpen.Collections.EmptyList<ReflogEntry>();
			}
			int rs = RawParseUtils.PrevLF(log, log.Length);
			IList<ReflogEntry> ret = new AList<ReflogEntry>();
			while (rs >= 0 && max-- > 0)
			{
				rs = RawParseUtils.PrevLF(log, rs);
				ReflogEntry entry = new ReflogEntry(log, rs < 0 ? 0 : rs + 2);
				ret.AddItem(entry);
			}
			return ret;
		}