Ejemplo n.º 1
0
 public void test001_SplitLastColon()
 {
     string lhs = ":m:a:i:n:t";
     string rhs = "refs/heads/maint";
     RefSpec rs = new RefSpec(lhs + ":" + rhs);
     Assert.False(rs.Force);
     Assert.False(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.º 2
0
        public void test000_MasterMaster()
        {
            string sn = "refs/heads/master";
            RefSpec rs = new RefSpec(sn + ":" + sn);
            Assert.False(rs.Force);
            Assert.False(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()));

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

            r = new Ref(Ref.Storage.Loose, sn + "-and-more", null);
            Assert.False(rs.MatchSource(r));
            Assert.False(rs.MatchDestination(r));
        }
Ejemplo n.º 3
0
 public void test012_ExpandFromDestination_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);
     Assert.AreNotSame(a, r);
     Assert.False(r.Wildcard);
     Assert.AreEqual(src, r.Source);
     Assert.AreEqual(dst, r.Destination);
 }
Ejemplo n.º 4
0
 public void test011_SetSourceDestination()
 {
     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.º 5
0
        public void test010_SetDestination_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.º 6
0
 private RefSpec(RefSpec p)
 {
     Force = p.Force;
     Wildcard = p.Wildcard;
     Source = p.Source;
     Destination = p.Destination;
 }
Ejemplo n.º 7
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.º 8
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.º 9
0
 public void test007_CreateEmpty()
 {
     RefSpec rs = new RefSpec();
     Assert.False(rs.Force);
     Assert.False(rs.Wildcard);
     Assert.AreEqual("HEAD", rs.Source);
     Assert.Null(rs.Destination);
     Assert.AreEqual("HEAD", rs.ToString());
 }
Ejemplo n.º 10
0
        public void test006_ForceRemotesOrigin()
        {
            string srcn = "refs/heads/*";
            string dstn = "refs/remotes/origin/*";
            RefSpec rs = new RefSpec("+" + srcn + ":" + dstn);
            Assert.True(rs.Force);
            Assert.True(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()));

            Ref r;
            RefSpec expanded;

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

            r = new Ref(Ref.Storage.Loose, "refs/remotes/origin/next", null);
            Assert.False(rs.MatchSource(r));
            Assert.True(rs.MatchDestination(r));

            r = new Ref(Ref.Storage.Loose, "refs/tags/v1.0", null);
            Assert.False(rs.MatchSource(r));
            Assert.False(rs.MatchDestination(r));
        }
Ejemplo n.º 11
0
 public bool RemovePushRefSpec(RefSpec s)
 {
     return Push.Remove(s);
 }
Ejemplo n.º 12
0
 public bool AddPushRefSpec(RefSpec s)
 {
     if (Push.Contains(s))
         return false;
     Push.Add(s);
     return true;
 }
Ejemplo n.º 13
0
 public bool RemoveFetchRefSpec(RefSpec s)
 {
     return Fetch.Remove(s);
 }
Ejemplo n.º 14
0
 public bool AddFetchRefSpec(RefSpec s)
 {
     if (Fetch.Contains(s))
         return false;
     Fetch.Add(s);
     return true;
 }
Ejemplo n.º 15
0
 public RefSpec SetDestination(string destination)
 {
     RefSpec r = new RefSpec(this);
     r.Destination = destination;
     if (IsWildcard(r.Destination) && r.Source == null)
         throw new ArgumentException("Source is not a wildcard.");
     if (IsWildcard(r.Source) != IsWildcard(r.Destination))
         throw new ArgumentException("Source/Destination must match.");
     return r;
 }
Ejemplo n.º 16
0
 public void test008_SetForceUpdate()
 {
     string s = "refs/heads/*:refs/remotes/origin/*";
     RefSpec a = new RefSpec(s);
     Assert.False(a.Force);
     RefSpec b = a.SetForce(true);
     Assert.AreNotSame(a, b);
     Assert.False(a.Force);
     Assert.True(b.Force);
     Assert.AreEqual(s, a.ToString());
     Assert.AreEqual("+" + s, b.ToString());
 }
Ejemplo n.º 17
0
 private TrackingRefUpdate createUpdate(RefSpec spec, ObjectId newId)
 {
     return new TrackingRefUpdate(_transport.Local, spec, newId, "fetch");
 }
Ejemplo n.º 18
0
 public void test009_SetSource()
 {
     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.º 19
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.º 20
0
 public void test010_SetDestination()
 {
     RefSpec a = new RefSpec();
     RefSpec b = a.SetDestination("refs/heads/master");
     Assert.AreNotSame(a, b);
     Assert.AreEqual("HEAD", a.ToString());
     Assert.AreEqual("HEAD:refs/heads/master", b.ToString());
 }
Ejemplo n.º 21
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.º 22
0
 private FetchResult fetchFromBundle(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};
     return new TransportBundleStream(newRepo, uri, @in).fetch(NullProgressMonitor.Instance, refs);
 }