public 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");
            Assert.IsTrue(rc.AddURI(a));
            Assert.IsTrue(rc.AddURI(b));
            Assert.IsTrue(rc.AddURI(c));

            Assert.AreEqual(3, rc.URIs.Count);
            Assert.AreSame(a, rc.URIs[0]);
            Assert.AreSame(b, rc.URIs[1]);
            Assert.AreEqual(c, rc.URIs[2]);

            Assert.IsTrue(rc.RemoveURI(c));
            Assert.AreEqual(2, rc.URIs.Count);
            Assert.AreSame(a, rc.URIs[0]);
            Assert.AreSame(b, rc.URIs[1]);
        }
Exemple #2
0
        public 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.SetTagOpt(TagOpt.FETCH_TAGS);
            rc.Update(config);

            checkConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n"
                        + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"
                        + "\ttagopt = --tags\n");
        }
        public void testRemoveOnlyURI()
        {
            readConfig(string.Empty);

            URIish a = new URIish("/some/dir");
            RemoteConfig rc = new RemoteConfig(config, "backup");
            Assert.IsTrue(rc.AddURI(a));

            Assert.AreEqual(1, rc.URIs.Count);
            Assert.AreSame(a, rc.URIs[0]);

            Assert.IsTrue(rc.RemoveURI(a));
            Assert.AreEqual(0, rc.URIs.Count);
        }
        public 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"));
            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");
        }
Exemple #5
0
        public virtual void TestTrackingUpdate()
        {
            Repository db2             = CreateBareRepository();
            string     remote          = "origin";
            string     branch          = "refs/heads/master";
            string     trackingBranch  = "refs/remotes/" + remote + "/master";
            Git        git             = new Git(db);
            RevCommit  commit1         = git.Commit().SetMessage("Initial commit").Call();
            RefUpdate  branchRefUpdate = db.UpdateRef(branch);

            branchRefUpdate.SetNewObjectId(commit1.Id);
            branchRefUpdate.Update();
            RefUpdate trackingBranchRefUpdate = db.UpdateRef(trackingBranch);

            trackingBranchRefUpdate.SetNewObjectId(commit1.Id);
            trackingBranchRefUpdate.Update();
            StoredConfig config       = ((FileBasedConfig)db.GetConfig());
            RemoteConfig remoteConfig = new RemoteConfig(config, remote);
            URIish       uri          = new URIish(db2.Directory.ToURI().ToURL());

            remoteConfig.AddURI(uri);
            remoteConfig.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + remote +
                                                     "/*"));
            remoteConfig.Update(config);
            config.Save();
            RevCommit             commit2        = git.Commit().SetMessage("Commit to push").Call();
            RefSpec               spec           = new RefSpec(branch + ":" + branch);
            Iterable <PushResult> resultIterable = git.Push().SetRemote(remote).SetRefSpecs(spec
                                                                                            ).Call();
            PushResult        result            = resultIterable.Iterator().Next();
            TrackingRefUpdate trackingRefUpdate = result.GetTrackingRefUpdate(trackingBranch);

            NUnit.Framework.Assert.IsNotNull(trackingRefUpdate);
            NUnit.Framework.Assert.AreEqual(trackingBranch, trackingRefUpdate.GetLocalName());
            NUnit.Framework.Assert.AreEqual(branch, trackingRefUpdate.GetRemoteName());
            NUnit.Framework.Assert.AreEqual(commit2.Id, trackingRefUpdate.GetNewObjectId());
            NUnit.Framework.Assert.AreEqual(commit2.Id, db.Resolve(trackingBranch));
            NUnit.Framework.Assert.AreEqual(commit2.Id, db2.Resolve(branch));
        }
        public virtual void TestPushWithRefSpecFromConfig()
        {
            Git          git          = new Git(db);
            Git          git2         = new Git(CreateBareRepository());
            StoredConfig config       = git.GetRepository().GetConfig();
            RemoteConfig remoteConfig = new RemoteConfig(config, "test");
            URIish       uri          = new URIish(git2.GetRepository().Directory.ToURI().ToURL());

            remoteConfig.AddURI(uri);
            remoteConfig.AddPushRefSpec(new RefSpec("HEAD:refs/heads/newbranch"));
            remoteConfig.Update(config);
            config.Save();
            WriteTrashFile("f", "content of f");
            git.Add().AddFilepattern("f").Call();
            RevCommit commit = git.Commit().SetMessage("adding f").Call();

            NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/master"
                                                                               ));
            git.Push().SetRemote("test").Call();
            NUnit.Framework.Assert.AreEqual(commit.Id, git2.GetRepository().Resolve("refs/heads/newbranch"
                                                                                    ));
        }
Exemple #7
0
        /// <exception cref="System.Exception"></exception>
        private Git SetUpRepoWithRemote()
        {
            Repository remoteRepository = CreateWorkRepository();
            Git        remoteGit        = new Git(remoteRepository);

            // commit something
            WriteTrashFile("Test.txt", "Hello world");
            remoteGit.Add().AddFilepattern("Test.txt").Call();
            initialCommit = remoteGit.Commit().SetMessage("Initial commit").Call();
            WriteTrashFile("Test.txt", "Some change");
            remoteGit.Add().AddFilepattern("Test.txt").Call();
            secondCommit = remoteGit.Commit().SetMessage("Second commit").Call();
            // create a master branch
            RefUpdate rup = remoteRepository.UpdateRef("refs/heads/master");

            rup.SetNewObjectId(initialCommit.Id);
            rup.ForceUpdate();
            Repository   localRepository = CreateWorkRepository();
            Git          localGit        = new Git(localRepository);
            StoredConfig config          = localRepository.GetConfig();
            RemoteConfig rc = new RemoteConfig(config, "origin");

            rc.AddURI(new URIish(remoteRepository.Directory.GetPath()));
            rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
            rc.Update(config);
            config.Save();
            FetchResult res = localGit.Fetch().SetRemote("origin").Call();

            NUnit.Framework.Assert.IsFalse(res.GetTrackingRefUpdates().IsEmpty());
            rup = localRepository.UpdateRef("refs/heads/master");
            rup.SetNewObjectId(initialCommit.Id);
            rup.ForceUpdate();
            rup = localRepository.UpdateRef(Constants.HEAD);
            rup.Link("refs/heads/master");
            rup.SetNewObjectId(initialCommit.Id);
            rup.Update();
            return(localGit);
        }
        public virtual void TestCheckoutRemoteTrackingWithoutLocalBranch()
        {
            // create second repository
            Repository db2  = CreateWorkRepository();
            Git        git2 = new Git(db2);
            // setup the second repository to fetch from the first repository
            StoredConfig config       = db2.GetConfig();
            RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
            URIish       uri          = new URIish(db.Directory.ToURI().ToURL());

            remoteConfig.AddURI(uri);
            remoteConfig.Update(config);
            config.Save();
            // fetch from first repository
            RefSpec spec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");

            git2.Fetch().SetRemote("origin").SetRefSpecs(spec).Call();
            // checkout remote tracking branch in second repository
            // (no local branches exist yet in second repository)
            git2.Checkout().SetName("remotes/origin/test").Call();
            NUnit.Framework.Assert.AreEqual("[Test.txt, mode:100644, content:Some change]", IndexState
                                                (db2, CONTENT));
        }
Exemple #9
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()));
        }
Exemple #10
0
 /// <summary>
 /// Add a new URI to the end of the list of URIs.
 /// </summary>
 /// <param name="toAdd">the new URI to add to this remote.</param>
 /// <returns>true if the URI was added; false if it already exists.</returns>
 public bool AddURI(URIish toAdd)
 {
     return(_config.AddURI(toAdd));
 }