Example #1
0
        public void test001_toString()
        {
            string   x   = "def4c620bc3713bb1bb26b808ec9312548e73946";
            ObjectId oid = ObjectId.FromString(x);

            Assert.AreEqual(x, oid.ToString());
        }
Example #2
0
        /// <exception cref="System.IO.IOException"></exception>
        private void WriteVerifyPack2(bool deltaReuse)
        {
            config.SetReuseDeltas(deltaReuse);
            List <ObjectId> interestings = new List <ObjectId>();

            interestings.AddItem(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"
                                                     ));
            List <ObjectId> uninterestings = new List <ObjectId>();

            uninterestings.AddItem(ObjectId.FromString("540a36d136cf413e4b064c2b0e0a4db60f77feab"
                                                       ));
            CreateVerifyOpenPack(interestings, uninterestings, false, false);
            ObjectId[] expectedOrder = new ObjectId[] { ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"
                                                                            ), ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799"), ObjectId.FromString
                                                            ("aabf2ffaec9b497f0950352b3e582d73035c2035"), ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327"
                                                                                                                              ), ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"), ObjectId.FromString
                                                            ("6ff87c4664981e4397625791c8ea3bbb5f2279a3") };
            if (deltaReuse)
            {
                // objects order influenced (swapped) by delta-base first rule
                ObjectId temp = expectedOrder[4];
                expectedOrder[4] = expectedOrder[5];
                expectedOrder[5] = temp;
            }
            NUnit.Framework.Assert.AreEqual(expectedOrder.Length, writer.GetObjectsNumber());
            VerifyObjectsOrder(expectedOrder);
            NUnit.Framework.Assert.AreEqual("ed3f96b8327c7c66b0f8f70056129f0769323d86", writer
                                            .ComputeName().Name);
        }
Example #3
0
        public void testParseFullIndexLine_WithMode()
        {
            const string oid = "78981922613b2afb6025042ff6bd878ac1994e85";
            const string nid = "61780798228d17af2d34fce4cfbdf35556832472";
            FileHeader   fh  = Data("diff --git a/a b/a\n" + "index " + oid
                                    + ".." + nid + " 100644\n" + "--- a/a\n" + "+++ b/a\n");

            AssertParse(fh);

            Assert.AreEqual("a", fh.OldName);
            Assert.AreEqual("a", fh.NewName);

            Assert.AreSame(FileMode.RegularFile, fh.GetOldMode());
            Assert.AreSame(FileMode.RegularFile, fh.NewMode);
            Assert.IsFalse(fh.hasMetaDataChanges());

            Assert.IsNotNull(fh.getOldId());
            Assert.IsNotNull(fh.getNewId());

            Assert.IsTrue(fh.getOldId().isComplete());
            Assert.IsTrue(fh.getNewId().isComplete());

            Assert.AreEqual(ObjectId.FromString(oid), fh.getOldId().ToObjectId());
            Assert.AreEqual(ObjectId.FromString(nid), fh.getNewId().ToObjectId());
        }
Example #4
0
        public override void setUp()
        {
            base.setUp();

            _toLoad = new List <TestObject>();
            using (var br = new StreamReader("Resources/all_packed_objects.txt", Constants.CHARSET))
            {
                string line;
                while ((line = br.ReadLine()) != null)
                {
                    string[] parts      = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    var      testObject = new TestObject
                    {
                        Id      = ObjectId.FromString(parts[0]),
                        Type    = parts[1],
                        RawSize = Convert.ToInt32(parts[2]),
                        // parts[3] is the size-in-pack
                        Offset = Convert.ToInt64(parts[4])
                    };

                    _toLoad.Add(testObject);
                }
            }

            Assert.AreEqual(96, _toLoad.Count);
        }
        public virtual void RepositoryWithMissingSubmodule()
        {
            ObjectId       id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_93(id, path));
            editor.Commit();
            SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
            IDictionary <string, SubmoduleStatus> statuses = command.Call();

            NUnit.Framework.Assert.IsNotNull(statuses);
            NUnit.Framework.Assert.AreEqual(1, statuses.Count);
            KeyValuePair <string, SubmoduleStatus> module = statuses.EntrySet().Iterator().Next
                                                                ();

            NUnit.Framework.Assert.IsNotNull(module);
            NUnit.Framework.Assert.AreEqual(path, module.Key);
            SubmoduleStatus status = module.Value;

            NUnit.Framework.Assert.IsNotNull(status);
            NUnit.Framework.Assert.AreEqual(path, status.GetPath());
            NUnit.Framework.Assert.AreEqual(id, status.GetIndexId());
            NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.MISSING, status.GetType());
        }
Example #6
0
        public virtual void Test1()
        {
            FilePath packFile = JGitTestUtil.GetTestResourceFile("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack"
                                                                 );
            InputStream @is = new FileInputStream(packFile);

            try
            {
                IndexPack pack = new IndexPack(db, @is, new FilePath(trash, "tmp_pack1"));
                pack.Index(new TextProgressMonitor());
                PackFile file = new PackFile(new FilePath(trash, "tmp_pack1.idx"), new FilePath(trash
                                                                                                , "tmp_pack1.pack"));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("540a36d136cf413e4b064c2b0e0a4db60f77feab"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035"
                                                                                 )));
                NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799"
                                                                                 )));
            }
            finally
            {
                @is.Close();
            }
        }
Example #7
0
        internal ReflogEntry(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;
            }
        }
        private void readBundleV2()
        {
            byte[] hdrbuf = new byte[1024];
            var    avail  = new Dictionary <string, Ref>();

            for (; ;)
            {
                string line = readLine(hdrbuf);
                if (line.Length == 0)
                {
                    break;
                }

                if (line[0] == '-')
                {
                    ObjectId id        = ObjectId.FromString(line.Slice(1, 41));
                    String   shortDesc = null;
                    if (line.Length > 42)
                    {
                        shortDesc = line.Substring(42);
                    }
                    _prereqs.put(id, shortDesc);
                    continue;
                }

                string   name  = line.Slice(41, line.Length);
                ObjectId id2   = ObjectId.FromString(line.Slice(0, 40));
                Ref      prior = avail.put(name, new Unpeeled(Storage.Network, name, id2));
                if (prior != null)
                {
                    throw duplicateAdvertisement(name);
                }
            }
            available(avail);
        }
        public override void SetUp()
        {
            base.SetUp();
            toLoad = new AList <WindowCacheGetTest.TestObject>();
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(
                                                                             JGitTestUtil.GetTestResourceFile("all_packed_objects.txt")), Constants.CHARSET));

            try
            {
                string line;
                while ((line = br.ReadLine()) != null)
                {
                    string[] parts = line.Split(" {1,}");
                    WindowCacheGetTest.TestObject o = new WindowCacheGetTest.TestObject(this);
                    o.id = ObjectId.FromString(parts[0]);
                    o.SetType(parts[1]);
                    // parts[2] is the inflate size
                    // parts[3] is the size-in-pack
                    // parts[4] is the offset in the pack
                    toLoad.AddItem(o);
                }
            }
            finally
            {
                br.Close();
            }
            NUnit.Framework.Assert.AreEqual(96, toLoad.Count);
        }
Example #10
0
        public void testUpdateUpToDate()
        {
            RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", "refs/heads/master", false, null, null);

            Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9"));
            testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.UP_TO_DATE, null);
        }
Example #11
0
        private void readBundleV2()
        {
            byte[] hdrbuf = new byte[1024];
            Dictionary <string, Ref> avail = new Dictionary <string, Ref>();

            for (;;)
            {
                string line = readLine(hdrbuf);
                if (line.Length == 0)
                {
                    break;
                }

                if (line[0] == '-')
                {
                    prereqs.Add(ObjectId.FromString(line.Slice(1, 41)));
                    continue;
                }

                string   name  = line.Slice(41, line.Length);
                ObjectId id    = ObjectId.FromString(line.Slice(0, 40));
                Ref      prior = new Ref(Ref.Storage.Network, name, id);
                if (avail.ContainsKey(name))
                {
                    throw duplicateAdvertisement(name);
                }
                avail.Add(name, prior);
            }
            available(avail);
        }
Example #12
0
        public virtual void Test028_LockPackedRef()
        {
            WriteTrashFile(".git/packed-refs", "7f822839a2fe9760f386cbbbcb3f92c5fe81def7 refs/heads/foobar"
                           );
            WriteTrashFile(".git/HEAD", "ref: refs/heads/foobar\n");
            BUG_WorkAroundRacyGitIssues("packed-refs");
            BUG_WorkAroundRacyGitIssues("HEAD");
            ObjectId resolve = db.Resolve("HEAD");

            NUnit.Framework.Assert.AreEqual("7f822839a2fe9760f386cbbbcb3f92c5fe81def7", resolve
                                            .Name);
            RefUpdate lockRef = db.UpdateRef("HEAD");
            ObjectId  newId   = ObjectId.FromString("07f822839a2fe9760f386cbbbcb3f92c5fe81def");

            lockRef.SetNewObjectId(newId);
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FORCED, lockRef.ForceUpdate());
            NUnit.Framework.Assert.IsTrue(new FilePath(db.Directory, "refs/heads/foobar").Exists
                                              ());
            NUnit.Framework.Assert.AreEqual(newId, db.Resolve("refs/heads/foobar"));
            // Again. The ref already exists
            RefUpdate lockRef2 = db.UpdateRef("HEAD");
            ObjectId  newId2   = ObjectId.FromString("7f822839a2fe9760f386cbbbcb3f92c5fe81def7");

            lockRef2.SetNewObjectId(newId2);
            NUnit.Framework.Assert.AreEqual(RefUpdate.Result.FORCED, lockRef2.ForceUpdate());
            NUnit.Framework.Assert.IsTrue(new FilePath(db.Directory, "refs/heads/foobar").Exists
                                              ());
            NUnit.Framework.Assert.AreEqual(newId2, db.Resolve("refs/heads/foobar"));
        }
Example #13
0
        public virtual void Test000_openrepo_alternate_index_file_and_objdirs()
        {
            FilePath   repo1Parent  = new FilePath(trash.GetParentFile(), "r1");
            FilePath   indexFile    = new FilePath(trash, "idx");
            FilePath   objDir       = new FilePath(trash, "../obj");
            FilePath   altObjDir    = ((ObjectDirectory)db.ObjectDatabase).GetDirectory();
            Repository repo1initial = new FileRepository(new FilePath(repo1Parent, Constants.
                                                                      DOT_GIT));

            repo1initial.Create();
            repo1initial.Close();
            FilePath       theDir = new FilePath(repo1Parent, Constants.DOT_GIT);
            FileRepository r      = new FileRepositoryBuilder().SetGitDir(theDir).SetObjectDirectory
                                        (objDir).AddAlternateObjectDirectory(altObjDir).SetIndexFile(indexFile).Build();

            //
            //
            //
            //
            AssertEqualsPath(theDir, r.Directory);
            AssertEqualsPath(theDir.GetParentFile(), r.WorkTree);
            AssertEqualsPath(indexFile, r.GetIndexFile());
            AssertEqualsPath(objDir, ((ObjectDirectory)r.ObjectDatabase).GetDirectory());
            NUnit.Framework.Assert.IsNotNull(r.Open(ObjectId.FromString("6db9c2ebf75590eef973081736730a9ea169a0c4"
                                                                        )));
            // Must close or the default repo pack files created by this test gets
            // locked via the alternate object directories on Windows.
            r.Close();
        }
Example #14
0
        public void test002_toString()
        {
            string   x   = "ff00eedd003713bb1bb26b808ec9312548e73946";
            ObjectId oid = ObjectId.FromString(x);

            Assert.AreEqual(x, oid.ToString());
        }
Example #15
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');

                // personident has no
                // \t
                if (p0 == -1)
                {
                    throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
                }
                int p1 = RawParseUtils.NextLF(raw, p0);

                if (p1 == -1)
                {
                    throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry);
                }
                comment = RawParseUtils.Decode(raw, p0, p1 - 1);
            }
Example #16
0
        private void RecvCommands()
        {
            while (true)
            {
                string line;
                try
                {
                    line = pckIn.ReadStringRaw();
                }
                catch (EndOfStreamException)
                {
                    if (commands.isEmpty())
                    {
                        return;
                    }
                    throw;
                }

                if (line == PacketLineIn.END)
                {
                    break;
                }

                if (commands.isEmpty())
                {
                    int nul = line.IndexOf('\0');
                    if (nul >= 0)
                    {
                        foreach (string c in line.Substring(nul + 1).Split(' '))
                        {
                            enabledCapabilities.Add(c);
                        }
                        line = line.Slice(0, nul);
                    }
                }

                if (line.Length < 83)
                {
                    string m = "error: invalid protocol: wanted 'old new ref'";
                    sendError(m);
                    throw new PackProtocolException(m);
                }

                ObjectId oldId = ObjectId.FromString(line.Slice(0, 40));
                ObjectId newId = ObjectId.FromString(line.Slice(41, 81));
                string   name  = line.Substring(82);
                var      cmd   = new ReceiveCommand(oldId, newId, name);

                if (name.Equals(Constants.HEAD))
                {
                    cmd.setResult(ReceiveCommand.Result.REJECTED_CURRENT_BRANCH);
                }
                else
                {
                    cmd.setRef(refs.get(cmd.getRefName()));
                }

                commands.Add(cmd);
            }
        }
Example #17
0
        public void testCheckout()
        {
            // Prepare tree, remote it and checkout
            var      index   = new GitIndex(db);
            FileInfo aslashb = writeTrashFile("a/b", "data:a/b");
            FileInfo acolonb = writeTrashFile("a@b", "data:a:b");
            FileInfo adotb   = writeTrashFile("a.b", "data:a.b");

            index.add(trash, aslashb);
            index.add(trash, acolonb);
            index.add(trash, adotb);
            index.write();
            index.writeTree();
            Delete(aslashb);
            Delete(acolonb);
            Delete(adotb);
            Delete(Directory.GetParent(aslashb.FullName));

            var index2 = new GitIndex(db);

            Assert.AreEqual(0, index2.Members.Count);

            index2.ReadTree(db.MapTree(ObjectId.FromString("0036d433dc4f10ec47b61abc3ec5033c78d34f84")));

            index2.checkout(trash);
            Assert.AreEqual("data:a/b", Content(aslashb));
            Assert.AreEqual("data:a:b", Content(acolonb));
            Assert.AreEqual("data:a.b", Content(adotb));

            if (CanRunGitStatus)
            {
                Assert.AreEqual(0, System(trash, "git status"));
            }
        }
Example #18
0
        public void test1()
        {
            FileInfo packFile = GetPack("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");

            using (Stream @is = packFile.Open(System.IO.FileMode.Open, FileAccess.Read))
            {
                var tmppack = new FileInfo(Path.Combine(trash.FullName, "tmp_pack1"));
                var pack    = new IndexPack(db, @is, tmppack);
                pack.index(new TextProgressMonitor());

                var idxFile     = new FileInfo(Path.Combine(trash.FullName, "tmp_pack1.idx"));
                var tmpPackFile = new FileInfo(Path.Combine(trash.FullName, "tmp_pack1.pack"));
                //return;
                using (var file = new PackFile(idxFile, tmpPackFile))
                {
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("540a36d136cf413e4b064c2b0e0a4db60f77feab")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799")));
                }
            }
        }
Example #19
0
        public virtual void TestReadTwoLine()
        {
            SetupReflog("logs/refs/heads/master", twoLine);
            ReflogReader reader = new ReflogReader(db, "refs/heads/master");
            IList <ReflogReader.Entry> reverseEntries = reader.GetReverseEntries();

            NUnit.Framework.Assert.AreEqual(2, reverseEntries.Count);
            ReflogReader.Entry 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());
            e = reverseEntries[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
                                                ());
        }
Example #20
0
        public void test2()
        {
            FileInfo packFile = GetPack("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack");

            using (Stream @is = packFile.Open(System.IO.FileMode.Open, FileAccess.Read))
            {
                var tmppack = new FileInfo(Path.Combine(trash.FullName, "tmp_pack2"));
                var pack    = new IndexPack(db, @is, tmppack);
                pack.index(new TextProgressMonitor());

                var idxFile     = new FileInfo(Path.Combine(trash.FullName, "tmp_pack2.idx"));
                var tmpPackFile = new FileInfo(Path.Combine(trash.FullName, "tmp_pack2.pack"));
                using (var file = new PackFile(idxFile, tmpPackFile))
                {
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("02ba32d3649e510002c21651936b7077aa75ffa9")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("0966a434eb1a025db6b71485ab63a3bfbea520b6")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("09efc7e59a839528ac7bda9fa020dc9101278680")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("0a3d7772488b6b106fb62813c4d6d627918d9181")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("1004d0d7ac26fbf63050a234c9b88a46075719d3")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("10da5895682013006950e7da534b705252b03be6")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("1203b03dc816ccbb67773f28b3c19318654b0bc8")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("15fae9e651043de0fd1deef588aa3fbf5a7a41c6")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("16f9ec009e5568c435f473ba3a1df732d49ce8c3")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("1fd7d579fb6ae3fe942dc09c2c783443d04cf21e")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("20a8ade77639491ea0bd667bf95de8abf3a434c8")));
                    Assert.IsTrue(file.HasObject(ObjectId.FromString("2675188fd86978d5bc4d7211698b2118ae3bf658")));
                    // and lots more...
                }
            }
        }
Example #21
0
        /// <exception cref="System.IO.IOException"></exception>
        private void ReadBundleV2()
        {
            byte[] hdrbuf = new byte[1024];
            LinkedHashMap <string, Ref> avail = new LinkedHashMap <string, Ref>();

            for (; ;)
            {
                string line = ReadLine(hdrbuf);
                if (line.Length == 0)
                {
                    break;
                }
                if (line[0] == '-')
                {
                    ObjectId id        = ObjectId.FromString(Sharpen.Runtime.Substring(line, 1, 41));
                    string   shortDesc = null;
                    if (line.Length > 42)
                    {
                        shortDesc = Sharpen.Runtime.Substring(line, 42);
                    }
                    prereqs.Put(id, shortDesc);
                    continue;
                }
                string   name  = Sharpen.Runtime.Substring(line, 41, line.Length);
                ObjectId id_1  = ObjectId.FromString(Sharpen.Runtime.Substring(line, 0, 40));
                Ref      prior = avail.Put(name, new ObjectIdRef.Unpeeled(RefStorage.NETWORK, name, id_1
                                                                          ));
                if (prior != null)
                {
                    throw DuplicateAdvertisement(name);
                }
            }
            Available(avail);
        }
        public void testBackwords_Prebuilts2()
        {
            // What is interesting about this test is the ObjectId for the
            // "darwin-x86" path entry ends in an octal digit (37 == '7').
            // Thus when scanning backwards we could over scan and consume
            // part of the SHA-1, and miss the path terminator.
            //
            ObjectId common = ObjectId
                              .FromString("af7bf97cb9bce3f60f1d651a0ef862e9447dd8bc");
            ObjectId darwinx86 = ObjectId
                                 .FromString("0000000000000000000000000000000000000037");
            ObjectId linuxx86 = ObjectId
                                .FromString("ac08dd97120c7cb7d06e98cd5b152011183baf21");
            ObjectId windows = ObjectId
                               .FromString("6c4c64c221a022bb973165192cca4812033479df");

            ctp.reset(mktree(Entry(mt, "common", common),
                             Entry(mt, "darwin-x86", darwinx86), Entry(mt, "linux-x86", linuxx86),
                             Entry(mt, "windows", windows)));
            ctp.next(3);
            Assert.AreEqual("windows", ctp.EntryPathString);
            Assert.AreSame(mt, ctp.EntryFileMode);
            Assert.AreEqual(windows, ctp.getEntryObjectId());

            ctp.back(1);
            Assert.AreEqual("linux-x86", ctp.EntryPathString);
            Assert.AreSame(mt, ctp.EntryFileMode);
            Assert.AreEqual(linuxx86, ctp.getEntryObjectId());

            ctp.next(1);
            Assert.AreEqual("windows", ctp.EntryPathString);
            Assert.AreSame(mt, ctp.EntryFileMode);
            Assert.AreEqual(windows, ctp.getEntryObjectId());
        }
        public virtual void RepositoryWithUninitializedSubmodule()
        {
            ObjectId       id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_125(id, path));
            editor.Commit();
            FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants
                                                                             .DOT_GIT_MODULES), db.FileSystem);

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_PATH, path);
            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, "git://server/repo.git");
            modulesConfig.Save();
            SubmoduleStatusCommand command = new SubmoduleStatusCommand(db);
            IDictionary <string, SubmoduleStatus> statuses = command.Call();

            NUnit.Framework.Assert.IsNotNull(statuses);
            NUnit.Framework.Assert.AreEqual(1, statuses.Count);
            KeyValuePair <string, SubmoduleStatus> module = statuses.EntrySet().Iterator().Next
                                                                ();

            NUnit.Framework.Assert.IsNotNull(module);
            NUnit.Framework.Assert.AreEqual(path, module.Key);
            SubmoduleStatus status = module.Value;

            NUnit.Framework.Assert.IsNotNull(status);
            NUnit.Framework.Assert.AreEqual(path, status.GetPath());
            NUnit.Framework.Assert.AreEqual(id, status.GetIndexId());
            NUnit.Framework.Assert.AreEqual(SubmoduleStatusType.UNINITIALIZED, status.GetType
                                                ());
        }
        public virtual void RepositoryWithUnconfiguredSubmodule()
        {
            ObjectId       id     = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string         path   = "sub";
            DirCache       cache  = db.LockDirCache();
            DirCacheEditor editor = cache.Editor();

            editor.Add(new _PathEdit_137(id, path));
            editor.Commit();
            FileBasedConfig modulesConfig = new FileBasedConfig(new FilePath(db.WorkTree, Constants
                                                                             .DOT_GIT_MODULES), db.FileSystem);

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_PATH, path);
            string url = "git://server/repo.git";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_URL, url);
            string update = "rebase";

            modulesConfig.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                    .CONFIG_KEY_UPDATE, update);
            modulesConfig.Save();
            SubmoduleUpdateCommand command = new SubmoduleUpdateCommand(db);
            ICollection <string>   updated = command.Call();

            NUnit.Framework.Assert.IsNotNull(updated);
            NUnit.Framework.Assert.IsTrue(updated.IsEmpty());
        }
Example #25
0
        public virtual void TestTreeIteratorWithGitmodules()
        {
            ObjectId subId      = ObjectId.FromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
            string   path       = "sub";
            Config   gitmodules = new Config();

            gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                 .CONFIG_KEY_PATH, "sub");
            gitmodules.SetString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants
                                 .CONFIG_KEY_URL, "git://example.com/sub");
            RevCommit commit = testDb.GetRevWalk().ParseCommit(testDb.Commit().NoParents().Add
                                                                   (Constants.DOT_GIT_MODULES, gitmodules.ToText()).Edit(new _PathEdit_397(subId, path
                                                                                                                                           )).Create());
            CanonicalTreeParser p = new CanonicalTreeParser();

            p.Reset(testDb.GetRevWalk().GetObjectReader(), commit.Tree);
            SubmoduleWalk gen = SubmoduleWalk.ForPath(db, p, "sub");

            NUnit.Framework.Assert.AreEqual(path, gen.GetPath());
            NUnit.Framework.Assert.AreEqual(subId, gen.GetObjectId());
            NUnit.Framework.Assert.AreEqual(new FilePath(db.WorkTree, path), gen.GetDirectory
                                                ());
            NUnit.Framework.Assert.IsNull(gen.GetConfigUpdate());
            NUnit.Framework.Assert.IsNull(gen.GetConfigUrl());
            NUnit.Framework.Assert.AreEqual("sub", gen.GetModulesPath());
            NUnit.Framework.Assert.IsNull(gen.GetModulesUpdate());
            NUnit.Framework.Assert.AreEqual("git://example.com/sub", gen.GetModulesUrl());
            NUnit.Framework.Assert.IsNull(gen.GetRepository());
            NUnit.Framework.Assert.IsFalse(gen.Next());
        }
Example #26
0
        public void test028_LockPackedRef()
        {
            writeTrashFile(".git/packed-refs", "7f822839a2fe9760f386cbbbcb3f92c5fe81def7 refs/heads/foobar");
            writeTrashFile(".git/HEAD", "ref: refs/heads/foobar\n");
            BUG_WorkAroundRacyGitIssues("packed-refs");
            BUG_WorkAroundRacyGitIssues("HEAD");

            ObjectId resolve = db.Resolve("HEAD");

            Assert.AreEqual("7f822839a2fe9760f386cbbbcb3f92c5fe81def7", resolve.Name);

            RefUpdate lockRef = db.UpdateRef("HEAD");
            ObjectId  newId   = ObjectId.FromString("07f822839a2fe9760f386cbbbcb3f92c5fe81def");

            lockRef.NewObjectId = newId;
            Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, lockRef.forceUpdate());

            Assert.IsTrue(new FileInfo(db.Directory.FullName + "/refs/heads/foobar").Exists);
            Assert.AreEqual(newId, db.Resolve("refs/heads/foobar"));

            // Again. The ref already exists
            RefUpdate lockRef2 = db.UpdateRef("HEAD");
            ObjectId  newId2   = ObjectId.FromString("7f822839a2fe9760f386cbbbcb3f92c5fe81def7");

            lockRef2.NewObjectId = newId2;
            Assert.AreEqual(RefUpdate.RefUpdateResult.FORCED, lockRef2.forceUpdate());

            Assert.IsTrue(new FileInfo(db.Directory.FullName + "/refs/heads/foobar").Exists);
            Assert.AreEqual(newId2, db.Resolve("refs/heads/foobar"));
        }
Example #27
0
        /// <exception cref="System.IO.IOException"></exception>
        private void WriteVerifyPack4(bool thin)
        {
            List <ObjectId> interestings = new List <ObjectId>();

            interestings.AddItem(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"
                                                     ));
            List <ObjectId> uninterestings = new List <ObjectId>();

            uninterestings.AddItem(ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799"
                                                       ));
            CreateVerifyOpenPack(interestings, uninterestings, thin, false);
            ObjectId[] writtenObjects = new ObjectId[] { ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"
                                                                             ), ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035"), ObjectId.FromString
                                                             ("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259") };
            NUnit.Framework.Assert.AreEqual(writtenObjects.Length, writer.GetObjectsNumber());
            ObjectId[] expectedObjects;
            if (thin)
            {
                expectedObjects = new ObjectId[4];
                System.Array.Copy(writtenObjects, 0, expectedObjects, 0, writtenObjects.Length);
                expectedObjects[3] = ObjectId.FromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3"
                                                         );
            }
            else
            {
                expectedObjects = writtenObjects;
            }
            VerifyObjectsOrder(expectedObjects);
            NUnit.Framework.Assert.AreEqual("cded4b74176b4456afa456768b2b5aafb41c44fc", writer
                                            .ComputeName().Name);
        }
Example #28
0
 public void test029_mapObject()
 {
     Assert.AreEqual((new byte[0].GetType()), db.MapObject(ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"), null).GetType());
     Assert.AreEqual(typeof(global::GitSharp.Core.Commit), db.MapObject(ObjectId.FromString("540a36d136cf413e4b064c2b0e0a4db60f77feab"), null).GetType());
     Assert.AreEqual(typeof(global::GitSharp.Core.Tree), db.MapObject(ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035"), null).GetType());
     Assert.AreEqual(typeof(global::GitSharp.Core.Tag), db.MapObject(ObjectId.FromString("17768080a2318cd89bba4c8b87834401e2095703"), null).GetType());
 }
Example #29
0
        public void testParseAbbrIndexLine_NoMode()
        {
            const int    a   = 7;
            const string oid = "78981922613b2afb6025042ff6bd878ac1994e85";
            const string nid = "61780798228d17af2d34fce4cfbdf35556832472";
            FileHeader   fh  = Data("diff --git a/a b/a\n" + "index "
                                    + oid.Substring(0, a - 1) + ".." + nid.Substring(0, a - 1)
                                    + "\n" + "--- a/a\n" + "+++ b/a\n");

            AssertParse(fh);

            Assert.AreEqual("a", fh.OldName);
            Assert.AreEqual("a", fh.NewName);

            Assert.IsNull(fh.GetOldMode());
            Assert.IsNull(fh.NewMode);
            Assert.IsFalse(fh.hasMetaDataChanges());

            Assert.IsNotNull(fh.getOldId());
            Assert.IsNotNull(fh.getNewId());

            Assert.IsFalse(fh.getOldId().isComplete());
            Assert.IsFalse(fh.getNewId().isComplete());

            Assert.AreEqual(oid.Substring(0, a - 1), fh.getOldId().name());
            Assert.AreEqual(nid.Substring(0, a - 1), fh.getNewId().name());

            Assert.IsTrue(ObjectId.FromString(oid).startsWith(fh.getOldId()));
            Assert.IsTrue(ObjectId.FromString(nid).startsWith(fh.getNewId()));
        }
Example #30
0
        public void ObjectIdToStringTest()
        {
            var id = ObjectId.FromString("003ae55c8f6f23aaee66acd2e1c35523fa6ddc33");

            Assert.AreEqual("003ae55c8f6f23aaee66acd2e1c35523fa6ddc33", id.ToString());
            Assert.AreEqual(0, id.GetFirstByte());
        }