Ejemplo n.º 1
0
        public virtual void TestUploadPack()
        {
            ReadConfig("[remote \"example\"]\n" + "url = [email protected]:egit.git\n" + "fetch = +refs/heads/*:refs/remotes/example/*\n"
                       + "uploadpack = /path/to/git/git-upload-pack\n" + "receivepack = /path/to/git/git-receive-pack\n"
                       );
            RemoteConfig   rc      = new RemoteConfig(config, "example");
            IList <URIish> allURIs = rc.URIs;
            RefSpec        spec;

            NUnit.Framework.Assert.AreEqual("example", rc.Name);
            NUnit.Framework.Assert.IsNotNull(allURIs);
            NUnit.Framework.Assert.IsNotNull(rc.FetchRefSpecs);
            NUnit.Framework.Assert.IsNotNull(rc.PushRefSpecs);
            NUnit.Framework.Assert.AreEqual(1, allURIs.Count);
            NUnit.Framework.Assert.AreEqual("[email protected]:egit.git", allURIs[0].ToString(
                                                ));
            NUnit.Framework.Assert.AreEqual(1, rc.FetchRefSpecs.Count);
            spec = rc.FetchRefSpecs[0];
            NUnit.Framework.Assert.IsTrue(spec.IsForceUpdate());
            NUnit.Framework.Assert.IsTrue(spec.IsWildcard());
            NUnit.Framework.Assert.AreEqual("refs/heads/*", spec.GetSource());
            NUnit.Framework.Assert.AreEqual("refs/remotes/example/*", spec.GetDestination());
            NUnit.Framework.Assert.AreEqual(0, rc.PushRefSpecs.Count);
            NUnit.Framework.Assert.AreEqual("/path/to/git/git-upload-pack", rc.UploadPack);
            NUnit.Framework.Assert.AreEqual("/path/to/git/git-receive-pack", rc.ReceivePack);
        }
Ejemplo n.º 2
0
        public virtual void TestBackup()
        {
            ReadConfig("[remote \"backup\"]\n" + "url = http://www.spearce.org/egit.git\n" +
                       "url = [email protected]:/srv/git/egit.git\n" + "push = +refs/heads/*:refs/heads/*\n"
                       + "push = refs/tags/*:refs/tags/*\n");
            RemoteConfig   rc      = new RemoteConfig(config, "backup");
            IList <URIish> allURIs = rc.URIs;
            RefSpec        spec;

            NUnit.Framework.Assert.AreEqual("backup", rc.Name);
            NUnit.Framework.Assert.IsNotNull(allURIs);
            NUnit.Framework.Assert.IsNotNull(rc.FetchRefSpecs);
            NUnit.Framework.Assert.IsNotNull(rc.PushRefSpecs);
            NUnit.Framework.Assert.AreEqual(2, allURIs.Count);
            NUnit.Framework.Assert.AreEqual("http://www.spearce.org/egit.git", allURIs[0].ToString
                                                ());
            NUnit.Framework.Assert.AreEqual("[email protected]:/srv/git/egit.git", allURIs[1].ToString
                                                ());
            NUnit.Framework.Assert.AreEqual(0, rc.FetchRefSpecs.Count);
            NUnit.Framework.Assert.AreEqual(2, rc.PushRefSpecs.Count);
            spec = rc.PushRefSpecs[0];
            NUnit.Framework.Assert.IsTrue(spec.IsForceUpdate());
            NUnit.Framework.Assert.IsTrue(spec.IsWildcard());
            NUnit.Framework.Assert.AreEqual("refs/heads/*", spec.GetSource());
            NUnit.Framework.Assert.AreEqual("refs/heads/*", spec.GetDestination());
            spec = rc.PushRefSpecs[1];
            NUnit.Framework.Assert.IsFalse(spec.IsForceUpdate());
            NUnit.Framework.Assert.IsTrue(spec.IsWildcard());
            NUnit.Framework.Assert.AreEqual("refs/tags/*", spec.GetSource());
            NUnit.Framework.Assert.AreEqual("refs/tags/*", spec.GetDestination());
        }
Ejemplo n.º 3
0
		public virtual void TestPush()
		{
			// create other repository
			Repository db2 = CreateWorkRepository();
			// setup the first repository
			StoredConfig config = ((FileBasedConfig)db.GetConfig());
			RemoteConfig remoteConfig = new RemoteConfig(config, "test");
			URIish uri = new URIish(db2.Directory.ToURI().ToURL());
			remoteConfig.AddURI(uri);
			remoteConfig.Update(config);
			config.Save();
			Git git1 = new Git(db);
			// create some refs via commits and tag
			RevCommit commit = git1.Commit().SetMessage("initial commit").Call();
			Ref tagRef = git1.Tag().SetName("tag").Call();
			try
			{
				db2.Resolve(commit.Id.GetName() + "^{commit}");
				NUnit.Framework.Assert.Fail("id shouldn't exist yet");
			}
			catch (MissingObjectException)
			{
			}
			// we should get here
			RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
			git1.Push().SetRemote("test").SetRefSpecs(spec).Call();
			NUnit.Framework.Assert.AreEqual(commit.Id, db2.Resolve(commit.Id.GetName() + "^{commit}"
				));
			NUnit.Framework.Assert.AreEqual(tagRef.GetObjectId(), db2.Resolve(tagRef.GetObjectId
				().GetName()));
		}
Ejemplo n.º 4
0
        public virtual void TestSimple()
        {
            ReadConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" +
                       "fetch = +refs/heads/*:refs/remotes/spearce/*\n");
            RemoteConfig   rc      = new RemoteConfig(config, "spearce");
            IList <URIish> allURIs = rc.URIs;
            RefSpec        spec;

            NUnit.Framework.Assert.AreEqual("spearce", rc.Name);
            NUnit.Framework.Assert.IsNotNull(allURIs);
            NUnit.Framework.Assert.IsNotNull(rc.FetchRefSpecs);
            NUnit.Framework.Assert.IsNotNull(rc.PushRefSpecs);
            NUnit.Framework.Assert.IsNotNull(rc.TagOpt);
            NUnit.Framework.Assert.AreEqual(0, rc.Timeout);
            NUnit.Framework.Assert.AreEqual(TagOpt.AUTO_FOLLOW, rc.TagOpt);
            NUnit.Framework.Assert.AreEqual(1, allURIs.Count);
            NUnit.Framework.Assert.AreEqual("http://www.spearce.org/egit.git", allURIs[0].ToString
                                                ());
            NUnit.Framework.Assert.AreEqual(1, rc.FetchRefSpecs.Count);
            spec = rc.FetchRefSpecs[0];
            NUnit.Framework.Assert.IsTrue(spec.IsForceUpdate());
            NUnit.Framework.Assert.IsTrue(spec.IsWildcard());
            NUnit.Framework.Assert.AreEqual("refs/heads/*", spec.GetSource());
            NUnit.Framework.Assert.AreEqual("refs/remotes/spearce/*", spec.GetDestination());
            NUnit.Framework.Assert.AreEqual(0, rc.PushRefSpecs.Count);
        }
Ejemplo n.º 5
0
		public virtual void TestSimple()
		{
			ReadConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" +
				 "fetch = +refs/heads/*:refs/remotes/spearce/*\n");
			RemoteConfig rc = new RemoteConfig(config, "spearce");
			IList<URIish> allURIs = rc.URIs;
			RefSpec spec;
			NUnit.Framework.Assert.AreEqual("spearce", rc.Name);
			NUnit.Framework.Assert.IsNotNull(allURIs);
			NUnit.Framework.Assert.IsNotNull(rc.FetchRefSpecs);
			NUnit.Framework.Assert.IsNotNull(rc.PushRefSpecs);
			NUnit.Framework.Assert.IsNotNull(rc.TagOpt);
			NUnit.Framework.Assert.AreEqual(0, rc.Timeout);
			NUnit.Framework.Assert.AreEqual(TagOpt.AUTO_FOLLOW, rc.TagOpt);
			NUnit.Framework.Assert.AreEqual(1, allURIs.Count);
			NUnit.Framework.Assert.AreEqual("http://www.spearce.org/egit.git", allURIs[0].ToString
				());
			NUnit.Framework.Assert.AreEqual(1, rc.FetchRefSpecs.Count);
			spec = rc.FetchRefSpecs[0];
			NUnit.Framework.Assert.IsTrue(spec.IsForceUpdate());
			NUnit.Framework.Assert.IsTrue(spec.IsWildcard());
			NUnit.Framework.Assert.AreEqual("refs/heads/*", spec.GetSource());
			NUnit.Framework.Assert.AreEqual("refs/remotes/spearce/*", spec.GetDestination());
			NUnit.Framework.Assert.AreEqual(0, rc.PushRefSpecs.Count);
		}
Ejemplo n.º 6
0
        public virtual void TestSimpleAlwaysTags()
        {
            ReadConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" +
                       "fetch = +refs/heads/*:refs/remotes/spearce/*\n" + "tagopt = --tags\n");
            RemoteConfig rc = new RemoteConfig(config, "spearce");

            NUnit.Framework.Assert.AreEqual(TagOpt.FETCH_TAGS, rc.TagOpt);
        }
Ejemplo n.º 7
0
 public override void SetUp()
 {
     base.SetUp();
     Config config = ((FileBasedConfig)db.GetConfig());
     remoteConfig = new RemoteConfig(config, "test");
     remoteConfig.AddURI(new URIish("http://everyones.loves.git/u/2"));
     transport = null;
 }
Ejemplo n.º 8
0
        public virtual void TestSimpleTimeout()
        {
            ReadConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" +
                       "fetch = +refs/heads/*:refs/remotes/spearce/*\n" + "timeout = 12\n");
            RemoteConfig rc = new RemoteConfig(config, "spearce");

            NUnit.Framework.Assert.AreEqual(12, rc.Timeout);
        }
Ejemplo n.º 9
0
        public override void SetUp()
        {
            base.SetUp();
            Config config = ((FileBasedConfig)db.GetConfig());

            remoteConfig = new RemoteConfig(config, "test");
            remoteConfig.AddURI(new URIish("http://everyones.loves.git/u/2"));
            transport = null;
        }
Ejemplo n.º 10
0
        public virtual void NoInsteadOf()
        {
            config.SetString("remote", "origin", "url", "short:project.git");
            config.SetString("url", "https://server/repos/", "name", "short:");
            RemoteConfig rc = new RemoteConfig(config, "origin");

            NUnit.Framework.Assert.IsFalse(rc.URIs.IsEmpty());
            NUnit.Framework.Assert.AreEqual("short:project.git", rc.URIs[0].ToASCIIString());
        }
Ejemplo n.º 11
0
        public virtual void TestCreateOrigin()
        {
            RemoteConfig rc = new RemoteConfig(config, "origin");

            rc.AddURI(new URIish("/some/dir"));
            rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.Name + "/*"));
            rc.Update(config);
            CheckConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"
                        );
        }
Ejemplo n.º 12
0
        public virtual void TestUnknown()
        {
            ReadConfig(string.Empty);
            RemoteConfig rc = new RemoteConfig(config, "backup");

            NUnit.Framework.Assert.AreEqual(0, rc.URIs.Count);
            NUnit.Framework.Assert.AreEqual(0, rc.FetchRefSpecs.Count);
            NUnit.Framework.Assert.AreEqual(0, rc.PushRefSpecs.Count);
            NUnit.Framework.Assert.AreEqual("git-upload-pack", rc.UploadPack);
            NUnit.Framework.Assert.AreEqual("git-receive-pack", rc.ReceivePack);
        }
Ejemplo n.º 13
0
        public virtual void MultiplePushInsteadOf()
        {
            config.SetString("remote", "origin", "pushurl", "prefixproject.git");
            config.SetStringList("url", "https://server/repos/", "pushInsteadOf", Arrays.AsList
                                     ("pre", "prefix", "pref", "perf"));
            RemoteConfig rc = new RemoteConfig(config, "origin");

            NUnit.Framework.Assert.IsFalse(rc.PushURIs.IsEmpty());
            NUnit.Framework.Assert.AreEqual("https://server/repos/project.git", rc.PushURIs[0
                                            ].ToASCIIString());
        }
Ejemplo n.º 14
0
        public virtual void TestSaveAllTags()
        {
            RemoteConfig rc = new RemoteConfig(config, "origin");

            rc.AddURI(new URIish("/some/dir"));
            rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.Name + "/*"));
            rc.TagOpt = TagOpt.FETCH_TAGS;
            rc.Update(config);
            CheckConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"
                        + "\ttagopt = --tags\n");
        }
Ejemplo n.º 15
0
        public virtual void TestLocalTransportWithRelativePath()
        {
            FileRepository other    = CreateWorkRepository();
            string         otherDir = other.WorkTree.GetName();
            RemoteConfig   config   = new RemoteConfig(((FileBasedConfig)db.GetConfig()), "other"
                                                       );

            config.AddURI(new URIish("../" + otherDir));
            // Should not throw NoRemoteRepositoryException
            transport = NGit.Transport.Transport.Open(db, config);
        }
Ejemplo n.º 16
0
        public virtual void TestRemoveOnlyURI()
        {
            ReadConfig(string.Empty);
            URIish       a  = new URIish("/some/dir");
            RemoteConfig rc = new RemoteConfig(config, "backup");

            NUnit.Framework.Assert.IsTrue(rc.AddURI(a));
            NUnit.Framework.Assert.AreEqual(1, rc.URIs.Count);
            NUnit.Framework.Assert.AreSame(a, rc.URIs[0]);
            NUnit.Framework.Assert.IsTrue(rc.RemoveURI(a));
            NUnit.Framework.Assert.AreEqual(0, rc.URIs.Count);
        }
Ejemplo n.º 17
0
        public virtual void TestSaveAddURI()
        {
            ReadConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" +
                       "fetch = +refs/heads/*:refs/remotes/spearce/*\n");
            RemoteConfig rc = new RemoteConfig(config, "spearce");

            rc.AddURI(new URIish("/some/dir"));
            NUnit.Framework.Assert.AreEqual(2, rc.URIs.Count);
            rc.Update(config);
            CheckConfig("[remote \"spearce\"]\n" + "\turl = http://www.spearce.org/egit.git\n"
                        + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/spearce/*\n");
        }
Ejemplo n.º 18
0
        public virtual void TestAddURI()
        {
            ReadConfig(string.Empty);
            URIish       uri = new URIish("/some/dir");
            RemoteConfig rc  = new RemoteConfig(config, "backup");

            NUnit.Framework.Assert.AreEqual(0, rc.URIs.Count);
            NUnit.Framework.Assert.IsTrue(rc.AddURI(uri));
            NUnit.Framework.Assert.AreEqual(1, rc.URIs.Count);
            NUnit.Framework.Assert.AreSame(uri, rc.URIs[0]);
            NUnit.Framework.Assert.IsFalse(rc.AddURI(new URIish(uri.ToString())));
            NUnit.Framework.Assert.AreEqual(1, rc.URIs.Count);
        }
Ejemplo n.º 19
0
        public virtual void TestRemoveLastURI()
        {
            ReadConfig(string.Empty);
            URIish       a  = new URIish("/some/dir");
            URIish       b  = new URIish("/another/dir");
            URIish       c  = new URIish("/more/dirs");
            RemoteConfig rc = new RemoteConfig(config, "backup");

            NUnit.Framework.Assert.IsTrue(rc.AddURI(a));
            NUnit.Framework.Assert.IsTrue(rc.AddURI(b));
            NUnit.Framework.Assert.IsTrue(rc.AddURI(c));
            NUnit.Framework.Assert.AreEqual(3, rc.URIs.Count);
            NUnit.Framework.Assert.AreSame(a, rc.URIs[0]);
            NUnit.Framework.Assert.AreSame(b, rc.URIs[1]);
            NUnit.Framework.Assert.AreSame(c, rc.URIs[2]);
            NUnit.Framework.Assert.IsTrue(rc.RemoveURI(c));
            NUnit.Framework.Assert.AreEqual(2, rc.URIs.Count);
            NUnit.Framework.Assert.AreSame(a, rc.URIs[0]);
            NUnit.Framework.Assert.AreSame(b, rc.URIs[1]);
        }
Ejemplo n.º 20
0
		public virtual void TestFetch()
		{
			// create other repository
			Repository db2 = CreateWorkRepository();
			Git git2 = new Git(db2);
			// setup the first repository to fetch from the second repository
			StoredConfig config = ((FileBasedConfig)db.GetConfig());
			RemoteConfig remoteConfig = new RemoteConfig(config, "test");
			URIish uri = new URIish(db2.Directory.ToURI().ToURL());
			remoteConfig.AddURI(uri);
			remoteConfig.Update(config);
			config.Save();
			// create some refs via commits and tag
			RevCommit commit = git2.Commit().SetMessage("initial commit").Call();
			RevTag tag = git2.Tag().SetName("tag").Call();
			Git git1 = new Git(db);
			RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
			git1.Fetch().SetRemote("test").SetRefSpecs(spec).Call();
			NUnit.Framework.Assert.AreEqual(commit.Id, db.Resolve(commit.Id.GetName() + "^{commit}"
				));
			NUnit.Framework.Assert.AreEqual(tag.Id, db.Resolve(tag.Id.GetName()));
		}
Ejemplo n.º 21
0
 /// <summary>Open a new transport instance to connect two repositories.</summary>
 /// <remarks>
 /// Open a new transport instance to connect two repositories.
 /// <p>
 /// This method assumes
 /// <see cref="Operation.FETCH">Operation.FETCH</see>
 /// .
 /// </remarks>
 /// <param name="local">existing local repository.</param>
 /// <param name="cfg">
 /// configuration describing how to connect to the remote
 /// repository.
 /// </param>
 /// <returns>
 /// the new transport instance. Never null. In case of multiple URIs
 /// in remote configuration, only the first is chosen.
 /// </returns>
 /// <exception cref="System.NotSupportedException">the protocol specified is not supported.
 /// 	</exception>
 /// <exception cref="NGit.Errors.TransportException">the transport cannot open this URI.
 /// 	</exception>
 /// <exception cref="System.ArgumentException">
 /// if provided remote configuration doesn't have any URI
 /// associated.
 /// </exception>
 public static NGit.Transport.Transport Open(Repository local, RemoteConfig cfg)
 {
     return Open(local, cfg, Transport.Operation.FETCH);
 }
Ejemplo n.º 22
0
        private static IList<URIish> GetURIs(RemoteConfig cfg, Transport.Operation op)
        {
            switch (op)
            {
                case Transport.Operation.FETCH:
                {
                    return cfg.URIs;
                }

                case Transport.Operation.PUSH:
                {
                    IList<URIish> uris = cfg.PushURIs;
                    if (uris.IsEmpty())
                    {
                        uris = cfg.URIs;
                    }
                    return uris;
                }

                default:
                {
                    throw new ArgumentException(op.ToString());
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>Open a new transport instance to connect two repositories.</summary>
        /// <remarks>Open a new transport instance to connect two repositories.</remarks>
        /// <param name="local">existing local repository.</param>
        /// <param name="remote">
        /// location of the remote repository - may be URI or remote
        /// configuration name.
        /// </param>
        /// <param name="op">
        /// planned use of the returned Transport; the URI may differ
        /// based on the type of connection desired.
        /// </param>
        /// <returns>
        /// the new transport instance. Never null. In case of multiple URIs
        /// in remote configuration, only the first is chosen.
        /// </returns>
        /// <exception cref="Sharpen.URISyntaxException">
        /// the location is not a remote defined in the configuration
        /// file and is not a well-formed URL.
        /// </exception>
        /// <exception cref="System.NotSupportedException">the protocol specified is not supported.
        /// 	</exception>
        /// <exception cref="NGit.Errors.TransportException">the transport cannot open this URI.
        /// 	</exception>
        public static NGit.Transport.Transport Open(Repository local, string remote, Transport.Operation
			 op)
        {
            RemoteConfig cfg = new RemoteConfig(local.GetConfig(), remote);
            if (DoesNotExist(cfg))
            {
                return Open(local, new URIish(remote), null);
            }
            return Open(local, cfg, op);
        }
Ejemplo n.º 24
0
 public override void SetUp()
 {
     base.SetUp();
     dbTarget = CreateWorkRepository();
     source = new Git(db);
     target = new Git(dbTarget);
     // put some file in the source repo
     sourceFile = new FilePath(db.WorkTree, "SomeFile.txt");
     WriteToFile(sourceFile, "Hello world");
     // and commit it
     source.Add().AddFilepattern("SomeFile.txt").Call();
     source.Commit().SetMessage("Initial commit for source").Call();
     // configure the target repo to connect to the source via "origin"
     StoredConfig targetConfig = ((FileBasedConfig)dbTarget.GetConfig());
     targetConfig.SetString("branch", "master", "remote", "origin");
     targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
     RemoteConfig config = new RemoteConfig(targetConfig, "origin");
     config.AddURI(new URIish(source.GetRepository().WorkTree.GetPath()));
     config.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
     config.Update(targetConfig);
     targetConfig.Save();
     targetFile = new FilePath(dbTarget.WorkTree, "SomeFile.txt");
     // make sure we have the same content
     target.Pull().Call();
     target.Checkout().SetStartPoint("refs/remotes/origin/master").SetName("master").Call
         ();
     targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
     targetConfig.SetBoolean("branch", "master", "rebase", true);
     targetConfig.Save();
     AssertFileContentsEqual(targetFile, "Hello world");
 }
Ejemplo n.º 25
0
 private static bool DoesNotExist(RemoteConfig cfg)
 {
     return cfg.URIs.IsEmpty() && cfg.PushURIs.IsEmpty();
 }
Ejemplo n.º 26
0
		public virtual void TestSaveTimeout()
		{
			RemoteConfig rc = new RemoteConfig(config, "origin");
			rc.AddURI(new URIish("/some/dir"));
			rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.Name + "/*"));
			rc.Timeout = 60;
			rc.Update(config);
			CheckConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"
				 + "\ttimeout = 60\n");
		}
Ejemplo n.º 27
0
        /// <summary>Open a new transport instance to connect two repositories.</summary>
        /// <remarks>Open a new transport instance to connect two repositories.</remarks>
        /// <param name="local">existing local repository.</param>
        /// <param name="cfg">
        /// configuration describing how to connect to the remote
        /// repository.
        /// </param>
        /// <param name="op">
        /// planned use of the returned Transport; the URI may differ
        /// based on the type of connection desired.
        /// </param>
        /// <returns>
        /// the new transport instance. Never null. In case of multiple URIs
        /// in remote configuration, only the first is chosen.
        /// </returns>
        /// <exception cref="System.NotSupportedException">the protocol specified is not supported.
        /// 	</exception>
        /// <exception cref="NGit.Errors.TransportException">the transport cannot open this URI.
        /// 	</exception>
        /// <exception cref="System.ArgumentException">
        /// if provided remote configuration doesn't have any URI
        /// associated.
        /// </exception>
        public static NGit.Transport.Transport Open(Repository local, RemoteConfig cfg, Transport.Operation
			 op)
        {
            IList<URIish> uris = GetURIs(cfg, op);
            if (uris.IsEmpty())
            {
                throw new ArgumentException(MessageFormat.Format(JGitText.Get().remoteConfigHasNoURIAssociated
                    , cfg.Name));
            }
            NGit.Transport.Transport tn = Open(local, uris[0], cfg.Name);
            tn.ApplyConfig(cfg);
            return tn;
        }
Ejemplo n.º 28
0
		public virtual void TestSaveAllTags()
		{
			RemoteConfig rc = new RemoteConfig(config, "origin");
			rc.AddURI(new URIish("/some/dir"));
			rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.Name + "/*"));
			rc.TagOpt = TagOpt.FETCH_TAGS;
			rc.Update(config);
			CheckConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"
				 + "\ttagopt = --tags\n");
		}
Ejemplo n.º 29
0
		public virtual void TestSimpleTimeout()
		{
			ReadConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" +
				 "fetch = +refs/heads/*:refs/remotes/spearce/*\n" + "timeout = 12\n");
			RemoteConfig rc = new RemoteConfig(config, "spearce");
			NUnit.Framework.Assert.AreEqual(12, rc.Timeout);
		}
Ejemplo n.º 30
0
		public virtual void TestRemoveOnlyURI()
		{
			ReadConfig(string.Empty);
			URIish a = new URIish("/some/dir");
			RemoteConfig rc = new RemoteConfig(config, "backup");
			NUnit.Framework.Assert.IsTrue(rc.AddURI(a));
			NUnit.Framework.Assert.AreEqual(1, rc.URIs.Count);
			NUnit.Framework.Assert.AreSame(a, rc.URIs[0]);
			NUnit.Framework.Assert.IsTrue(rc.RemoveURI(a));
			NUnit.Framework.Assert.AreEqual(0, rc.URIs.Count);
		}
Ejemplo n.º 31
0
		public virtual void TestSaveRemoveFirstURI()
		{
			ReadConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" +
				 "url = /some/dir\n" + "fetch = +refs/heads/*:refs/remotes/spearce/*\n");
			RemoteConfig rc = new RemoteConfig(config, "spearce");
			NUnit.Framework.Assert.AreEqual(2, rc.URIs.Count);
			rc.RemoveURI(new URIish("http://www.spearce.org/egit.git"));
			NUnit.Framework.Assert.AreEqual(1, rc.URIs.Count);
			rc.Update(config);
			CheckConfig("[remote \"spearce\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/spearce/*\n"
				);
		}
Ejemplo n.º 32
0
		public virtual void TestRemoveLastURI()
		{
			ReadConfig(string.Empty);
			URIish a = new URIish("/some/dir");
			URIish b = new URIish("/another/dir");
			URIish c = new URIish("/more/dirs");
			RemoteConfig rc = new RemoteConfig(config, "backup");
			NUnit.Framework.Assert.IsTrue(rc.AddURI(a));
			NUnit.Framework.Assert.IsTrue(rc.AddURI(b));
			NUnit.Framework.Assert.IsTrue(rc.AddURI(c));
			NUnit.Framework.Assert.AreEqual(3, rc.URIs.Count);
			NUnit.Framework.Assert.AreSame(a, rc.URIs[0]);
			NUnit.Framework.Assert.AreSame(b, rc.URIs[1]);
			NUnit.Framework.Assert.AreSame(c, rc.URIs[2]);
			NUnit.Framework.Assert.IsTrue(rc.RemoveURI(c));
			NUnit.Framework.Assert.AreEqual(2, rc.URIs.Count);
			NUnit.Framework.Assert.AreSame(a, rc.URIs[0]);
			NUnit.Framework.Assert.AreSame(b, rc.URIs[1]);
		}
Ejemplo n.º 33
0
        /// <summary>Open new transport instances to connect two repositories.</summary>
        /// <remarks>
        /// Open new transport instances to connect two repositories.
        /// <p>
        /// This method assumes
        /// <see cref="Operation.FETCH">Operation.FETCH</see>
        /// .
        /// </remarks>
        /// <param name="local">existing local repository.</param>
        /// <param name="cfg">
        /// configuration describing how to connect to the remote
        /// repository.
        /// </param>
        /// <returns>
        /// the list of new transport instances for every URI in remote
        /// configuration.
        /// </returns>
        /// <exception cref="System.NotSupportedException">the protocol specified is not supported.
        /// 	</exception>
        /// <exception cref="NGit.Errors.TransportException">the transport cannot open this URI.
        /// 	</exception>
        public static IList<NGit.Transport.Transport> OpenAll(Repository local, RemoteConfig
			 cfg)
        {
            return OpenAll(local, cfg, Transport.Operation.FETCH);
        }
Ejemplo n.º 34
0
		internal RemoteSource (StoredConfig cfg, RemoteConfig rem)
		{
			this.cfg = cfg;
			RepoRemote = rem;
			Name = rem.Name;
			FetchUrl = rem.URIs.Select (u => u.ToString ()).FirstOrDefault ();
			PushUrl = rem.PushURIs.Select (u => u.ToString ()).FirstOrDefault ();
			if (string.IsNullOrEmpty (PushUrl))
				PushUrl = FetchUrl;
		}
Ejemplo n.º 35
0
		public void Push (IProgressMonitor monitor, string remote, string remoteBranch)
		{
			RemoteConfig remoteConfig = new RemoteConfig (RootRepository.GetConfig (), remote);
			Transport tp = Transport.Open (RootRepository, remoteConfig);
			
			string remoteRef = "refs/heads/" + remoteBranch;
			
			RemoteRefUpdate rr = new RemoteRefUpdate (RootRepository, RootRepository.GetBranch (), remoteRef, false, null, null);
			List<RemoteRefUpdate> list = new List<RemoteRefUpdate> ();
			list.Add (rr);
			using (var gm = new GitMonitor (monitor))
				tp.Push (gm, list);
			switch (rr.GetStatus ()) {
			case RemoteRefUpdate.Status.UP_TO_DATE: monitor.ReportSuccess (GettextCatalog.GetString ("Remote branch is up to date.")); break;
			case RemoteRefUpdate.Status.REJECTED_NODELETE: monitor.ReportError (GettextCatalog.GetString ("The server is configured to deny deletion of the branch"), null); break;
			case RemoteRefUpdate.Status.REJECTED_NONFASTFORWARD: monitor.ReportError (GettextCatalog.GetString ("The update is a non-fast-forward update. Merge the remote changes before pushing again."), null); break;
			case RemoteRefUpdate.Status.OK:
				monitor.ReportSuccess (GettextCatalog.GetString ("Push operation successfully completed."));
				// Update the remote branch
				ObjectId headId = rr.GetNewObjectId ();
				RefUpdate updateRef = RootRepository.UpdateRef (Constants.R_REMOTES + remote + "/" + remoteBranch);
				updateRef.SetNewObjectId(headId);
				updateRef.Update();
				break;
			default:
				string msg = rr.GetMessage ();
				msg = !string.IsNullOrEmpty (msg) ? msg : GettextCatalog.GetString ("Push operation failed");
				monitor.ReportError (msg, null);
				break;
			}
		}
Ejemplo n.º 36
0
 /// <summary>Apply provided remote configuration on this transport.</summary>
 /// <remarks>Apply provided remote configuration on this transport.</remarks>
 /// <param name="cfg">configuration to apply on this transport.</param>
 public virtual void ApplyConfig(RemoteConfig cfg)
 {
     SetOptionUploadPack(cfg.UploadPack);
     SetOptionReceivePack(cfg.ReceivePack);
     SetTagOpt(cfg.TagOpt);
     fetch = cfg.FetchRefSpecs;
     push = cfg.PushRefSpecs;
     timeout = cfg.Timeout;
 }
Ejemplo n.º 37
0
        /// <summary>Open new transport instances to connect two repositories.</summary>
        /// <remarks>Open new transport instances to connect two repositories.</remarks>
        /// <param name="local">existing local repository.</param>
        /// <param name="remote">
        /// location of the remote repository - may be URI or remote
        /// configuration name.
        /// </param>
        /// <param name="op">
        /// planned use of the returned Transport; the URI may differ
        /// based on the type of connection desired.
        /// </param>
        /// <returns>
        /// the list of new transport instances for every URI in remote
        /// configuration.
        /// </returns>
        /// <exception cref="Sharpen.URISyntaxException">
        /// the location is not a remote defined in the configuration
        /// file and is not a well-formed URL.
        /// </exception>
        /// <exception cref="System.NotSupportedException">the protocol specified is not supported.
        /// 	</exception>
        /// <exception cref="NGit.Errors.TransportException">the transport cannot open this URI.
        /// 	</exception>
        public static IList<NGit.Transport.Transport> OpenAll(Repository local, string remote
			, Transport.Operation op)
        {
            RemoteConfig cfg = new RemoteConfig(local.GetConfig(), remote);
            if (DoesNotExist(cfg))
            {
                AList<NGit.Transport.Transport> transports = new AList<NGit.Transport.Transport>(
                    1);
                transports.AddItem(Open(local, new URIish(remote), null));
                return transports;
            }
            return OpenAll(local, cfg, op);
        }
Ejemplo n.º 38
0
		public virtual void TestSimpleAlwaysTags()
		{
			ReadConfig("[remote \"spearce\"]\n" + "url = http://www.spearce.org/egit.git\n" +
				 "fetch = +refs/heads/*:refs/remotes/spearce/*\n" + "tagopt = --tags\n");
			RemoteConfig rc = new RemoteConfig(config, "spearce");
			NUnit.Framework.Assert.AreEqual(TagOpt.FETCH_TAGS, rc.TagOpt);
		}
Ejemplo n.º 39
0
        /// <summary>Open new transport instances to connect two repositories.</summary>
        /// <remarks>Open new transport instances to connect two repositories.</remarks>
        /// <param name="local">existing local repository.</param>
        /// <param name="cfg">
        /// configuration describing how to connect to the remote
        /// repository.
        /// </param>
        /// <param name="op">
        /// planned use of the returned Transport; the URI may differ
        /// based on the type of connection desired.
        /// </param>
        /// <returns>
        /// the list of new transport instances for every URI in remote
        /// configuration.
        /// </returns>
        /// <exception cref="System.NotSupportedException">the protocol specified is not supported.
        /// 	</exception>
        /// <exception cref="NGit.Errors.TransportException">the transport cannot open this URI.
        /// 	</exception>
        public static IList<NGit.Transport.Transport> OpenAll(Repository local, RemoteConfig
			 cfg, Transport.Operation op)
        {
            IList<URIish> uris = GetURIs(cfg, op);
            IList<NGit.Transport.Transport> transports = new AList<NGit.Transport.Transport>(
                uris.Count);
            foreach (URIish uri in uris)
            {
                NGit.Transport.Transport tn = Open(local, uri, cfg.Name);
                tn.ApplyConfig(cfg);
                transports.AddItem(tn);
            }
            return transports;
        }
Ejemplo n.º 40
0
		public virtual void TestBackup()
		{
			ReadConfig("[remote \"backup\"]\n" + "url = http://www.spearce.org/egit.git\n" + 
				"url = [email protected]:/srv/git/egit.git\n" + "push = +refs/heads/*:refs/heads/*\n"
				 + "push = refs/tags/*:refs/tags/*\n");
			RemoteConfig rc = new RemoteConfig(config, "backup");
			IList<URIish> allURIs = rc.URIs;
			RefSpec spec;
			NUnit.Framework.Assert.AreEqual("backup", rc.Name);
			NUnit.Framework.Assert.IsNotNull(allURIs);
			NUnit.Framework.Assert.IsNotNull(rc.FetchRefSpecs);
			NUnit.Framework.Assert.IsNotNull(rc.PushRefSpecs);
			NUnit.Framework.Assert.AreEqual(2, allURIs.Count);
			NUnit.Framework.Assert.AreEqual("http://www.spearce.org/egit.git", allURIs[0].ToString
				());
			NUnit.Framework.Assert.AreEqual("[email protected]:/srv/git/egit.git", allURIs[1].ToString
				());
			NUnit.Framework.Assert.AreEqual(0, rc.FetchRefSpecs.Count);
			NUnit.Framework.Assert.AreEqual(2, rc.PushRefSpecs.Count);
			spec = rc.PushRefSpecs[0];
			NUnit.Framework.Assert.IsTrue(spec.IsForceUpdate());
			NUnit.Framework.Assert.IsTrue(spec.IsWildcard());
			NUnit.Framework.Assert.AreEqual("refs/heads/*", spec.GetSource());
			NUnit.Framework.Assert.AreEqual("refs/heads/*", spec.GetDestination());
			spec = rc.PushRefSpecs[1];
			NUnit.Framework.Assert.IsFalse(spec.IsForceUpdate());
			NUnit.Framework.Assert.IsTrue(spec.IsWildcard());
			NUnit.Framework.Assert.AreEqual("refs/tags/*", spec.GetSource());
			NUnit.Framework.Assert.AreEqual("refs/tags/*", spec.GetDestination());
		}
Ejemplo n.º 41
0
		public static FileRepository Init (string targetLocalPath, string url, IProgressMonitor monitor)
		{
			InitCommand ci = new InitCommand ();
			ci.SetDirectory (targetLocalPath);
			var git = ci.Call ();
			FileRepository repo = (FileRepository) git.GetRepository ();
			
			string branch = Constants.R_HEADS + "master";
			
			RefUpdate head = repo.UpdateRef (Constants.HEAD);
			head.DisableRefLog ();
			head.Link (branch);
			
			RemoteConfig remoteConfig = new RemoteConfig (repo.GetConfig (), "origin");
			remoteConfig.AddURI (new URIish (url));
			
			string dst = Constants.R_REMOTES + remoteConfig.Name;
			RefSpec wcrs = new RefSpec();
			wcrs = wcrs.SetForceUpdate (true);
			wcrs = wcrs.SetSourceDestination (Constants.R_HEADS	+ "*", dst + "/*");
			
			remoteConfig.AddFetchRefSpec (wcrs);
	
			// we're setting up for a clone with a checkout
			repo.GetConfig().SetBoolean ("core", null, "bare", false);
	
			remoteConfig.Update (repo.GetConfig());
	
			repo.GetConfig().Save();
			return repo;
		}
Ejemplo n.º 42
0
		public virtual void TestUploadPack()
		{
			ReadConfig("[remote \"example\"]\n" + "url = [email protected]:egit.git\n" + "fetch = +refs/heads/*:refs/remotes/example/*\n"
				 + "uploadpack = /path/to/git/git-upload-pack\n" + "receivepack = /path/to/git/git-receive-pack\n"
				);
			RemoteConfig rc = new RemoteConfig(config, "example");
			IList<URIish> allURIs = rc.URIs;
			RefSpec spec;
			NUnit.Framework.Assert.AreEqual("example", rc.Name);
			NUnit.Framework.Assert.IsNotNull(allURIs);
			NUnit.Framework.Assert.IsNotNull(rc.FetchRefSpecs);
			NUnit.Framework.Assert.IsNotNull(rc.PushRefSpecs);
			NUnit.Framework.Assert.AreEqual(1, allURIs.Count);
			NUnit.Framework.Assert.AreEqual("[email protected]:egit.git", allURIs[0].ToString(
				));
			NUnit.Framework.Assert.AreEqual(1, rc.FetchRefSpecs.Count);
			spec = rc.FetchRefSpecs[0];
			NUnit.Framework.Assert.IsTrue(spec.IsForceUpdate());
			NUnit.Framework.Assert.IsTrue(spec.IsWildcard());
			NUnit.Framework.Assert.AreEqual("refs/heads/*", spec.GetSource());
			NUnit.Framework.Assert.AreEqual("refs/remotes/example/*", spec.GetDestination());
			NUnit.Framework.Assert.AreEqual(0, rc.PushRefSpecs.Count);
			NUnit.Framework.Assert.AreEqual("/path/to/git/git-upload-pack", rc.UploadPack);
			NUnit.Framework.Assert.AreEqual("/path/to/git/git-receive-pack", rc.ReceivePack);
		}
Ejemplo n.º 43
0
		public void AddRemote (RemoteSource remote, bool importTags)
		{
			if (string.IsNullOrEmpty (remote.Name))
				throw new InvalidOperationException ("Name not set");
			
			StoredConfig c = RootRepository.GetConfig ();
			RemoteConfig rc = new RemoteConfig (c, remote.Name);
			c.Save ();
			remote.RepoRemote = rc;
			remote.cfg = c;
			UpdateRemote (remote);
		}
Ejemplo n.º 44
0
		public virtual void TestUnknown()
		{
			ReadConfig(string.Empty);
			RemoteConfig rc = new RemoteConfig(config, "backup");
			NUnit.Framework.Assert.AreEqual(0, rc.URIs.Count);
			NUnit.Framework.Assert.AreEqual(0, rc.FetchRefSpecs.Count);
			NUnit.Framework.Assert.AreEqual(0, rc.PushRefSpecs.Count);
			NUnit.Framework.Assert.AreEqual("git-upload-pack", rc.UploadPack);
			NUnit.Framework.Assert.AreEqual("git-receive-pack", rc.ReceivePack);
		}
Ejemplo n.º 45
0
		public override void Update (FilePath[] localPaths, bool recurse, IProgressMonitor monitor)
		{
			IEnumerable<DiffEntry> statusList = null;
			
			monitor.BeginTask (GettextCatalog.GetString ("Updating"), 5);
			
			// Fetch remote commits
			string remote = GetCurrentRemote ();
			if (remote == null)
				throw new InvalidOperationException ("No remotes defined");
			monitor.Log.WriteLine (GettextCatalog.GetString ("Fetching from '{0}'", remote));
			RemoteConfig remoteConfig = new RemoteConfig (RootRepository.GetConfig (), remote);
			Transport tn = Transport.Open (RootRepository, remoteConfig);
			using (var gm = new GitMonitor (monitor))
				tn.Fetch (gm, null);
			monitor.Step (1);
			
			string upstreamRef = GitUtil.GetUpstreamSource (RootRepository, GetCurrentBranch ());
			if (upstreamRef == null)
				upstreamRef = GetCurrentRemote () + "/" + GetCurrentBranch ();
			
			if (GitService.UseRebaseOptionWhenPulling)
				Rebase (upstreamRef, GitService.StashUnstashWhenUpdating, monitor);
			else
				Merge (upstreamRef, GitService.StashUnstashWhenUpdating, monitor);

			monitor.Step (1);
			
			// Notify changes
			if (statusList != null)
				NotifyFileChanges (monitor, statusList);
			
			monitor.EndTask ();
		}
Ejemplo n.º 46
0
		public virtual void TestAddURI()
		{
			ReadConfig(string.Empty);
			URIish uri = new URIish("/some/dir");
			RemoteConfig rc = new RemoteConfig(config, "backup");
			NUnit.Framework.Assert.AreEqual(0, rc.URIs.Count);
			NUnit.Framework.Assert.IsTrue(rc.AddURI(uri));
			NUnit.Framework.Assert.AreEqual(1, rc.URIs.Count);
			NUnit.Framework.Assert.AreSame(uri, rc.URIs[0]);
			NUnit.Framework.Assert.IsFalse(rc.AddURI(new URIish(uri.ToString())));
			NUnit.Framework.Assert.AreEqual(1, rc.URIs.Count);
		}