Пример #1
0
        public virtual void Test021_createTreeTag()
        {
            ObjectId emptyId         = InsertEmptyBlob();
            Tree     almostEmptyTree = new Tree(db);

            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, Sharpen.Runtime.GetBytesForString
                                                           ("empty"), false));
            ObjectId   almostEmptyTreeId = InsertTree(almostEmptyTree);
            TagBuilder t = new TagBuilder();

            t.SetObjectId(almostEmptyTreeId, Constants.OBJ_TREE);
            t.SetTag("test021");
            t.SetTagger(new PersonIdent(author, 1154236443000L, -4 * 60));
            t.SetMessage("test021 tagged\n");
            ObjectId actid = InsertTag(t);

            NUnit.Framework.Assert.AreEqual("b0517bc8dbe2096b419d42424cd7030733f4abe5", actid
                                            .Name);
            RevTag mapTag = ParseTag(actid);

            NUnit.Framework.Assert.AreEqual(Constants.OBJ_TREE, mapTag.GetObject().Type);
            NUnit.Framework.Assert.AreEqual("test021 tagged\n", mapTag.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60),
                                            mapTag.GetTaggerIdent());
            NUnit.Framework.Assert.AreEqual("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag
                                            .GetObject().Id.Name);
        }
Пример #2
0
        public void testParse_OnlyLFMessage()
        {
            RevTag c = create("\n");

            Assert.AreEqual("\n", c.getFullMessage());
            Assert.AreEqual(string.Empty, c.getShortMessage());
        }
Пример #3
0
        public void testParse_explicit_bad_encoded()
        {
            RevTag c;

            using (var b = new BinaryWriter(new MemoryStream()))
            {
                b.Write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
                b.Write("type tree\n".getBytes("UTF-8"));
                b.Write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
                b.Write("tagger F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n".getBytes("ISO-8859-1"));
                b.Write("encoding EUC-JP\n".getBytes("UTF-8"));
                b.Write("\n".getBytes("UTF-8"));
                b.Write("\u304d\u308c\u3044\n".getBytes("UTF-8"));
                b.Write("\n".getBytes("UTF-8"));
                b.Write("Hi\n".getBytes("UTF-8"));

                c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
                c.parseCanonical(new Core.RevWalk.RevWalk(db), ((MemoryStream)b.BaseStream).ToArray());
            }

            AssertHelper.IgnoreOnMono(() => Assert.AreEqual("F\u00f6r fattare", c.getTaggerIdent().Name), "Will fail in mono due to https://bugzilla.novell.com/show_bug.cgi?id=547902");

            Assert.AreEqual("\u304d\u308c\u3044", c.getShortMessage());
            Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.getFullMessage());
        }
Пример #4
0
        private void Want(RevObject o)
        {
            if (o.has(WANT))
            {
                return;
            }

            o.add(WANT);
            _wantAll.Add(o);

            RevTag oTag = (o as RevTag);

            while (oTag != null)
            {
                o    = oTag.getObject();
                oTag = (o as RevTag);
            }

            RevCommit oComm = (o as RevCommit);

            if (oComm != null)
            {
                _wantCommits.Add(oComm);
            }
        }
Пример #5
0
        public virtual void Test022_createCommitTag()
        {
            ObjectId emptyId         = InsertEmptyBlob();
            Tree     almostEmptyTree = new Tree(db);

            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, Sharpen.Runtime.GetBytesForString
                                                           ("empty"), false));
            ObjectId almostEmptyTreeId = InsertTree(almostEmptyTree);

            NGit.CommitBuilder almostEmptyCommit = new NGit.CommitBuilder();
            almostEmptyCommit.Author = new PersonIdent(author, 1154236443000L, -2 * 60);
            // not exactly the same
            almostEmptyCommit.Committer = new PersonIdent(author, 1154236443000L, -2 * 60);
            almostEmptyCommit.Message   = "test022\n";
            almostEmptyCommit.TreeId    = almostEmptyTreeId;
            ObjectId   almostEmptyCommitId = InsertCommit(almostEmptyCommit);
            TagBuilder t = new TagBuilder();

            t.SetObjectId(almostEmptyCommitId, Constants.OBJ_COMMIT);
            t.SetTag("test022");
            t.SetTagger(new PersonIdent(author, 1154236443000L, -4 * 60));
            t.SetMessage("test022 tagged\n");
            ObjectId actid = InsertTag(t);

            NUnit.Framework.Assert.AreEqual("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", actid
                                            .Name);
            RevTag mapTag = ParseTag(actid);

            NUnit.Framework.Assert.AreEqual(Constants.OBJ_COMMIT, mapTag.GetObject().Type);
            NUnit.Framework.Assert.AreEqual("test022 tagged\n", mapTag.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60),
                                            mapTag.GetTaggerIdent());
            NUnit.Framework.Assert.AreEqual("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag
                                            .GetObject().Id.Name);
        }
Пример #6
0
        private void ProcessTag(RevObject obj)
        {
            RevTag tag = (RevTag)obj;

            Needs(tag.GetObject());
            obj.Add(COMPLETE);
        }
Пример #7
0
        public virtual void TestPush()
        {
            // create other repository
            Repository db2 = CreateWorkRepository();
            // setup the first repository
            StoredConfig config       = ((FileBasedConfig)db.GetConfig());
            RemoteConfig remoteConfig = new RemoteConfig(config, "test");
            URIish       uri          = new URIish(db2.Directory.ToURI().ToURL());

            remoteConfig.AddURI(uri);
            remoteConfig.Update(config);
            config.Save();
            Git git1 = new Git(db);
            // create some refs via commits and tag
            RevCommit commit = git1.Commit().SetMessage("initial commit").Call();
            RevTag    tag    = git1.Tag().SetName("tag").Call();

            try
            {
                db2.Resolve(commit.Id.GetName() + "^{commit}");
                NUnit.Framework.Assert.Fail("id shouldn't exist yet");
            }
            catch (MissingObjectException)
            {
            }
            // we should get here
            RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");

            git1.Push().SetRemote("test").SetRefSpecs(spec).Call();
            NUnit.Framework.Assert.AreEqual(commit.Id, db2.Resolve(commit.Id.GetName() + "^{commit}"
                                                                   ));
            NUnit.Framework.Assert.AreEqual(tag.Id, db2.Resolve(tag.Id.GetName()));
        }
Пример #8
0
        public void testParse_ShortLineOnlyNoLF()
        {
            const string shortMsg = "This is a short message.";
            RevTag       c        = create(shortMsg);

            Assert.AreEqual(shortMsg, c.getFullMessage());
            Assert.AreEqual(shortMsg, c.getShortMessage());
        }
Пример #9
0
        public void testParse_NoMessage()
        {
            const string msg = "";
            RevTag       c   = create(msg);

            Assert.AreEqual(msg, c.getFullMessage());
            Assert.AreEqual(msg, c.getShortMessage());
        }
Пример #10
0
        public virtual void TestTaggingOnHead()
        {
            Git       git    = new Git(db);
            RevCommit commit = git.Commit().SetMessage("initial commit").Call();
            RevTag    tag    = git.Tag().SetName("tag").Call();

            NUnit.Framework.Assert.AreEqual(commit.Id, tag.GetObject().Id);
        }
Пример #11
0
        public void testParse_ShortLineOnlyEmbeddedLF()
        {
            const string fullMsg  = "This is a\nshort message.";
            string       shortMsg = fullMsg.Replace('\n', ' ');
            RevTag       c        = create(fullMsg);

            Assert.AreEqual(fullMsg, c.getFullMessage());
            Assert.AreEqual(shortMsg, c.getShortMessage());
        }
Пример #12
0
        public void testParse_ShortLineOnlyEmbeddedAndEndingLF()
        {
            const string fullMsg  = "This is a\nshort message.\n";
            const string shortMsg = "This is a short message.";
            RevTag       c        = create(fullMsg);

            Assert.AreEqual(fullMsg, c.getFullMessage());
            Assert.AreEqual(shortMsg, c.getShortMessage());
        }
Пример #13
0
        public void testParse_GitStyleMessage()
        {
            const string shortMsg = "This fixes a bug.";
            const string body     = "We do it with magic and pixie dust and stuff.\n"
                                    + "\n" + "Signed-off-by: A U. Thor <*****@*****.**>\n";
            const string fullMsg = shortMsg + "\n" + "\n" + body;
            RevTag       c       = create(fullMsg);

            Assert.AreEqual(fullMsg, c.getFullMessage());
            Assert.AreEqual(shortMsg, c.getShortMessage());
        }
Пример #14
0
 public override void SetUp()
 {
     base.SetUp();
     diskRepo = CreateBareRepository();
     refdir   = (RefDirectory)diskRepo.RefDatabase;
     repo     = new TestRepository(diskRepo);
     A        = repo.Commit().Create();
     B        = repo.Commit(repo.GetRevWalk().ParseCommit(A));
     v1_0     = repo.Tag("v1_0", B);
     repo.GetRevWalk().ParseBody(v1_0);
 }
Пример #15
0
        public virtual void AnnotatedTag_objectNotPruned()
        {
            RevBlob a = tr.Blob("a");
            RevTag  t = tr.Tag("t", a);

            // this doesn't create the refs/tags/t ref
            tr.LightweightTag("t", t);
            gc.SetExpireAgeMillis(0);
            gc.Prune(Collections.EmptySet <ObjectId>());
            NUnit.Framework.Assert.IsTrue(repo.HasObject(t));
            NUnit.Framework.Assert.IsTrue(repo.HasObject(a));
        }
Пример #16
0
        public void testParseAllFields()
        {
            ObjectId     treeId      = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            const string name        = "v1.2.3.4.5";
            const string taggerName  = "A U. Thor";
            const string taggerEmail = "*****@*****.**";
            const int    taggerTime  = 1218123387;

            var 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");

            var rw = new Core.RevWalk.RevWalk(db);

            var c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));

            Assert.IsNull(c.getObject());
            Assert.IsNull(c.getTagName());

            c.parseCanonical(rw, body.ToString().getBytes("UTF-8"));
            Assert.IsNotNull(c.getObject());
            Assert.AreEqual(treeId, c.getObject().getId());
            Assert.AreSame(rw.lookupTree(treeId), c.getObject());

            Assert.IsNotNull(c.getTagName());
            Assert.AreEqual(name, c.getTagName());
            Assert.AreEqual(string.Empty, c.getFullMessage());

            PersonIdent cTagger = c.getTaggerIdent();

            Assert.IsNotNull(cTagger);
            Assert.AreEqual(taggerName, cTagger.Name);
            Assert.AreEqual(taggerEmail, cTagger.EmailAddress);
        }
Пример #17
0
        public override void setUp()
        {
            base.setUp();

            diskRepo = createBareRepository();
            refdir   = (RefDirectory)diskRepo.RefDatabase;

            repo = new TestRepository(diskRepo);
            A    = repo.commit().create();
            B    = repo.commit(repo.getRevWalk().parseCommit(A));
            v1_0 = repo.tag("v1_0", B);
            repo.getRevWalk().parseBody(v1_0);
        }
Пример #18
0
 internal virtual long Timeof(RevObject o)
 {
     if (o is RevCommit)
     {
         return(((RevCommit)o).CommitTime);
     }
     if (o is RevTag)
     {
         RevTag      tag = (RevTag)o;
         PersonIdent who = tag.GetTaggerIdent();
         return(who != null?who.GetWhen().GetTime() : 0);
     }
     return(0);
 }
Пример #19
0
        /// <summary>
        /// Advertise one object is available using the magic <code>.have</code>.
        /// <para/>
        /// The magic <code>.have</code> advertisement is not available for fetching by a
        /// client, but can be used by a client when considering a delta base
        /// candidate before transferring data in a push. Within the record created
        /// by this method the ref name is simply the invalid string <code>.have</code>.
        /// </summary>
        /// <param name="id">
        /// identity of the object that is assumed to exist.
        /// </param>
        public void advertiseHave(AnyObjectId id)
        {
            RevObject obj = parseAnyOrNull(id);

            if (obj != null)
            {
                advertiseAnyOnce(obj, ".have");
            }

            RevTag rt = (obj as RevTag);

            if (rt != null)
            {
                advertiseAnyOnce(rt.getObject(), ".have");
            }
        }
Пример #20
0
 /// <summary>
 /// Format an advertisement for the supplied refs.
 /// </summary>
 /// <param name="refs">
 /// zero or more refs to format for the client. The collection is
 /// sorted before display if necessary, and therefore may appear
 /// in any order.
 /// </param>
 public void send(IDictionary <string, Ref> refs)
 {
     foreach (Ref r in getSortedRefs(refs))
     {
         RevObject obj = parseAnyOrNull(r.ObjectId);
         if (obj != null)
         {
             advertiseAny(obj, r.Name);
             RevTag rt = (obj as RevTag);
             if (_derefTags && rt != null)
             {
                 advertiseTag(rt, r.Name + "^{}");
             }
         }
     }
 }
Пример #21
0
 public void send(IEnumerable <Ref> refs)
 {
     foreach (Ref r in RefComparator.Sort(refs))
     {
         RevObject obj = parseAnyOrNull(r.ObjectId);
         if (obj != null)
         {
             advertiseAny(obj, r.OriginalName);
             RevTag rt = (obj as RevTag);
             if (_derefTags && rt != null)
             {
                 advertiseTag(rt, r.OriginalName + "^{}");
             }
         }
     }
 }
Пример #22
0
        private RevTag create(string msg)
        {
            var b = new StringBuilder();

            b.Append("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n");
            b.Append("type tree\n");
            b.Append("tag v1.2.3.4.5\n");
            b.Append("tagger A U. Thor <*****@*****.**> 1218123387 +0700\n");
            b.Append("\n");
            b.Append(msg);

            var c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));

            c.parseCanonical(new Core.RevWalk.RevWalk(db), b.ToString().getBytes("UTF-8"));
            return(c);
        }
Пример #23
0
        public void testParseOldStyleNoTagger()
        {
            ObjectId treeId  = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            string   name    = "v1.2.3.4.5";
            string   message = "test\n"                                //
                               + "\n"                                  //
                               + "-----BEGIN PGP SIGNATURE-----\n"     //
                               + "Version: GnuPG v1.4.1 (GNU/Linux)\n" //
                               + "\n"                                  //
                               + "iD8DBQBC0b9oF3Y\n"                   //
                               + "-----END PGP SIGNATURE------n";

            var 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("\n");
            body.Append(message);

            var    rw = new Core.RevWalk.RevWalk(db);
            RevTag c;

            c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            Assert.IsNull(c.getObject());
            Assert.IsNull(c.getTagName());

            c.parseCanonical(rw, body.ToString().getBytes("UTF-8"));
            Assert.IsNotNull(c.getObject());
            Assert.AreEqual(treeId, c.getObject().getId());
            Assert.AreSame(rw.lookupTree(treeId), c.getObject());

            Assert.IsNotNull(c.getTagName());
            Assert.AreEqual(name, c.getTagName());
            Assert.AreEqual("test", c.getShortMessage());
            Assert.AreEqual(message, c.getFullMessage());

            Assert.IsNull(c.getTaggerIdent());
        }
Пример #24
0
        private void advertiseTag(RevTag tag, string refName)
        {
            RevTag o = (tag as RevTag);

            do
            {
                RevTag target = (o.getObject() as RevTag);
                try
                {
                    _walk.parseHeaders(target);
                }
                catch (IOException)
                {
                    return;
                }
                target.add(ADVERTISED);
                o = target;
            } while (o != null);
            advertiseAny(tag.getObject(), refName);
        }
Пример #25
0
        private void advertiseTag(RevTag tag, string refName)
        {
            RevObject o = tag;

            do
            {
                // Fully unwrap here so later on we have these already parsed.
                RevObject target = (((RevTag)o).getObject());
                try
                {
                    _walk.parseHeaders(target);
                }
                catch (IOException)
                {
                    return;
                }
                target.add(ADVERTISED);
                o = target;
            } while (o is RevTag);

            advertiseAny(tag.getObject(), refName);
        }
Пример #26
0
 internal virtual long Timeof(RevObject o)
 {
     if (o is RevCommit)
     {
         return(((RevCommit)o).CommitTime);
     }
     if (o is RevTag)
     {
         RevTag tag = (RevTag)o;
         try
         {
             this._enclosing.ParseBody(tag);
         }
         catch (IOException)
         {
             return(0);
         }
         PersonIdent who = tag.GetTaggerIdent();
         return(who != null?who.GetWhen().GetTime() : 0);
     }
     return(0);
 }
Пример #27
0
        public virtual void Test020_createBlobTag()
        {
            ObjectId   emptyId = InsertEmptyBlob();
            TagBuilder t       = new TagBuilder();

            t.SetObjectId(emptyId, Constants.OBJ_BLOB);
            t.SetTag("test020");
            t.SetTagger(new PersonIdent(author, 1154236443000L, -4 * 60));
            t.SetMessage("test020 tagged\n");
            ObjectId actid = InsertTag(t);

            NUnit.Framework.Assert.AreEqual("6759556b09fbb4fd8ae5e315134481cc25d46954", actid
                                            .Name);
            RevTag mapTag = ParseTag(actid);

            NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, mapTag.GetObject().Type);
            NUnit.Framework.Assert.AreEqual("test020 tagged\n", mapTag.GetFullMessage());
            NUnit.Framework.Assert.AreEqual(new PersonIdent(author, 1154236443000L, -4 * 60),
                                            mapTag.GetTaggerIdent());
            NUnit.Framework.Assert.AreEqual("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag
                                            .GetObject().Id.Name);
        }
Пример #28
0
        public void testParse_implicit_UTF8_encoded()
        {
            RevTag c;

            using (var b = new BinaryWriter(new MemoryStream()))
            {
                b.Write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8"));
                b.Write("type tree\n".getBytes("UTF-8"));
                b.Write("tag v1.2.3.4.5\n".getBytes("UTF-8"));
                b.Write("tagger F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n".getBytes("UTF-8"));
                b.Write("\n".getBytes("UTF-8"));
                b.Write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8"));
                b.Write("\n".getBytes("UTF-8"));
                b.Write("\u304d\u308c\u3044\n".getBytes("UTF-8"));

                c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
                c.parseCanonical(new Core.RevWalk.RevWalk(db), ((MemoryStream)b.BaseStream).ToArray());
            }
            Assert.AreEqual("F\u00f6r fattare", c.getTaggerIdent().Name);
            Assert.AreEqual("Sm\u00f6rg\u00e5sbord", c.getShortMessage());
            Assert.AreEqual("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage());
        }
Пример #29
0
        private void testOneType(int typeCode)
        {
            ObjectId locId = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            var      b     = new StringBuilder();

            b.Append("object " + locId.Name + "\n");
            b.Append("type " + Constants.typeString(typeCode) + "\n");
            b.Append("tag v1.2.3.4.5\n");
            b.Append("tagger A U. Thor <*****@*****.**> 1218123387 +0700\n");
            b.Append("\n");

            var rw = new Core.RevWalk.RevWalk(db);

            var c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));

            Assert.IsNull(c.getObject());
            Assert.IsNull(c.getTagName());

            c.parseCanonical(rw, b.ToString().getBytes("UTF-8"));
            Assert.IsNotNull(c.getObject());
            Assert.AreEqual(locId, c.getObject().getId());
            Assert.AreSame(rw.lookupAny(locId, typeCode), c.getObject());
        }
Пример #30
0
        public void testParse_explicit_encoded()
        {
            Assert.Ignore("We are going to deal with encoding problems later. For now, they are only disturbing the build.");
            RevTag c;

            using (var b = new BinaryWriter(new MemoryStream()))
            {
                b.Write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("EUC-JP"));
                b.Write("type tree\n".getBytes("EUC-JP"));
                b.Write("tag v1.2.3.4.5\n".getBytes("EUC-JP"));
                b.Write("tagger F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n".getBytes("EUC-JP"));
                b.Write("encoding euc_JP\n".getBytes("EUC-JP"));
                b.Write("\n".getBytes("EUC-JP"));
                b.Write("\u304d\u308c\u3044\n".getBytes("EUC-JP"));
                b.Write("\n".getBytes("EUC-JP"));
                b.Write("Hi\n".getBytes("EUC-JP"));

                c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
                c.parseCanonical(new Core.RevWalk.RevWalk(db), ((MemoryStream)b.BaseStream).ToArray());
            }
            Assert.AreEqual("F\u00f6r fattare", c.getTaggerIdent().Name);
            Assert.AreEqual("\u304d\u308c\u3044", c.getShortMessage());
            Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.getFullMessage());
        }