MapObject() public method

Access any type of Git object by id and
public MapObject ( ObjectId id, string refName ) : object
id ObjectId SHA-1 of object to read
refName string optional, only relevant for simple tags
return object
Ejemplo n.º 1
0
        /// <summary>
        /// Returns the object that this object points to if this is a commit.
        /// </summary>
        /// <param name="dref">The ref.</param>
        /// <returns></returns>
        internal Ref Peel(Ref dref)
        {
            if (dref.Peeled)
            {
                return(dref);
            }

            ObjectId peeled = null;

            try
            {
                Tag target = (Repository.MapObject(dref.ObjectId, dref.Name) as Tag);

                while (target != null)
                {
                    peeled = target.Id;

                    if (target.TagType == Constants.TYPE_TAG)
                    {
                        target = (Repository.MapObject(target.Id, dref.Name) as Tag);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (IOException)
            {
                // Ignore a read error.  Callers will also get the same error
                // if they try to use the result of getPeeledObjectId.
            }
            return(new Ref(dref.StorageFormat, dref.Name, dref.ObjectId, peeled, true));
        }
        public void CanReadMsysgitIndex()
        {
            //setup of .git directory
            var resource =
                new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"),
                                               "OneFileRepository"));
            var tempRepository =
                new DirectoryInfo(Path.Combine(trash.FullName, "OneFileRepository" + Path.GetRandomFileName()));
            CopyDirectory(resource.FullName, tempRepository.FullName);

            var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, ".git"));
            Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName);

            var repository = new Repository(repositoryPath);
            GitIndex index = repository.Index;

            Assert.IsNotNull(index);
            List<GitIndex.Entry> entries = index.Members.ToList();
            Assert.AreEqual(1, entries.Count);

            GitIndex.Entry entry = entries[0];
            Assert.AreEqual("dummy.txt", entry.Name);

            Ref headRef = repository.Head;
            Assert.AreEqual("refs/heads/master", headRef.Name);
            Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", headRef.ObjectId.Name);

            object obj = repository.MapObject(headRef.ObjectId, headRef.OriginalName);
            Assert.IsInstanceOfType(typeof(Commit), obj);
            var commit = (Commit) obj;

            Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", commit.CommitId.Name);
            Assert.AreEqual(commit.Committer, commit.Author);
            Assert.AreEqual("nulltoken <*****@*****.**> 1255117188 +0200", commit.Committer.ToExternalString());

            Assert.AreEqual(0, commit.ParentIds.Length);
        }