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
        public void testConstructor_PeeledStatusNotKnown()
        {
            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 Unpeeled(Storage.Packed, name, ID_A);
            Assert.AreSame(Storage.Packed, r.getStorage());

            r = new Unpeeled(Storage.LoosePacked, name, ID_A);
            Assert.AreSame(Storage.LoosePacked, r.getStorage());

            r = new Unpeeled(Storage.New, name, null);
            Assert.AreSame(Storage.New, 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(r, r.getLeaf(), "leaf is this");
            Assert.AreSame(r, r.getTarget(), "target is this");
            Assert.IsFalse(r.isSymbolic(), "not symbolic");
        }
Exemplo n.º 3
0
        public void ShouldReturnValueForAValidRef()
        {
            var result = new PushResult();
            var r = new Unpeeled(null, "ref", ObjectId.ZeroId);

            result.AdvertisedRefs.Add("ref", r);

            Assert.AreEqual(r, result.GetAdvertisedRef("ref"));
        }
Exemplo n.º 4
0
        public void ShouldReturnValueForAValidRef()
        {
            var connection = new StubConnection();
            var r = new Unpeeled(null, "ref", ObjectId.ZeroId);

            connection.RefsMap.Add("ref", r);

            Assert.AreEqual(r, connection.GetRef("ref"));
        }
Exemplo n.º 5
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"));
        }
Exemplo n.º 6
0
 public void testPushResult()
 {
     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();
     Assert.AreEqual(1, result.TrackingRefUpdates.Count);
     Assert.AreEqual(1, result.AdvertisedRefs.Count);
     Assert.AreEqual(1, result.RemoteUpdates.Count);
     Assert.IsNotNull(result.GetTrackingRefUpdate("refs/remotes/test/master"));
     Assert.IsNotNull(result.GetAdvertisedRef("refs/heads/master"));
     Assert.IsNotNull(result.GetRemoteUpdate("refs/heads/master"));
 }
Exemplo n.º 7
0
        public override RefUpdate newUpdate(string name, bool detach)
        {
            RefList <Ref> packed = getPackedRefs();
            Ref           @ref   = readRef(name, packed);

            if (@ref != null)
            {
                @ref = resolve(@ref, 0, null, null, packed);
            }
            if (@ref == null)
            {
                @ref = new Unpeeled(Storage.New, name, null);
            }
            else if (detach && @ref.isSymbolic())
            {
                @ref = new Unpeeled(Storage.Loose, name, @ref.getObjectId());
            }
            return(new RefDirectoryUpdate(this, @ref));
        }
Exemplo n.º 8
0
        public void testDeleteMaster()
        {
            string sn = "refs/heads/master";
            RefSpec rs = new RefSpec(":" + sn);
            Assert.IsFalse(rs.Force);
            Assert.IsFalse(rs.Wildcard);
            Assert.AreEqual(sn, rs.Destination);
            Assert.IsNull(rs.Source);
            Assert.AreEqual(":" + sn, rs.ToString());
            Assert.AreEqual(rs, new RefSpec(rs.ToString()));

            Core.Ref r = new Unpeeled(Storage.Loose, sn, null);
            Assert.IsFalse(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));
        }
Exemplo n.º 9
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());
        }
Exemplo n.º 10
0
        private static RefList <Ref> parsePackedRefs(TextReader br)
        {
            var all = new RefList <Ref> .Builder <Ref>();

            Ref  last     = null;
            bool peeled   = false;
            bool needSort = false;

            string p;

            while ((p = br.ReadLine()) != null)
            {
                if (p[0] == '#')
                {
                    if (p.StartsWith(PACKED_REFS_HEADER))
                    {
                        p      = p.Substring(PACKED_REFS_HEADER.Length);
                        peeled = p.Contains(PACKED_REFS_PEELED);
                    }
                    continue;
                }

                if (p[0] == '^')
                {
                    if (last == null)
                    {
                        throw new IOException("Peeled line before ref.");
                    }

                    ObjectId id = ObjectId.FromString(p.Substring(1));
                    last = new PeeledTag(Storage.Packed, last.getName(), last
                                         .getObjectId(), id);
                    all.set(all.size() - 1, last);
                    continue;
                }

                int         sp   = p.IndexOf(' ');
                ObjectId    id2  = ObjectId.FromString(p.Slice(0, sp));
                string      name = copy(p, sp + 1, p.Length);
                ObjectIdRef cur;
                if (peeled)
                {
                    cur = new PeeledNonTag(Storage.Packed, name, id2);
                }
                else
                {
                    cur = new Unpeeled(Storage.Packed, name, id2);
                }
                if (last != null && RefComparator.compareTo(last, cur) > 0)
                {
                    needSort = true;
                }
                all.add(cur);
                last = cur;
            }

            if (needSort)
            {
                all.sort();
            }
            return(all.toRefList());
        }
Exemplo n.º 11
0
        public void testForceRemotesOrigin()
        {
            string srcn = "refs/heads/*";
            string dstn = "refs/remotes/origin/*";
            RefSpec rs = new RefSpec("+" + srcn + ":" + dstn);
            Assert.IsTrue(rs.Force);
            Assert.IsTrue(rs.Wildcard);
            Assert.AreEqual(srcn, rs.Source);
            Assert.AreEqual(dstn, rs.Destination);
            Assert.AreEqual("+" + srcn + ":" + dstn, rs.ToString());
            Assert.AreEqual(rs, new RefSpec(rs.ToString()));

            Core.Ref r;
            RefSpec expanded;

            r = new Unpeeled(Storage.Loose, "refs/heads/master", null);
            Assert.IsTrue(rs.MatchSource(r));
            Assert.IsFalse(rs.MatchDestination(r));
            expanded = rs.ExpandFromSource(r);
            Assert.AreNotSame(rs, expanded);
            Assert.IsTrue(expanded.Force);
            Assert.IsFalse(expanded.Wildcard);
            Assert.AreEqual(r.Name, expanded.Source);
            Assert.AreEqual("refs/remotes/origin/master", expanded.Destination);

            r = new Unpeeled(Storage.Loose, "refs/remotes/origin/next", null);
            Assert.IsFalse(rs.MatchSource(r));
            Assert.IsTrue(rs.MatchDestination(r));

            r = new Unpeeled(Storage.Loose, "refs/tags/v1.0", null);
            Assert.IsFalse(rs.MatchSource(r));
            Assert.IsFalse(rs.MatchDestination(r));
        }
Exemplo n.º 12
0
 public void testUpdateNonFastForwardForced()
 {
     RemoteRefUpdate rru = new RemoteRefUpdate(db, "ac7e7e44c1885efb472ad54a78327d66bfc4ecef",
                                   "refs/heads/master", true, null, null);
     Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9"));
     testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.OK, false);
 }
Exemplo n.º 13
0
        public void testToString()
        {
            ObjectIdRef r;

            r = new Unpeeled(Storage.Loose, name, ID_A);
            Assert.AreEqual("Ref[" + name + "=" + ID_A.Name + "]", r.ToString());
        }
Exemplo n.º 14
0
 public void testUpdateUnexpectedRemoteVsForce()
 {
     RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9",
                                   "refs/heads/master", true, null,
                                   ObjectId.FromString("0000000000000000000000000000000000000001"));
     Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("ac7e7e44c1885efb472ad54a78327d66bfc4ecef"));
     testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.REJECTED_REMOTE_CHANGED, null);
 }
Exemplo n.º 15
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);
 }
Exemplo n.º 16
0
 public void testUpdateRejectedByConnection()
 {
     connectionUpdateStatus = RemoteRefUpdate.UpdateStatus.REJECTED_OTHER_REASON;
     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"));
     testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.REJECTED_OTHER_REASON, null);
 }
Exemplo n.º 17
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);
 }
Exemplo n.º 18
0
 public void testUpdateNonFastForwardUnknownObject()
 {
     RemoteRefUpdate rru = new RemoteRefUpdate(db, "2c349335b7f797072cf729c4f3bb0914ecb6dec9",
                                               "refs/heads/master", false, null, null);
     Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("0000000000000000000000000000000000000001"));
     testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.REJECTED_NONFASTFORWARD, null);
 }
Exemplo n.º 19
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);
 }
Exemplo n.º 20
0
 public void testTrackingRefUpdateOnReject()
 {
     RemoteRefUpdate rru = new RemoteRefUpdate(db, "ac7e7e44c1885efb472ad54a78327d66bfc4ecef", "refs/heads/master", false, null, null);
     Core.Ref @ref = new Unpeeled(Storage.Loose, "refs/heads/master", ObjectId.FromString("2c349335b7f797072cf729c4f3bb0914ecb6dec9"));
     PushResult result = testOneUpdateStatus(rru, @ref, RemoteRefUpdate.UpdateStatus.REJECTED_NONFASTFORWARD, null);
     Assert.IsTrue(result.TrackingRefUpdates.Count == 0);
 }