using LibGit2Sharp.Core; namespace LibGit2Sharp { /// /// Provides helper overloads to a . /// public static class BranchCollectionExtensions { /// /// Create a new local branch with the specified name /// /// The name of the branch. /// Revparse spec for the target commit. /// True to allow silent overwriting a potentially existing branch, false otherwise. /// The being worked with. /// A new . public static Branch Add(this BranchCollection branches, string name, string committish, bool allowOverwrite = false) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(committish, "committish"); Commit commit = branches.repo.LookupCommit(committish); return branches.Add(name, commit, allowOverwrite); } /// /// Deletes the branch with the specified name. /// /// The name of the branch to delete. /// True if the provided is the name of a remote branch, false otherwise. /// The being worked with. public static void Remove(this BranchCollection branches, string name, bool isRemote = false) { Ensure.ArgumentNotNullOrEmptyString(name, "name"); string branchName = isRemote ? Reference.RemoteTrackingBranchPrefix + name : name; Branch branch = branches[branchName]; if (branch == null) { return; } branches.Remove(branch); } /// /// Renames an existing local branch with a new name. /// /// The current branch name. /// The new name the existing branch should bear. /// True to allow silent overwriting a potentially existing branch, false otherwise. /// The being worked with. /// A new . public static Branch Move(this BranchCollection branches, string currentName, string newName, bool allowOverwrite = false) { Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName"); Ensure.ArgumentNotNullOrEmptyString(newName, "newName"); Branch branch = branches[currentName]; if (branch == null) { throw new LibGit2SharpException("No branch named '{0}' exists in the repository."); } return branches.Move(branch, newName, allowOverwrite); } } }