public GetResponse <RepoTarget> Get( IGitRepository repo, GitPatcherVersioning patcherVersioning) { string?targetSha; string?target; switch (patcherVersioning.Versioning) { case PatcherVersioningEnum.Tag: if (string.IsNullOrWhiteSpace(patcherVersioning.Target)) { return(GetResponse <RepoTarget> .Fail("No tag selected")); } repo.Fetch(); if (!repo.TryGetTagSha(patcherVersioning.Target, out targetSha)) { return(GetResponse <RepoTarget> .Fail("Could not locate tag")); } target = patcherVersioning.Target; break; case PatcherVersioningEnum.Commit: targetSha = patcherVersioning.Target; if (string.IsNullOrWhiteSpace(targetSha)) { return(GetResponse <RepoTarget> .Fail("Could not locate commit")); } target = patcherVersioning.Target; break; case PatcherVersioningEnum.Branch: if (string.IsNullOrWhiteSpace(patcherVersioning.Target)) { return(GetResponse <RepoTarget> .Fail($"Target branch had no name.")); } repo.Fetch(); if (!repo.TryGetBranch(patcherVersioning.Target, out var targetBranch)) { return(GetResponse <RepoTarget> .Fail($"Could not locate branch: {patcherVersioning.Target}")); } targetSha = targetBranch.Tip.Sha; target = patcherVersioning.Target; break; default: throw new NotImplementedException(); } return(GetResponse <RepoTarget> .Succeed( new RepoTarget(targetSha, target))); }
public GetResponse <ICommit> TryGet( IGitRepository repo, RepoTarget targets, GitPatcherVersioning patcherVersioning, CancellationToken cancel) { var commit = repo.TryGetCommit(targets.TargetSha, out var validSha); if (!validSha) { return(GetResponse <ICommit> .Fail("Malformed sha string")); } cancel.ThrowIfCancellationRequested(); if (commit == null) { bool fetchIfMissing = ShouldFetchIfMissing.Should(patcherVersioning); if (!fetchIfMissing) { return(GetResponse <ICommit> .Fail("Could not locate commit with given sha")); } repo.Fetch(); commit = repo.TryGetCommit(targets.TargetSha, out _); if (commit == null) { return(GetResponse <ICommit> .Fail("Could not locate commit with given sha")); } } return(GetResponse <ICommit> .Succeed(commit)); }
void TryFetch(Branch targetBranch) { try { repository.Fetch(targetBranch.RemoteName, credentials); } catch (Exception ex) { eventStream.Push(Status.Create("Unable to fetch from remote '{0}': {1}", targetBranch.RemoteName, ex.Message)); } }
public Task ExecuteAsync(CancellationToken cancellation = default) { var remotes = repository.Network.Remotes.ToList(); foreach (var remote in remotes) { eventStream.Push(Status.Create((remotes.IndexOf(remote) + 1f) / (remotes.Count + 1f), "Fetching {0}...", remote.Name)); repository.Fetch(remote, credentials, eventStream); } eventStream.Push(Status.Succeeded()); return(Task.CompletedTask); }