예제 #1
0
        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));
        }
예제 #2
0
 public void FailIfNotValidSha(
     [Frozen] IGitRepository repo,
     ICommit commit,
     RepoTarget targets,
     GitPatcherVersioning patcherVersioning,
     CancellationToken cancel,
     RetrieveCommit sut)
 {
     repo.TryGetCommit(default !, out _).ReturnsForAnyArgs(x =>
예제 #3
0
 public void PassesShaToTryGetCommit(
     [Frozen] IGitRepository repo,
     RepoTarget targets,
     GitPatcherVersioning patcherVersioning,
     CancellationToken cancel,
     RetrieveCommit sut)
 {
     sut.TryGet(repo, targets, patcherVersioning, cancel);
     repo.Received(1).TryGetCommit(targets.TargetSha, out Arg.Any <bool>());
 }