public virtual void TestPullConfigRemoteBranch() { Git localGit = SetUpRepoWithRemote(); Ref remote = localGit.BranchList().SetListMode(ListBranchCommand.ListMode.REMOTE) .Call()[0]; NUnit.Framework.Assert.AreEqual("refs/remotes/origin/master", remote.GetName()); // by default, we should create pull configuration CreateBranch(localGit, "newFromRemote", false, remote.GetName(), null); NUnit.Framework.Assert.AreEqual("origin", localGit.GetRepository().GetConfig().GetString ("branch", "newFromRemote", "remote")); localGit.BranchDelete().SetBranchNames("newFromRemote").Call(); // the pull configuration should be gone after deletion NUnit.Framework.Assert.IsNull(localGit.GetRepository().GetConfig().GetString("branch" , "newFromRemote", "remote")); CreateBranch(localGit, "newFromRemote", false, remote.GetName(), null); NUnit.Framework.Assert.AreEqual("origin", localGit.GetRepository().GetConfig().GetString ("branch", "newFromRemote", "remote")); localGit.BranchDelete().SetBranchNames("refs/heads/newFromRemote").Call(); // the pull configuration should be gone after deletion NUnit.Framework.Assert.IsNull(localGit.GetRepository().GetConfig().GetString("branch" , "newFromRemote", "remote")); // use --no-track CreateBranch(localGit, "newFromRemote", false, remote.GetName(), CreateBranchCommand.SetupUpstreamMode .NOTRACK); NUnit.Framework.Assert.IsNull(localGit.GetRepository().GetConfig().GetString("branch" , "newFromRemote", "remote")); localGit.BranchDelete().SetBranchNames("newFromRemote").Call(); }
public virtual void TestPullConfigLocalBranch() { 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.BranchDelete().SetBranchNames("refs/heads/newFromMaster").Call(); // the pull configuration should be gone after deletion NUnit.Framework.Assert.IsNull(localGit.GetRepository().GetConfig().GetString("branch" , "newFromRemote", "remote")); }
public virtual void TestCreateForce() { // using commits Ref newBranch = CreateBranch(git, "NewForce", false, secondCommit.Id.Name, null); NUnit.Framework.Assert.AreEqual(newBranch.GetTarget().GetObjectId(), secondCommit .Id); try { newBranch = CreateBranch(git, "NewForce", false, initialCommit.Id.Name, null); NUnit.Framework.Assert.Fail("Should have failed"); } catch (RefAlreadyExistsException) { } // expected newBranch = CreateBranch(git, "NewForce", true, initialCommit.Id.Name, null); NUnit.Framework.Assert.AreEqual(newBranch.GetTarget().GetObjectId(), initialCommit .Id); git.BranchDelete().SetBranchNames("NewForce").Call(); // using names git.BranchCreate().SetName("NewForce").SetStartPoint("master").Call(); NUnit.Framework.Assert.AreEqual(newBranch.GetTarget().GetObjectId(), initialCommit .Id); try { git.BranchCreate().SetName("NewForce").SetStartPoint("master").Call(); NUnit.Framework.Assert.Fail("Should have failed"); } catch (RefAlreadyExistsException) { } // expected git.BranchCreate().SetName("NewForce").SetStartPoint("master").SetForce(true).Call (); NUnit.Framework.Assert.AreEqual(newBranch.GetTarget().GetObjectId(), initialCommit .Id); }
public void RemoveBranch (string name) { var git = new NGit.Api.Git (RootRepository); git.BranchDelete ().SetBranchNames (name).SetForce (true).Call (); }