Connects two Git repositories together and copies objects between them. A transport can be used for either fetching (copying objects into the caller's repository from the remote repository) or pushing (copying objects into the remote repository from the caller's repository). Each transport implementation is responsible for the details associated with establishing the network connection(s) necessary for the copy, as well as actually shuffling data back and forth. Transport instances and the connections they Create are not thread-safe. Callers must ensure a transport is accessed by only one thread at a time.
Inheritance: IDisposable
        protected void showFetchResult(GitSharp.Core.Transport.Transport tn, FetchResult r)
        {
            bool shownURI = false;

            foreach (TrackingRefUpdate u in r.TrackingRefUpdates)
            {
                if (!verbose && u.Result == RefUpdate.RefUpdateResult.NoChange)
                {
                    continue;
                }

                char   type     = shortTypeOf(u.Result);
                string longType = longTypeOf(u);
                string src      = AbbreviateRef(u.RemoteName, false);
                string dst      = AbbreviateRef(u.LocalName, true);

                if (!shownURI)
                {
                    OutputStream.Write("From ");
                    OutputStream.WriteLine(tn.Uri);
                    shownURI = true;
                }

                OutputStream.WriteLine(" " + type + " " + longType + " " + src + " -> " + dst);
            }
        }
Exemple #2
0
        public void testFindRemoteRefUpdatesWildcardNoTracking()
        {
            transport = GitSharp.Core.Transport.Transport.Open(db, remoteConfig);
            ICollection <RemoteRefUpdate> result =
                transport.findRemoteRefUpdatesFor(new List <RefSpec> {
                new RefSpec("+refs/heads/*:refs/heads/test/*")
            });

            Assert.AreEqual(12, result.Count);
            bool foundA = false;
            bool foundB = false;

            foreach (RemoteRefUpdate rru in result)
            {
                if ("refs/heads/a".Equals(rru.SourceRef) && "refs/heads/test/a".Equals(rru.RemoteName))
                {
                    foundA = true;
                }
                if ("refs/heads/b".Equals(rru.SourceRef) && "refs/heads/test/b".Equals(rru.RemoteName))
                {
                    foundB = true;
                }
            }
            Assert.IsTrue(foundA);
            Assert.IsTrue(foundB);
        }
Exemple #3
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);
        }
        public BundleFetchConnection(Transport transportBundle, Stream src)
        {
            transport = transportBundle;
            bin = new BufferedStream(src, IndexPack.BUFFER_SIZE);
            try
            {
                switch (readSignature())
                {
                    case 2:
                        readBundleV2();
                        break;

                    default:
                        throw new TransportException(transport.Uri, "not a bundle");
                }
            }
            catch (TransportException)
            {
                Close();
                throw;
            }
            catch (IOException err)
            {
                Close();
                throw new TransportException(transport.Uri, err.Message, err);
            }
        }
Exemple #5
0
 public override void setUp()
 {
     base.setUp();
     RepositoryConfig config = db.Config;
     remoteConfig = new RemoteConfig(config, "test");
     remoteConfig.AddURI(new URIish("http://everyones.loves.git/u/2"));
     transport = null;
 }
Exemple #6
0
 public override void tearDown()
 {
     if (transport != null)
     {
         transport.Dispose();
         transport = null;
     }
     base.tearDown();
 }
Exemple #7
0
        public override void setUp()
        {
            base.setUp();
            RepositoryConfig config = db.Config;

            remoteConfig = new RemoteConfig(config, "test");
            remoteConfig.AddURI(new URIish("http://everyones.loves.git/u/2"));
            transport = null;
        }
Exemple #8
0
 protected new void tearDown()
 {
     if (transport != null)
     {
         transport.close();
         transport = null;
     }
     base.tearDown();
 }
Exemple #9
0
 public override void tearDown()
 {
     if (transport != null)
     {
         transport.Dispose();
         transport = null;
     }
     base.tearDown();
 }
Exemple #10
0
        public void testFindRemoteRefUpdatesNoWildcardNoTracking()
        {
            transport = GitSharp.Core.Transport.Transport.open(db, remoteConfig);
            ICollection<RemoteRefUpdate> result =
                transport.findRemoteRefUpdatesFor(new List<RefSpec> {new RefSpec("refs/heads/master:refs/heads/x")});

            Assert.AreEqual(1, result.Count);
            RemoteRefUpdate rru = result.ToArray()[0];
            Assert.AreEqual(null, rru.ExpectedOldObjectId);
            Assert.IsFalse(rru.ForceUpdate);
            Assert.AreEqual("refs/heads/master", rru.SourceRef);
            Assert.AreEqual(db.Resolve("refs/heads/master"), rru.NewObjectId);
            Assert.AreEqual("refs/heads/x", rru.RemoteName);
        }
Exemple #11
0
        ///	 <summary> * Create process for specified transport and refs updates specification.
        ///	 * </summary>
        ///	 * <param name="transport">
        ///	 *            transport between remote and local repository, used to Create
        ///	 *            connection. </param>
        ///	 * <param name="toPush">
        ///	 *            specification of refs updates (and local tracking branches). </param>
        ///	 * <exception cref="TransportException"> </exception>
        public PushProcess(Transport transport, IEnumerable<RemoteRefUpdate> toPush)
        {
            _walker = new RevWalk.RevWalk(transport.Local);
            _transport = transport;
            _toPush = new Dictionary<string, RemoteRefUpdate>();
            foreach (RemoteRefUpdate rru in toPush)
            {
                if (_toPush.ContainsKey(rru.RemoteName))
                {
                    throw new TransportException("Duplicate remote ref update is illegal. Affected remote name: " + rru.RemoteName);
                }

                _toPush.Add(rru.RemoteName, rru);
            }
        }
Exemple #12
0
        public void testFindRemoteRefUpdatesNoWildcardNoDestination()
        {
            transport = GitSharp.Core.Transport.Transport.Open(db, remoteConfig);
            ICollection <RemoteRefUpdate> result =
                transport.findRemoteRefUpdatesFor(new List <RefSpec> {
                new RefSpec("+refs/heads/master")
            });

            Assert.AreEqual(1, result.Count);
            RemoteRefUpdate rru = result.ToArray()[0];

            Assert.AreEqual(null, rru.ExpectedOldObjectId);
            Assert.IsTrue(rru.ForceUpdate);
            Assert.AreEqual("refs/heads/master", rru.SourceRef);
            Assert.AreEqual(db.Resolve("refs/heads/master"), rru.NewObjectId);
            Assert.AreEqual("refs/heads/master", rru.RemoteName);
        }
Exemple #13
0
        public void testFindRemoteRefUpdatesTrackingRef()
        {
            remoteConfig.AddFetchRefSpec(new RefSpec("refs/heads/*:refs/remotes/test/*"));
            transport = GitSharp.Core.Transport.Transport.Open(db, remoteConfig);
            ICollection <RemoteRefUpdate> result =
                transport.findRemoteRefUpdatesFor(new List <RefSpec> {
                new RefSpec("+refs/heads/a:refs/heads/a")
            });

            Assert.AreEqual(1, result.Count);
            TrackingRefUpdate tru = result.ToArray()[0].TrackingRefUpdate;

            Assert.AreEqual("refs/remotes/test/a", tru.LocalName);
            Assert.AreEqual("refs/heads/a", tru.RemoteName);
            Assert.AreEqual(db.Resolve("refs/heads/a"), tru.NewObjectId);
            Assert.AreEqual(null, tru.OldObjectId);
        }
Exemple #14
0
        /// <summary>
        /// Create process for specified transport and refs updates specification.
        /// </summary>
        /// <param name="transport">
        /// transport between remote and local repository, used to Create
        /// connection. </param>
        /// <param name="toPush">
        /// specification of refs updates (and local tracking branches).
        /// </param>
        /// <exception cref="TransportException"> </exception>
        public PushProcess(Transport transport, IEnumerable<RemoteRefUpdate> toPush)
        {
            if (transport == null)
                throw new ArgumentNullException("transport");
            if (toPush == null)
                throw new ArgumentNullException("toPush");

            _walker = new RevWalk.RevWalk(transport.Local);
            _transport = transport;
            _toPush = new Dictionary<string, RemoteRefUpdate>();
            foreach (RemoteRefUpdate rru in toPush)
            {
                if (_toPush.put(rru.RemoteName, rru) != null)
                {
                    throw new TransportException("Duplicate remote ref update is illegal. Affected remote name: " + rru.RemoteName);
                }
            }
        }
Exemple #15
0
        public void testFindRemoteRefUpdatesTrackingRef()
        {
            remoteConfig.AddFetchRefSpec(new RefSpec("refs/heads/*:refs/remotes/test/*"));
            transport = GitSharp.Core.Transport.Transport.open(db, remoteConfig);
            ICollection<RemoteRefUpdate> result =
                transport.findRemoteRefUpdatesFor(new List<RefSpec> {new RefSpec("+refs/heads/a:refs/heads/a")});

            Assert.AreEqual(1, result.Count);
            TrackingRefUpdate tru = result.ToArray()[0].TrackingRefUpdate;
            Assert.AreEqual("refs/remotes/test/a", tru.LocalName);
            Assert.AreEqual("refs/heads/a", tru.RemoteName);
            Assert.AreEqual(db.Resolve("refs/heads/a"), tru.NewObjectId);
            Assert.AreEqual(null, tru.OldObjectId);
        }
 protected BasePackConnection(IPackTransport packTransport)
 {
     transport = (Transport) packTransport;
     local = transport.Local;
     uri = transport.Uri;
 }
Exemple #17
0
 internal FetchProcess(Transport t, ICollection <RefSpec> f)
 {
     _transport = t;
     _toFetch   = f;
 }
Exemple #18
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);
        }
Exemple #19
0
        public void testFindRemoteRefUpdatesWildcardNoTracking()
        {
            transport = GitSharp.Core.Transport.Transport.open(db, remoteConfig);
            ICollection<RemoteRefUpdate> result =
                transport.findRemoteRefUpdatesFor(new List<RefSpec> { new RefSpec("+refs/heads/*:refs/heads/test/*") });

            Assert.AreEqual(12, result.Count);
            bool foundA = false;
            bool foundB = false;
            foreach (RemoteRefUpdate rru in result)
            {
                if ("refs/heads/a".Equals(rru.SourceRef) && "refs/heads/test/a".Equals(rru.RemoteName))
                {
                	foundA = true;
                }
                if ("refs/heads/b".Equals(rru.SourceRef) && "refs/heads/test/b".Equals(rru.RemoteName))
                {
                	foundB = true;
                }
            }
            Assert.IsTrue(foundA);
            Assert.IsTrue(foundB);
        }
Exemple #20
0
 internal FetchProcess(Transport t, ICollection<RefSpec> f)
 {
     _transport = t;
     _toFetch = f;
 }
Exemple #21
0
 protected new void tearDown()
 {
     if (transport != null)
     {
         transport.close();
         transport = null;
     }
     base.tearDown();
 }