public virtual void RenameBranchNoConfigValues()
        {
            StoredConfig config = git.GetRepository().GetConfig();

            config.UnsetSection(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER);
            config.Save();
            string branch = "b1";

            NUnit.Framework.Assert.IsTrue(config.GetNames(ConfigConstants.CONFIG_BRANCH_SECTION
                                                          , Constants.MASTER).IsEmpty());
            NUnit.Framework.Assert.IsNotNull(git.BranchRename().SetNewName(branch).Call());
            config = git.GetRepository().GetConfig();
            NUnit.Framework.Assert.IsTrue(config.GetNames(ConfigConstants.CONFIG_BRANCH_SECTION
                                                          , Constants.MASTER).IsEmpty());
            NUnit.Framework.Assert.IsTrue(config.GetNames(ConfigConstants.CONFIG_BRANCH_SECTION
                                                          , branch).IsEmpty());
        }
Ejemplo n.º 2
0
        public virtual void TestRenameRemoteTrackingBranch()
        {
            Git localGit     = SetUpRepoWithRemote();
            Ref remoteBranch = localGit.BranchList().SetListMode(ListBranchCommand.ListMode.REMOTE
                                                                 ).Call()[0];
            Ref renamed = localGit.BranchRename().SetOldName(remoteBranch.GetName()).SetNewName
                              ("newRemote").Call();

            NUnit.Framework.Assert.AreEqual(Constants.R_REMOTES + "newRemote", renamed.GetName
                                                ());
        }
Ejemplo n.º 3
0
        public virtual void TestPullConfigRenameLocalBranch()
        {
            Git localGit = SetUpRepoWithRemote();

            // by default, we should not create pull configuration
            CreateBranch(localGit, "newFromMaster", false, "master", null);
            NUnit.Framework.Assert.IsNull(localGit.GetRepository().GetConfig().GetString("branch"
                                                                                         , "newFromMaster", "remote"));
            localGit.BranchDelete().SetBranchNames("newFromMaster").Call();
            // use --track
            CreateBranch(localGit, "newFromMaster", false, "master", CreateBranchCommand.SetupUpstreamMode
                         .TRACK);
            NUnit.Framework.Assert.AreEqual(".", localGit.GetRepository().GetConfig().GetString
                                                ("branch", "newFromMaster", "remote"));
            localGit.BranchRename().SetOldName("newFromMaster").SetNewName("renamed").Call();
            NUnit.Framework.Assert.IsNull(localGit.GetRepository().GetConfig().GetString("branch"
                                                                                         , "newFromMaster", "remote"), ".");
            NUnit.Framework.Assert.AreEqual(".", localGit.GetRepository().GetConfig().GetString
                                                ("branch", "renamed", "remote"));
            localGit.BranchDelete().SetBranchNames("renamed").Call();
            // the pull configuration should be gone after deletion
            NUnit.Framework.Assert.IsNull(localGit.GetRepository().GetConfig().GetString("branch"
                                                                                         , "newFromRemote", "remote"));
        }
Ejemplo n.º 4
0
		public void RenameBranch (string name, string newName)
		{
			var git = new NGit.Api.Git (RootRepository);
			git.BranchRename ().SetOldName (name).SetNewName (newName).Call ();
		}
Ejemplo n.º 5
0
        public virtual void TestRenameLocalBranch()
        {
            // null newName not allowed
            try
            {
                git.BranchRename().Call();
            }
            catch (InvalidRefNameException)
            {
            }
            // expected
            // invalid newName not allowed
            try
            {
                git.BranchRename().SetNewName("In va lid").Call();
            }
            catch (InvalidRefNameException)
            {
            }
            // expected
            // not existing name not allowed
            try
            {
                git.BranchRename().SetOldName("notexistingbranch").SetNewName("newname").Call();
            }
            catch (RefNotFoundException)
            {
            }
            // expected
            // create some branch
            CreateBranch(git, "existing", false, "master", null);
            // a local branch
            Ref branch = CreateBranch(git, "fromMasterForRename", false, "master", null);

            NUnit.Framework.Assert.AreEqual(Constants.R_HEADS + "fromMasterForRename", branch
                                            .GetName());
            Ref renamed = git.BranchRename().SetOldName("fromMasterForRename").SetNewName("newName"
                                                                                          ).Call();

            NUnit.Framework.Assert.AreEqual(Constants.R_HEADS + "newName", renamed.GetName());
            try
            {
                git.BranchRename().SetOldName(renamed.GetName()).SetNewName("existing").Call();
                NUnit.Framework.Assert.Fail("Should have failed");
            }
            catch (RefAlreadyExistsException)
            {
            }
            // expected
            try
            {
                git.BranchRename().SetNewName("In va lid").Call();
                NUnit.Framework.Assert.Fail("Rename with invalid ref name should fail");
            }
            catch (InvalidRefNameException)
            {
            }
            // expected
            // rename without old name and detached head not allowed
            RefUpdate rup = git.GetRepository().UpdateRef(Constants.HEAD, true);

            rup.SetNewObjectId(initialCommit);
            rup.ForceUpdate();
            try
            {
                git.BranchRename().SetNewName("detached").Call();
            }
            catch (DetachedHeadException)
            {
            }
        }