Ejemplo n.º 1
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void ExpandSingle(RefSpec spec, ICollection <Ref> matched)
        {
            Ref src = conn.GetRef(spec.GetSource());

            if (src == null)
            {
                throw new TransportException(MessageFormat.Format(JGitText.Get().remoteDoesNotHaveSpec
                                                                  , spec.GetSource()));
            }
            if (matched.AddItem(src))
            {
                Want(src, spec);
            }
        }
Ejemplo n.º 2
0
        public virtual void TestForceRemotesOrigin()
        {
            string  srcn = "refs/heads/*";
            string  dstn = "refs/remotes/origin/*";
            RefSpec rs   = new RefSpec("+" + srcn + ":" + dstn);

            NUnit.Framework.Assert.IsTrue(rs.IsForceUpdate());
            NUnit.Framework.Assert.IsTrue(rs.IsWildcard());
            NUnit.Framework.Assert.AreEqual(srcn, rs.GetSource());
            NUnit.Framework.Assert.AreEqual(dstn, rs.GetDestination());
            NUnit.Framework.Assert.AreEqual("+" + srcn + ":" + dstn, rs.ToString());
            NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString()));
            Ref     r;
            RefSpec expanded;

            r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", null);
            NUnit.Framework.Assert.IsTrue(rs.MatchSource(r));
            NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r));
            expanded = rs.ExpandFromSource(r);
            NUnit.Framework.Assert.AreNotSame(rs, expanded);
            NUnit.Framework.Assert.IsTrue(expanded.IsForceUpdate());
            NUnit.Framework.Assert.IsFalse(expanded.IsWildcard());
            NUnit.Framework.Assert.AreEqual(r.GetName(), expanded.GetSource());
            NUnit.Framework.Assert.AreEqual("refs/remotes/origin/master", expanded.GetDestination
                                                ());
            r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/remotes/origin/next", null);
            NUnit.Framework.Assert.IsFalse(rs.MatchSource(r));
            NUnit.Framework.Assert.IsTrue(rs.MatchDestination(r));
            r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/tags/v1.0", null);
            NUnit.Framework.Assert.IsFalse(rs.MatchSource(r));
            NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r));
        }
Ejemplo n.º 3
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private TrackingRefUpdate CreateUpdate(RefSpec spec, ObjectId newId)
        {
            Ref      @ref  = LocalRefs().Get(spec.GetDestination());
            ObjectId oldId = @ref != null && @ref.GetObjectId() != null? @ref.GetObjectId() :
                                 ObjectId.ZeroId;

            return(new TrackingRefUpdate(spec.IsForceUpdate(), spec.GetSource(), spec.GetDestination
                                             (), oldId, newId));
        }
Ejemplo n.º 4
0
        public virtual void TestCreateEmpty()
        {
            RefSpec rs = new RefSpec();

            NUnit.Framework.Assert.IsFalse(rs.IsForceUpdate());
            NUnit.Framework.Assert.IsFalse(rs.IsWildcard());
            NUnit.Framework.Assert.AreEqual("HEAD", rs.GetSource());
            NUnit.Framework.Assert.IsNull(rs.GetDestination());
            NUnit.Framework.Assert.AreEqual("HEAD", rs.ToString());
        }
Ejemplo n.º 5
0
		public virtual void TestSplitLastColon()
		{
			string lhs = ":m:a:i:n:t";
			string rhs = "refs/heads/maint";
			RefSpec rs = new RefSpec(lhs + ":" + rhs);
			NUnit.Framework.Assert.IsFalse(rs.IsForceUpdate());
			NUnit.Framework.Assert.IsFalse(rs.IsWildcard());
			NUnit.Framework.Assert.AreEqual(lhs, rs.GetSource());
			NUnit.Framework.Assert.AreEqual(rhs, rs.GetDestination());
			NUnit.Framework.Assert.AreEqual(lhs + ":" + rhs, rs.ToString());
			NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString()));
		}
Ejemplo n.º 6
0
        public virtual void TestExpandFromDestination_Wildcard()
        {
            string  src = "refs/heads/master";
            string  dst = "refs/remotes/origin/master";
            RefSpec a   = new RefSpec("refs/heads/*:refs/remotes/origin/*");
            RefSpec r   = a.ExpandFromDestination(dst);

            NUnit.Framework.Assert.AreNotSame(a, r);
            NUnit.Framework.Assert.IsFalse(r.IsWildcard());
            NUnit.Framework.Assert.AreEqual(src, r.GetSource());
            NUnit.Framework.Assert.AreEqual(dst, r.GetDestination());
        }
Ejemplo n.º 7
0
        private void DeleteTrackingRef(FetchResult result, BatchRefUpdate batch, RefSpec
                                       spec, Ref localRef)
        {
            if (localRef.GetObjectId() == null)
            {
                return;
            }
            TrackingRefUpdate update = new TrackingRefUpdate(true, spec.GetSource(), localRef
                                                             .GetName(), localRef.GetObjectId(), ObjectId.ZeroId);

            result.Add(update);
            batch.AddCommand(update.AsReceiveCommand());
        }
Ejemplo n.º 8
0
        public virtual void TestSplitLastColon()
        {
            string  lhs = ":m:a:i:n:t";
            string  rhs = "refs/heads/maint";
            RefSpec rs  = new RefSpec(lhs + ":" + rhs);

            NUnit.Framework.Assert.IsFalse(rs.IsForceUpdate());
            NUnit.Framework.Assert.IsFalse(rs.IsWildcard());
            NUnit.Framework.Assert.AreEqual(lhs, rs.GetSource());
            NUnit.Framework.Assert.AreEqual(rhs, rs.GetDestination());
            NUnit.Framework.Assert.AreEqual(lhs + ":" + rhs, rs.ToString());
            NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString()));
        }
Ejemplo n.º 9
0
		public virtual void TestMasterMaster()
		{
			string sn = "refs/heads/master";
			RefSpec rs = new RefSpec(sn + ":" + sn);
			NUnit.Framework.Assert.IsFalse(rs.IsForceUpdate());
			NUnit.Framework.Assert.IsFalse(rs.IsWildcard());
			NUnit.Framework.Assert.AreEqual(sn, rs.GetSource());
			NUnit.Framework.Assert.AreEqual(sn, rs.GetDestination());
			NUnit.Framework.Assert.AreEqual(sn + ":" + sn, rs.ToString());
			NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString()));
			Ref r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, sn, null);
			NUnit.Framework.Assert.IsTrue(rs.MatchSource(r));
			NUnit.Framework.Assert.IsTrue(rs.MatchDestination(r));
			NUnit.Framework.Assert.AreSame(rs, rs.ExpandFromSource(r));
			r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, sn + "-and-more", null);
			NUnit.Framework.Assert.IsFalse(rs.MatchSource(r));
			NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r));
		}
Ejemplo n.º 10
0
 /// <exception cref="System.IO.IOException"></exception>
 private void DeleteStaleTrackingRefs(FetchResult result, BatchRefUpdate batch)
 {
     foreach (Ref @ref in LocalRefs().Values)
     {
         string refname = @ref.GetName();
         foreach (RefSpec spec in toFetch)
         {
             if (spec.MatchDestination(refname))
             {
                 RefSpec s = spec.ExpandFromDestination(refname);
                 if (result.GetAdvertisedRef(s.GetSource()) == null)
                 {
                     DeleteTrackingRef(result, batch, s, @ref);
                 }
             }
         }
     }
 }
Ejemplo n.º 11
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void DeleteStaleTrackingRefs(FetchResult result, RevWalk walk)
        {
            Repository db = transport.local;

            foreach (Ref @ref in db.GetAllRefs().Values)
            {
                string refname = @ref.GetName();
                foreach (RefSpec spec in toFetch)
                {
                    if (spec.MatchDestination(refname))
                    {
                        RefSpec s = spec.ExpandFromDestination(refname);
                        if (result.GetAdvertisedRef(s.GetSource()) == null)
                        {
                            DeleteTrackingRef(result, db, walk, s, @ref);
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public virtual void TestForceMasterMaster()
        {
            string  sn = "refs/heads/master";
            RefSpec rs = new RefSpec("+" + sn + ":" + sn);

            NUnit.Framework.Assert.IsTrue(rs.IsForceUpdate());
            NUnit.Framework.Assert.IsFalse(rs.IsWildcard());
            NUnit.Framework.Assert.AreEqual(sn, rs.GetSource());
            NUnit.Framework.Assert.AreEqual(sn, rs.GetDestination());
            NUnit.Framework.Assert.AreEqual("+" + sn + ":" + sn, rs.ToString());
            NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString()));
            Ref r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, sn, null);

            NUnit.Framework.Assert.IsTrue(rs.MatchSource(r));
            NUnit.Framework.Assert.IsTrue(rs.MatchDestination(r));
            NUnit.Framework.Assert.AreSame(rs, rs.ExpandFromSource(r));
            r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, sn + "-and-more", null);
            NUnit.Framework.Assert.IsFalse(rs.MatchSource(r));
            NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r));
        }
Ejemplo n.º 13
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void DeleteTrackingRef(FetchResult result, Repository db, RevWalk walk, RefSpec
                                       spec, Ref localRef)
        {
            string name = localRef.GetName();

            try
            {
                TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.GetSource(), true, ObjectId
                                                            .ZeroId, "deleted");
                result.Add(u);
                if (transport.IsDryRun())
                {
                    return;
                }
                u.Delete(walk);
                switch (u.GetResult())
                {
                case RefUpdate.Result.NEW:
                case RefUpdate.Result.NO_CHANGE:
                case RefUpdate.Result.FAST_FORWARD:
                case RefUpdate.Result.FORCED:
                {
                    break;
                }

                default:
                {
                    throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get
                                                                                              ().cannotDeleteStaleTrackingRef2, name, u.GetResult().ToString()));
                }
                }
            }
            catch (IOException e)
            {
                throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get
                                                                                          ().cannotDeleteStaleTrackingRef, name), e);
            }
        }
Ejemplo n.º 14
0
		private void DeleteTrackingRef(FetchResult result, BatchRefUpdate batch, RefSpec 
			spec, Ref localRef)
		{
			if (localRef.GetObjectId() == null)
			{
				return;
			}
			TrackingRefUpdate update = new TrackingRefUpdate(true, spec.GetSource(), localRef
				.GetName(), localRef.GetObjectId(), ObjectId.ZeroId);
			result.Add(update);
			batch.AddCommand(update.AsReceiveCommand());
		}
Ejemplo n.º 15
0
		public virtual void TestCreateEmpty()
		{
			RefSpec rs = new RefSpec();
			NUnit.Framework.Assert.IsFalse(rs.IsForceUpdate());
			NUnit.Framework.Assert.IsFalse(rs.IsWildcard());
			NUnit.Framework.Assert.AreEqual("HEAD", rs.GetSource());
			NUnit.Framework.Assert.IsNull(rs.GetDestination());
			NUnit.Framework.Assert.AreEqual("HEAD", rs.ToString());
		}
Ejemplo n.º 16
0
		public virtual void TestForceRemotesOrigin()
		{
			string srcn = "refs/heads/*";
			string dstn = "refs/remotes/origin/*";
			RefSpec rs = new RefSpec("+" + srcn + ":" + dstn);
			NUnit.Framework.Assert.IsTrue(rs.IsForceUpdate());
			NUnit.Framework.Assert.IsTrue(rs.IsWildcard());
			NUnit.Framework.Assert.AreEqual(srcn, rs.GetSource());
			NUnit.Framework.Assert.AreEqual(dstn, rs.GetDestination());
			NUnit.Framework.Assert.AreEqual("+" + srcn + ":" + dstn, rs.ToString());
			NUnit.Framework.Assert.AreEqual(rs, new RefSpec(rs.ToString()));
			Ref r;
			RefSpec expanded;
			r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/heads/master", null);
			NUnit.Framework.Assert.IsTrue(rs.MatchSource(r));
			NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r));
			expanded = rs.ExpandFromSource(r);
			NUnit.Framework.Assert.AreNotSame(rs, expanded);
			NUnit.Framework.Assert.IsTrue(expanded.IsForceUpdate());
			NUnit.Framework.Assert.IsFalse(expanded.IsWildcard());
			NUnit.Framework.Assert.AreEqual(r.GetName(), expanded.GetSource());
			NUnit.Framework.Assert.AreEqual("refs/remotes/origin/master", expanded.GetDestination
				());
			r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/remotes/origin/next", null);
			NUnit.Framework.Assert.IsFalse(rs.MatchSource(r));
			NUnit.Framework.Assert.IsTrue(rs.MatchDestination(r));
			r = new ObjectIdRef.Unpeeled(RefStorage.LOOSE, "refs/tags/v1.0", null);
			NUnit.Framework.Assert.IsFalse(rs.MatchSource(r));
			NUnit.Framework.Assert.IsFalse(rs.MatchDestination(r));
		}
Ejemplo n.º 17
0
 /// <exception cref="NGit.Errors.TransportException"></exception>
 private void ExpandSingle(RefSpec spec, ICollection<Ref> matched)
 {
     Ref src = conn.GetRef(spec.GetSource());
     if (src == null)
     {
         throw new TransportException(MessageFormat.Format(JGitText.Get().remoteDoesNotHaveSpec
             , spec.GetSource()));
     }
     if (matched.AddItem(src))
     {
         Want(src, spec);
     }
 }
Ejemplo n.º 18
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void DeleteTrackingRef(FetchResult result, Repository db, RevWalk walk, RefSpec
			 spec, Ref localRef)
        {
            string name = localRef.GetName();
            try
            {
                TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.GetSource(), true, ObjectId
                    .ZeroId, "deleted");
                result.Add(u);
                if (transport.IsDryRun())
                {
                    return;
                }
                u.Delete(walk);
                switch (u.GetResult())
                {
                    case RefUpdate.Result.NEW:
                    case RefUpdate.Result.NO_CHANGE:
                    case RefUpdate.Result.FAST_FORWARD:
                    case RefUpdate.Result.FORCED:
                    {
                        break;
                    }

                    default:
                    {
                        throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get
                            ().cannotDeleteStaleTrackingRef2, name, u.GetResult().ToString()));
                    }
                }
            }
            catch (IOException e)
            {
                throw new TransportException(transport.GetURI(), MessageFormat.Format(JGitText.Get
                    ().cannotDeleteStaleTrackingRef, name), e);
            }
        }
Ejemplo n.º 19
0
        /// <exception cref="System.IO.IOException"></exception>
        internal TrackingRefUpdate(Repository db, RefSpec spec, AnyObjectId nv, string msg
			)
            : this(db, spec.GetDestination(), spec.GetSource(), spec.IsForceUpdate(), nv, 
			msg)
        {
        }
Ejemplo n.º 20
0
		/// <exception cref="NGit.Errors.TransportException"></exception>
		private TrackingRefUpdate CreateUpdate(RefSpec spec, ObjectId newId)
		{
			Ref @ref = LocalRefs().Get(spec.GetDestination());
			ObjectId oldId = @ref != null && @ref.GetObjectId() != null ? @ref.GetObjectId() : 
				ObjectId.ZeroId;
			return new TrackingRefUpdate(spec.IsForceUpdate(), spec.GetSource(), spec.GetDestination
				(), oldId, newId);
		}
Ejemplo n.º 21
0
 /// <exception cref="System.IO.IOException"></exception>
 internal TrackingRefUpdate(Repository db, RefSpec spec, AnyObjectId nv, string msg
                            ) : this(db, spec.GetDestination(), spec.GetSource(), spec.IsForceUpdate(), nv,
                                     msg)
 {
 }