public static void CheckoutAllRemoteBranches(this Repository repository, bool onlyUntracked = true) { var localBranches = from branch in repository.Branches where !branch.IsRemote select branch; var untrackedRemoteBranches = from remoteBranch in repository.Branches where remoteBranch.IsRemote where !onlyUntracked || (from localBranch in localBranches where remoteBranch.FriendlyName.EndsWith("/" + localBranch.FriendlyName) select localBranch).Count() == 0 select remoteBranch; foreach (var untrackedRemoteBranch in untrackedRemoteBranches) { var simpleName = untrackedRemoteBranch.FriendlyName.Split('/')?[1]; if (simpleName == null) throw new InvalidOperationException($"{nameof(LibGit2Extensions)}.{nameof(CheckoutAllRemoteBranches)}: the untracked remote branch name '{untrackedRemoteBranch.FriendlyName}' is not in the form '(remote)/(branch)'"); Branch branch = repository.CreateBranch(simpleName, untrackedRemoteBranch.Tip); repository.Branches.Update(branch, (updater) => { updater.Remote = untrackedRemoteBranch.Remote.Name; updater.UpstreamBranch = untrackedRemoteBranch.CanonicalName; }); } }
static GameNode WhiteMove(this GameNode self,int x, int y) { var node = self.CreateBranch(); node.Move = new Move(StoneColor.White, new Position(x, y)); return node; }
public static Branch CreatePullRequest(this IRepository repository, string from, string to, int prNumber = 2, bool isRemotePr = true) { repository.Checkout(to); repository.MergeNoFF(from); repository.CreateBranch("pull/" + prNumber + "/merge").Checkout(); repository.Checkout(to); repository.Reset(ResetMode.Hard, "HEAD~1"); var pullBranch = repository.Checkout("pull/" + prNumber + "/merge"); if (isRemotePr) { // If we delete the branch, it is effectively the same as remote PR repository.Branches.Remove(from); } return pullBranch; }
public static Branch GetOrCreateBranch(this Repository repo, string branchName) { return repo.Branches[branchName] ?? repo.CreateBranch(branchName); }
/// <summary> /// /// </summary> /// <param name="repository"></param> /// <param name="branchName"></param> /// <param name="branchTarget"></param> internal static Branch AddGetBranch(this Repository repository, string branchName,string branchTarget = "HEAD", bool track = true) { Branch branch; //Branch already has been created if (!repository.TryGetLocalBranch(branchName, out branch)) { if (!repository.TryGetRemoteBranch(branchName, out branch)) { //No branch made.. create branch GitFlowExtensions.Log("Creating Branch : " + branchName); branch = repository.CreateBranch(branchName,branchTarget); if (track) { repository.SetRemoteBranch(branch); } } } return branch; }
public static Branch CreateBranch(this Repository repository, BranchName branchName, Commit commit) => repository.CreateBranch(branchName.ToString(), commit);