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 CreateBranchForPullRequestBranch(AuthenticationInfo auth) { RepositoryExtensions.RunSafe(() => { var network = repositoryInstance.Network; var remote = network.Remotes.Single(); log.Info("Fetching remote refs to see if there is a pull request ref"); var credentialsProvider = GetCredentialsProvider(auth); var remoteTips = (credentialsProvider != null ? network.ListReferences(remote, credentialsProvider) : network.ListReferences(remote)) .Select(r => r.ResolveToDirectReference()).ToList(); log.Info($"Remote Refs:{System.Environment.NewLine}" + string.Join(System.Environment.NewLine, remoteTips.Select(r => r.CanonicalName))); var headTipSha = Head.Tip?.Sha; var refs = remoteTips.Where(r => r.TargetIdentifier == headTipSha).ToList(); if (refs.Count == 0) { var message = $"Couldn't find any remote tips from remote '{remote.Url}' pointing at the commit '{headTipSha}'."; throw new WarningException(message); } if (refs.Count > 1) { var names = string.Join(", ", refs.Select(r => r.CanonicalName)); var message = $"Found more than one remote tip from remote '{remote.Url}' pointing at the commit '{headTipSha}'. Unable to determine which one to use ({names})."; throw new WarningException(message); } var reference = refs.First(); var canonicalName = reference.CanonicalName; var referenceName = ReferenceName.Parse(reference.CanonicalName); log.Info($"Found remote tip '{canonicalName}' pointing at the commit '{headTipSha}'."); if (referenceName.IsTag) { 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/"); log.Info($"Creating fake local branch '{fakeBranchName}'."); Refs.Add(fakeBranchName, headTipSha); 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 Checkout(string commitOrBranchSpec) { RepositoryExtensions.RunSafe(() => { Commands.Checkout(repositoryInstance, commitOrBranchSpec); }); }
private static IServiceProvider GetServiceProvider(GitVersionOptions gitVersionOptions, ILog log = null, IGitRepository repository = null, IFileSystem fileSystem = null, IEnvironment environment = null) { return(ConfigureServices(services => { if (log != null) { services.AddSingleton(log); } if (fileSystem != null) { services.AddSingleton(fileSystem); } if (repository != null) { services.AddSingleton(repository); } if (environment != null) { services.AddSingleton(environment); } var options = Options.Create(gitVersionOptions); services.AddSingleton(options); services.AddSingleton(RepositoryExtensions.ToGitRepositoryInfo(options)); })); }