Ejemplo n.º 1
0
 public void testCreateEmpty()
 {
     RefSpec rs = new RefSpec();
     Assert.IsFalse(rs.Force);
     Assert.IsFalse(rs.Wildcard);
     Assert.AreEqual("HEAD", rs.Source);
     Assert.IsNull(rs.Destination);
     Assert.AreEqual("HEAD", rs.ToString());
 }
Ejemplo n.º 2
0
 private void expandWildcard(RefSpec spec, HashSet <Ref> matched)
 {
     foreach (Ref src in _connection.Refs)
     {
         if (spec.MatchSource(src) && matched.Add(src))
         {
             want(src, spec.ExpandFromSource((src)));
         }
     }
 }
Ejemplo n.º 3
0
        public bool AddPushRefSpec(RefSpec s)
        {
            if (Push.Contains(s))
            {
                return(false);
            }

            Push.Add(s);
            return(true);
        }
Ejemplo n.º 4
0
        public bool AddFetchRefSpec(RefSpec s)
        {
            if (Fetch.Contains(s))
            {
                return(false);
            }

            Fetch.Add(s);

            return(true);
        }
Ejemplo n.º 5
0
 public void testSplitLastColon()
 {
     string lhs = ":m:a:i:n:t";
     string rhs = "refs/heads/maint";
     RefSpec rs = new RefSpec(lhs + ":" + rhs);
     Assert.IsFalse(rs.Force);
     Assert.IsFalse(rs.Wildcard);
     Assert.AreEqual(lhs, rs.Source);
     Assert.AreEqual(rhs, rs.Destination);
     Assert.AreEqual(lhs + ":" + rhs, rs.ToString());
     Assert.AreEqual(rs, new RefSpec(rs.ToString()));
 }
Ejemplo n.º 6
0
        private void expandSingle(RefSpec spec, HashSet <Ref> matched)
        {
            Ref src = _connection.Refs.Find(x => x.Name == spec.Source);

            if (src == null)
            {
                throw new TransportException("Remote does not have " + spec.Source + " available for fetch.");
            }
            if (matched.Add(src))
            {
                want(src, spec);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create a new RefSpec with a different source name setting.
        /// </summary>
        /// <param name="source">new value for source in the returned instance.</param>
        /// <returns>a new RefSpec with source as specified.</returns>
        public RefSpec SetSource(string source)
        {
            var r = new RefSpec(this);

            r.Source = source;
            if (IsWildcard(r.Source) && r.Destination == null)
            {
                throw new InvalidOperationException("Destination is not a wildcard.");
            }
            if (IsWildcard(r.Source) != IsWildcard(r.Destination))
            {
                throw new InvalidOperationException("Source/Destination must match.");
            }
            return(r);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create a new RefSpec with a different destination name setting.
        /// </summary>
        /// <param name="destination">new value for destination in the returned instance.</param>
        /// <returns>a new RefSpec with destination as specified.</returns>
        public RefSpec SetDestination(string destination)
        {
            RefSpec r = new RefSpec(this);

            r.Destination = destination;

            if (IsWildcard(r.Destination) && r.Source == null)
            {
                throw new InvalidOperationException("Source is not a wildcard.");
            }
            if (IsWildcard(r.Source) != IsWildcard(r.Destination))
            {
                throw new InvalidOperationException("Source/Destination must match.");
            }
            return(r);
        }
Ejemplo n.º 9
0
        private void deleteStaleTrackingRefs(FetchResult result, RevWalk.RevWalk walk)
        {
            Repository db = _transport.Local;

            foreach (Ref @ref in db.getAllRefs().Values)
            {
                string refname = @ref.Name;
                foreach (RefSpec spec in _toFetch)
                {
                    if (spec.MatchDestination(refname))
                    {
                        RefSpec s = spec.ExpandFromDestination(refname);
                        if (result.GetAdvertisedRef(s.Source) == null)
                        {
                            deleteTrackingRef(result, db, walk, s, @ref);
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
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 Core.Ref(Core.Ref.Storage.Loose, sn, null);
            Assert.IsFalse(rs.MatchSource(r));
            Assert.IsTrue(rs.MatchDestination(r));
            Assert.AreSame(rs, rs.ExpandFromSource(r));

            r = new Core.Ref(Core.Ref.Storage.Loose, sn + "-and-more", null);
            Assert.IsFalse(rs.MatchSource(r));
            Assert.IsFalse(rs.MatchDestination(r));
        }
Ejemplo n.º 11
0
 public void testSetForceUpdate()
 {
     string s = "refs/heads/*:refs/remotes/origin/*";
     RefSpec a = new RefSpec(s);
     Assert.IsFalse(a.Force);
     RefSpec b = a.SetForce(true);
     Assert.AreNotSame(a, b);
     Assert.IsFalse(a.Force);
     Assert.IsTrue(b.Force);
     Assert.AreEqual(s, a.ToString());
     Assert.AreEqual("+" + s, b.ToString());
 }
Ejemplo n.º 12
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 Core.Ref(Core.Ref.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 Core.Ref(Core.Ref.Storage.Loose, "refs/remotes/origin/next", null);
            Assert.IsFalse(rs.MatchSource(r));
            Assert.IsTrue(rs.MatchDestination(r));

            r = new Core.Ref(Core.Ref.Storage.Loose, "refs/tags/v1.0", null);
            Assert.IsFalse(rs.MatchSource(r));
            Assert.IsFalse(rs.MatchDestination(r));
        }
Ejemplo n.º 13
0
        public void testSetDestination_SourceNull()
        {
            RefSpec a = new RefSpec();
            RefSpec b;

            b = a.SetDestination("refs/heads/master");
            b = b.SetSource(null);
            Assert.AreNotSame(a, b);
            Assert.AreEqual("HEAD", a.ToString());
            Assert.AreEqual(":refs/heads/master", b.ToString());
        }
Ejemplo n.º 14
0
        private void want(Ref src, RefSpec spec)
        {
            ObjectId newId = src.ObjectId;
            if (spec.Destination != null)
            {
                try
                {
                    TrackingRefUpdate tru = createUpdate(spec, newId);
                    if (newId.Equals(tru.OldObjectId))
                    {
                        return;
                    }
                    _localUpdates.Add(tru);
                }
                catch (System.IO.IOException err)
                {
                    // Bad symbolic ref? That is the most likely cause.
                    throw new TransportException("Cannot resolve" + " local tracking ref " + spec.Destination + " for updating.", err);
                }
            }

            _askFor.Add(newId, src);

            FetchHeadRecord fhr = new FetchHeadRecord(newId, spec.Destination != null, src.Name, _transport.Uri);
            _fetchHeadUpdates.Add(fhr);
        }
Ejemplo n.º 15
0
        public void testFindRemoteRefUpdatesTwoRefSpecs()
        {
            transport = GitSharp.Core.Transport.Transport.open(db, remoteConfig);
            RefSpec specA = new RefSpec("+refs/heads/a:refs/heads/b");
            RefSpec specC = new RefSpec("+refs/heads/c:refs/heads/d");
            List<RefSpec> specs = new List<RefSpec>{specA, specC};
            ICollection<RemoteRefUpdate> result = transport.findRemoteRefUpdatesFor(specs);

            Assert.AreEqual(2, result.Count);
            bool foundA = false;
            bool foundC = false;
            foreach (RemoteRefUpdate rru in result)
            {
                if ("refs/heads/a".Equals(rru.SourceRef) && "refs/heads/b".Equals(rru.RemoteName))
                    foundA = true;
                if ("refs/heads/c".Equals(rru.SourceRef) && "refs/heads/d".Equals(rru.RemoteName))
                    foundC = true;
            }
            Assert.IsTrue(foundA);
            Assert.IsTrue(foundC);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Add a new push RefSpec to this remote.
        /// </summary>
        /// <param name="s">the new specification to add.</param>
        /// <returns>true if the specification was added; false if it already exists.</returns>
		public bool AddPushRefSpec(RefSpec s)
		{
			if (Push.Contains(s)) return false;

			Push.Add(s);
			return true;
		}
Ejemplo n.º 17
0
 private TrackingRefUpdate createUpdate(RefSpec spec, ObjectId newId)
 {
     return(new TrackingRefUpdate(_transport.Local, spec, newId, "fetch"));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Create a new RefSpec with a different source name setting.
 /// </summary>
 /// <param name="source">new value for source in the returned instance.</param>
 /// <returns>a new RefSpec with source as specified.</returns>
 public RefSpec SetSource(string source)
 {
     var r = new RefSpec(this);
     r.Source = source;
     if (IsWildcard(r.Source) && r.Destination == null)
         throw new InvalidOperationException("Destination is not a wildcard.");
     if (IsWildcard(r.Source) != IsWildcard(r.Destination))
         throw new InvalidOperationException("Source/Destination must match.");
     return r;
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Add a new fetch RefSpec to this remote.
        /// </summary>
        /// <param name="s">the new specification to add.</param>
        /// <returns>true if the specification was added; false if it already exists.</returns>
        public bool AddFetchRefSpec(RefSpec s)
        {
            if (Fetch.Contains(s))
            {
                return false;
            }

            Fetch.Add(s);

            return true;
        }
Ejemplo n.º 20
0
 public void testExpandFromDestination_NonWildcard()
 {
     string src = "refs/heads/master";
     string dst = "refs/remotes/origin/master";
     RefSpec a = new RefSpec(src + ":" + dst);
     RefSpec r = a.ExpandFromDestination(dst);
     Assert.AreSame(a, r);
     Assert.IsFalse(r.Wildcard);
     Assert.AreEqual(src, r.Source);
     Assert.AreEqual(dst, r.Destination);
 }
Ejemplo n.º 21
0
        private void deleteTrackingRef(FetchResult result, Repository db, RevWalk.RevWalk walk, RefSpec spec, Ref localRef)
        {
            string name = localRef.Name;

            try
            {
                TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.Source, true, ObjectId.ZeroId, "deleted");
                result.Add(u);
                if (_transport.DryRun)
                {
                    return;
                }

                u.Delete(walk);

                switch (u.Result)
                {
                case RefUpdate.RefUpdateResult.New:
                case RefUpdate.RefUpdateResult.NoChange:
                case RefUpdate.RefUpdateResult.FastForward:
                case RefUpdate.RefUpdateResult.Forced:
                    break;

                default:
                    throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name + ": " + u.Result.ToString());
                }
            }
            catch (System.IO.IOException e)
            {
                throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name, e);
            }
        }
Ejemplo n.º 22
0
 public void testSetSource()
 {
     RefSpec a = new RefSpec();
     RefSpec b = a.SetSource("refs/heads/master");
     Assert.AreNotSame(a, b);
     Assert.AreEqual("HEAD", a.ToString());
     Assert.AreEqual("refs/heads/master", b.ToString());
 }
Ejemplo n.º 23
0
 public bool RemoveFetchRefSpec(RefSpec s)
 {
     return(Fetch.Remove(s));
 }
Ejemplo n.º 24
0
        private void deleteTrackingRef(FetchResult result, Repository db, RevWalk.RevWalk walk, RefSpec spec, Ref localRef)
        {
            string name = localRef.Name;
            try
            {
                TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.Source, true, ObjectId.ZeroId, "deleted");
                result.Add(u);
                if (_transport.DryRun)
                {
                    return;
                }

                u.Delete(walk);

                switch (u.Result)
                {
                    case RefUpdate.RefUpdateResult.NEW:
                    case RefUpdate.RefUpdateResult.NO_CHANGE:
                    case RefUpdate.RefUpdateResult.FAST_FORWARD:
                    case RefUpdate.RefUpdateResult.FORCED:
                        break;

                    default:
                        throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name + ": " + Enum.GetName(typeof(RefUpdate.RefUpdateResult), u.Result));
                }
            }
            catch (IOException e)
            {
                throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name, e);
            }
        }
Ejemplo n.º 25
0
 public void testSetSourceDestination()
 {
     RefSpec a = new RefSpec();
     RefSpec b;
     b = a.SetSourceDestination("refs/heads/*", "refs/remotes/origin/*");
     Assert.AreNotSame(a, b);
     Assert.AreEqual("HEAD", a.ToString());
     Assert.AreEqual("refs/heads/*:refs/remotes/origin/*", b.ToString());
 }
Ejemplo n.º 26
0
 public bool RemovePushRefSpec(RefSpec s)
 {
     return(Push.Remove(s));
 }
Ejemplo n.º 27
0
        private FetchResult fetchFromBundle(Core.Repository newRepo, byte[] bundle)
        {
            var uri = new URIish("in-memory://");
            var @in = new MemoryStream(bundle);
            var rs = new RefSpec("refs/heads/*:refs/heads/*");
            var refs = new List<RefSpec>{rs};
            var transportBundleStream = new TransportBundleStream(newRepo, uri, @in);

            _transportBundleStreams.Add(transportBundleStream);

            return transportBundleStream.fetch(NullProgressMonitor.Instance, refs);
        }
Ejemplo n.º 28
0
 private TrackingRefUpdate createUpdate(RefSpec spec, ObjectId newId)
 {
     return new TrackingRefUpdate(_transport.Local, spec, newId, "fetch");
 }
Ejemplo n.º 29
0
 private RefSpec(RefSpec p)
 {
     Force = p.Force;
     Wildcard = p.Wildcard;
     Source = p.Source;
     Destination = p.Destination;
 }
Ejemplo n.º 30
0
        private void deleteTrackingRef(FetchResult result, Repository db, RevWalk.RevWalk walk, RefSpec spec, Ref localRef)
        {
            string name = localRef.Name;
            try
            {
                TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.Source, true, ObjectId.ZeroId, "deleted");
                result.Add(u);
                if (_transport.DryRun)
                {
                    return;
                }

                u.Delete(walk);

                switch (u.Result)
                {
                    case RefUpdate.RefUpdateResult.New:
                    case RefUpdate.RefUpdateResult.NoChange:
                    case RefUpdate.RefUpdateResult.FastForward:
                    case RefUpdate.RefUpdateResult.Forced:
                        break;

                    default:
                        throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name + ": " + u.Result.ToString());
                }
            }
            catch (System.IO.IOException e)
            {
                throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name, e);
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Create a new RefSpec with a different destination name setting.
        /// </summary>
        /// <param name="destination">new value for destination in the returned instance.</param>
        /// <returns>a new RefSpec with destination as specified.</returns>
        public RefSpec SetDestination(string destination)
        {
            RefSpec r = new RefSpec(this);
            r.Destination = destination;

            if (IsWildcard(r.Destination) && r.Source == null)
            {
                throw new InvalidOperationException("Source is not a wildcard.");
            }
            if (IsWildcard(r.Source) != IsWildcard(r.Destination))
            {
                throw new InvalidOperationException("Source/Destination must match.");
            }
            return r;
        }
Ejemplo n.º 32
0
 private void expandSingle(RefSpec spec, HashSet<Ref> matched)
 {
     Ref src = _connection.Refs.Find(x => x.Name == spec.Source);
     if (src == null)
     {
         throw new TransportException("Remote does not have " + spec.Source + " available for fetch.");
     }
     if (matched.Add(src))
     {
         want(src, spec);
     }
 }
Ejemplo n.º 33
0
		/// <summary>
        /// Remove a fetch RefSpec from this remote.
		/// </summary>
        /// <param name="s">the specification to remove.</param>
        /// <returns>true if the specification existed and was removed.</returns>
        public bool RemoveFetchRefSpec(RefSpec s)
		{
			return Fetch.Remove(s);
		}
Ejemplo n.º 34
0
 private void expandWildcard(RefSpec spec, HashSet<Ref> matched)
 {
     foreach (Ref src in _connection.Refs)
     {
         if (spec.MatchSource(src) && matched.Add(src))
             want(src, spec.ExpandFromSource((src)));
     }
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Remove a push RefSpec from this remote.
        /// </summary>
        /// <param name="s">the specification to remove.</param>
        /// <returns>true if the specification existed and was removed.</returns>
		public bool RemovePushRefSpec(RefSpec s)
		{
			return Push.Remove(s);
		}
Ejemplo n.º 36
0
        private void deleteTrackingRef(FetchResult result, Repository db, RevWalk.RevWalk walk, RefSpec spec, Ref localRef)
        {
            string name = localRef.Name;

            try
            {
                TrackingRefUpdate u = new TrackingRefUpdate(db, name, spec.Source, true, ObjectId.ZeroId, "deleted");
                result.Add(u);
                if (_transport.DryRun)
                {
                    return;
                }

                u.Delete(walk);

                switch (u.Result)
                {
                case RefUpdate.RefUpdateResult.NEW:
                case RefUpdate.RefUpdateResult.NO_CHANGE:
                case RefUpdate.RefUpdateResult.FAST_FORWARD:
                case RefUpdate.RefUpdateResult.FORCED:
                    break;

                default:
                    throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name + ": " + Enum.GetName(typeof(RefUpdate.RefUpdateResult), u.Result));
                }
            }
            catch (IOException e)
            {
                throw new TransportException(_transport.Uri, "Cannot delete stale tracking ref " + name, e);
            }
        }