Exemplo n.º 1
0
        public void testConstructor()
        {
            global::GitSharp.Core.Ref t;
            SymbolicRef r;

            t = new Unpeeled(Storage.New, targetName, null);
            r = new SymbolicRef(name, t);
            Assert.AreSame(Storage.Loose, r.getStorage());
            Assert.AreSame(name, r.getName());
            Assert.IsNull(r.getObjectId(), "no id on new ref");
            Assert.IsFalse(r.isPeeled(), "not peeled");
            Assert.IsNull(r.getPeeledObjectId(), "no peel id");
            Assert.AreSame(t, r.getLeaf(), "leaf is t");
            Assert.AreSame(t, r.getTarget(), "target is t");
            Assert.IsTrue(r.isSymbolic(), "is symbolic");

            t = new Unpeeled(Storage.Packed, targetName, ID_A);
            r = new SymbolicRef(name, t);
            Assert.AreSame(Storage.Loose, r.getStorage());
            Assert.AreSame(name, r.getName());
            Assert.AreSame(ID_A, r.getObjectId());
            Assert.IsFalse(r.isPeeled(), "not peeled");
            Assert.IsNull(r.getPeeledObjectId(), "no peel id");
            Assert.AreSame(t, r.getLeaf(), "leaf is t");
            Assert.AreSame(t, r.getTarget(), "target is t");
            Assert.IsTrue(r.isSymbolic(), "is symbolic");
        }
Exemplo n.º 2
0
            private Ref ReadRef(IDictionary <string, Ref> avail, string path, string name)
            {
                string line;

                try
                {
                    using (StreamReader br = openReader(path))
                    {
                        line = br.ReadLine();
                    }
                }
                catch (FileNotFoundException)
                {
                    return(null);
                }
                catch (IOException err)
                {
                    throw new TransportException("Cannot Read " + _objectsPath + "/" + path + ": " + err.Message, err);
                }

                if (line == null)
                {
                    throw new TransportException("Empty ref: " + name);
                }

                if (line.StartsWith("ref: "))
                {
                    string target = line.Substring("ref: ".Length);
                    Ref    r      = avail.GetValue(target);
                    if (r == null)
                    {
                        r = ReadRef(avail, ROOT_DIR + target, target);
                    }
                    if (r == null)
                    {
                        r = new Unpeeled(Storage.New, target, null);
                    }
                    r = new SymbolicRef(name, r);
                    avail.put(r.getName(), r);
                    return(r);
                }

                if (ObjectId.IsId(line))
                {
                    Ref r = new Unpeeled(Loose(avail.GetValue(name)),
                                         name, ObjectId.FromString(line));
                    avail.put(r.getName(), r);
                    return(r);
                }

                throw new TransportException("Bad ref: " + name + ": " + line);
            }
Exemplo n.º 3
0
            private Ref ReadRef(IDictionary<string, Ref> avail, string path, string name)
            {
                string line;
                try
                {
                    using (StreamReader br = openReader(path))
                    {
                        line = br.ReadLine();
                    }
                }
                catch (FileNotFoundException)
                {
                    return null;
                }
                catch (IOException err)
                {
                    throw new TransportException("Cannot Read " + _objectsPath + "/" + path + ": " + err.Message, err);
                }

                if (line == null)
                    throw new TransportException("Empty ref: " + name);

                if (line.StartsWith("ref: "))
                {
                    string target = line.Substring("ref: ".Length);
                    Ref r = avail.GetValue(target);
                    if (r == null)
                        r = ReadRef(avail, ROOT_DIR + target, target);
                    if (r == null)
                        r = new Unpeeled(Storage.New, target, null);
                    r = new SymbolicRef(name, r);
                    avail.put(r.getName(), r);
                    return r;
                }

                if (ObjectId.IsId(line))
                {
                    Ref r = new Unpeeled(Loose(avail.GetValue(name)),
                            name, ObjectId.FromString(line));
                    avail.put(r.getName(), r);
                    return r;
                }

                throw new TransportException("Bad ref: " + name + ": " + line);
            }