public void CreateBranchForPullRequestBranch(AuthenticationInfo auth) => RepositoryExtensions.RunSafe(() => { this.log.Info("Fetching remote refs to see if there is a pull request ref"); // FIX ME: What to do when Tip is null? if (Head.Tip == null) { return; } var headTipSha = Head.Tip.Sha; var remote = RepositoryInstance.Network.Remotes.Single(); var reference = GetPullRequestReference(auth, remote, headTipSha); var canonicalName = reference.CanonicalName; var referenceName = ReferenceName.Parse(reference.CanonicalName); this.log.Info($"Found remote tip '{canonicalName}' pointing at the commit '{headTipSha}'."); if (referenceName.IsTag) { this.log.Info($"Checking out tag '{canonicalName}'"); Checkout(reference.Target.Sha); } else if (referenceName.IsPullRequest) { var fakeBranchName = canonicalName.Replace("refs/pull/", "refs/heads/pull/").Replace("refs/pull-requests/", "refs/heads/pull-requests/"); this.log.Info($"Creating fake local branch '{fakeBranchName}'."); Refs.Add(fakeBranchName, headTipSha); this.log.Info($"Checking local branch '{fakeBranchName}' out."); Checkout(fakeBranchName); } else { var message = $"Remote tip '{canonicalName}' from remote '{remote.Url}' doesn't look like a valid pull request."; throw new WarningException(message); } });
public void Fetch(string remote, IEnumerable <string> refSpecs, AuthenticationInfo auth, string?logMessage) => RepositoryExtensions.RunSafe(() => Commands.Fetch((Repository)RepositoryInstance, remote, refSpecs, GetFetchOptions(auth), logMessage));
public void Checkout(string commitOrBranchSpec) => RepositoryExtensions.RunSafe(() => Commands.Checkout(RepositoryInstance, commitOrBranchSpec));