public void CreateBranch(string branch) { CreateBranchOptions options = new CreateBranchOptions(); options.BaseOn = CreateBranchOptions.Base.Head; options.Switch = true; CreateBranch(branch, string.Empty, options); }
public void CreateBranch(string branch, string description, CreateBranchOptions options) { Branch newBranch = null; try { switch (options.BaseOn) { case CreateBranchOptions.Base.Head: newBranch = _repo.Branches.Add(branch, _repo.Head.FriendlyName, options.Force); break; case CreateBranchOptions.Base.Branch: newBranch = _repo.Branches.Add(branch, options.Branch.FriendlyName, options.Force); break; case CreateBranchOptions.Base.Tag: throw new NotImplementedException("creation branch based on tag is not implemented."); case CreateBranchOptions.Base.Commit: newBranch = _repo.Branches.Add(branch, options.Commit, options.Force); break; } Trace.TraceInformation("git create branch '{0}'", branch); _repo.SetBranchDescription(branch, description); RequeryUnsyncedCommits(); if (options.Switch) { Checkout(branch, false); } } catch (LibGit2SharpException ex) { if (newBranch != null) { _repo.Branches.Remove(newBranch); } throw new GitException("Branch creation failed.", ex); } }