/// <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); }
internal static bool Track(this Flow gitFlow, string branchName) { var repo = gitFlow.Repository; Branch branch; if (repo.TryGetLocalBranch(branchName, out branch)) { GitFlowExtensions.Log($"Branch {branchName} already tracked"); } else if (repo.TryGetRemoteBranch(branchName, out branch)) { repo.TryCheckout(branch); GitFlowExtensions.Log($"Now Tracking {branchName}"); return(true); } else { GitFlowExtensions.LogError("Track Error, Branch Not Found"); } return(false); }
public static bool TryCheckout(this Repository repository, Branch branch, bool force = false) { CheckoutOptions options = new CheckoutOptions(); if (force) { options.CheckoutModifiers = CheckoutModifiers.Force; } try { var checkoutBranch = repository.Checkout(branch, options); GitFlowExtensions.Log("Checked out Branch : " + checkoutBranch.FriendlyName); } catch (CheckoutConflictException conflict) { GitFlowExtensions.LogError("Checkout Failed", conflict.Message); return(false); } return(true); }
internal static bool Publish(this Flow gitFlow, string branchName, string remoteName = "origin") { var repo = gitFlow.Repository; Remote remote = repo.Network.Remotes[remoteName]; try { gitFlow.Repository.Network.Fetch(remote); Branch branch; if (repo.TryGetRemoteBranch(branchName, out branch)) { GitFlowExtensions.Log($"Branch {branchName} already published"); return(false); } else if (repo.TryGetLocalBranch(branchName, out branch)) { if (!branch.IsTracking) { repo.SetRemoteBranch(branch, remoteName); } repo.Network.Push(branch); GitFlowExtensions.Log($"Branch {branchName} Published"); repo.TryCheckout(branch); return(true); } else { GitFlowExtensions.LogError("Publish Error, Branch Not Found"); } return(false); } catch (Exception ex) { GitFlowExtensions.LogError("Publish Error ", ex.Message); return(false); } }