Example #1
0
        public void testTrackingRefUpdateDisabled()
        {
            RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", "refs/heads/master", false, null, null);

            Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef"));
            refUpdates.Add(rru);
            advertisedRefs.Add(@ref);
            PushResult result = executePush();

            Assert.IsTrue(result.TrackingRefUpdates.Count == 0);
        }
Example #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);
            }
Example #3
0
        public void ShouldReturnValueForAValidRef()
        {
            var result = new PushResult();
            var r      = new Unpeeled(null, "ref", ObjectId.ZeroId);

            var refs    = result.AdvertisedRefs;
            var advRefs = refs.ToDictionary(@ref => @ref.Name);

            advRefs.Add("ref", r);

            result.SetAdvertisedRefs(result.URI, advRefs);

            Assert.AreEqual(r, result.GetAdvertisedRef("ref"));
        }
Example #4
0
        public void testTrackingRefUpdateEnabled()
        {
            RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", "refs/heads/master", false, "refs/remotes/test/master", null);

            Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef"));
            refUpdates.Add(rru);
            advertisedRefs.Add(@ref);
            PushResult        result = executePush();
            TrackingRefUpdate tru    = result.GetTrackingRefUpdate("refs/remotes/test/master");

            Assert.IsNotNull(tru);
            Assert.AreEqual("refs/remotes/test/master", tru.LocalName);
            Assert.AreEqual(RefUpdate.RefUpdateResult.NEW, tru.Result);
        }
Example #5
0
        public void testUpdateMixedCases()
        {
            RemoteRefUpdate rruOk = new RemoteRefUpdate(db, null, "refs/heads/master", false, null, null);

            Core.Ref        refToChange = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9"));
            RemoteRefUpdate rruReject   = new RemoteRefUpdate(db, null, "refs/heads/nonexisting", false, null, null);

            refUpdates.Add(rruOk);
            refUpdates.Add(rruReject);
            advertisedRefs.Add(refToChange);
            executePush();
            Assert.AreEqual(RemoteRefUpdate.UpdateStatus.OK, rruOk.Status);
            Assert.AreEqual(true, rruOk.FastForward);
            Assert.AreEqual(RemoteRefUpdate.UpdateStatus.NON_EXISTING, rruReject.Status);
        }
Example #6
0
        public void testForceMasterMaster()
        {
            string  sn = "refs/heads/master";
            RefSpec rs = new RefSpec("+" + sn + ":" + sn);

            Assert.IsTrue(rs.Force);
            Assert.IsFalse(rs.Wildcard);
            Assert.AreEqual(sn, rs.Source);
            Assert.AreEqual(sn, rs.Destination);
            Assert.AreEqual("+" + sn + ":" + sn, rs.ToString());
            Assert.AreEqual(rs, new RefSpec(rs.ToString()));

            Core.Ref r = new Unpeeled(Storage.Loose, sn, null);
            Assert.IsTrue(rs.MatchSource(r));
            Assert.IsTrue(rs.MatchDestination(r));
            Assert.AreSame(rs, rs.ExpandFromSource(r));

            r = new Unpeeled(Storage.Loose, sn + "-and-more", null);
            Assert.IsFalse(rs.MatchSource(r));
            Assert.IsFalse(rs.MatchDestination(r));
        }
Example #7
0
        public void testConstructor_Peeled()
        {
            ObjectIdRef r;

            r = new Unpeeled(Storage.Loose, name, ID_A);
            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(r, r.getLeaf(), "leaf is this");
            Assert.AreSame(r, r.getTarget(), "target is this");
            Assert.IsFalse(r.isSymbolic(), "not symbolic");

            r = new PeeledNonTag(Storage.Loose, name, ID_A);
            Assert.IsTrue(r.isPeeled(), "is peeled");
            Assert.IsNull(r.getPeeledObjectId(), "no peel id");

            r = new PeeledTag(Storage.Loose, name, ID_A, ID_B);
            Assert.IsTrue(r.isPeeled(), "is peeled");
            Assert.AreSame(ID_B, r.getPeeledObjectId());
        }
        private static void readPackedRefsImpl(Dictionary<string, Ref> avail, StreamReader sr)
        {
            Ref last = null;
            bool peeled = false;
            for (; ; )
            {
                string line = sr.ReadLine();

                if (line == null)
                    break;
                if (line[0] == '#')
                {
                    if (line.StartsWith(RefDirectory.PACKED_REFS_HEADER))
                    {
                        line = line.Substring(RefDirectory.PACKED_REFS_HEADER.Length);
                        peeled = line.Contains(RefDirectory.PACKED_REFS_PEELED);
                    }
                    continue;
                }

                if (line[0] == '^')
                {
                    if (last == null)
                        throw new TransportException("Peeled line before ref");
                    ObjectId pid = ObjectId.FromString(line.Substring(1));
                    last = new PeeledTag(Storage.Packed, last.Name, last.ObjectId, pid);
                    avail.put(last.Name, last);
                    continue;
                }

                int sp = line.IndexOf(' ');
                if (sp < 0)
                    throw new TransportException("Unrecognized ref: " + line);
                ObjectId id = ObjectId.FromString(line.Slice(0, sp));
                string name = line.Substring(sp + 1);
                if (peeled)
                    last = new PeeledNonTag(Storage.Packed, name, id);
                else
                    last = new Unpeeled(Storage.Packed, name, id);

                avail.put(last.Name, last);
            }
        }
Example #9
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);
            }
        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 Unpeeled(Storage.Network, name, id);
                if (avail.ContainsKey(name))
                {
                    throw duplicateAdvertisement(name);
                }
                avail.Add(name, prior);
            }
            available(avail);
        }