public void Delete_and_clone_when_repo_is_not_valid(
        [Frozen] IRepositoryStaticWrapper wrapper,
        [Frozen] IFileUtilities fileUtils,
        GitRepositoryFactory sut)
    {
        wrapper.IsValid(Arg.Any <string>()).Returns(false);

        sut.CreateAndCloneIfNeeded("repo_url", "repo_path", "branch");

        Received.InOrder(() =>
        {
            wrapper.IsValid("repo_path");
            fileUtils.DeleteReadOnlyDirectory("repo_path");
            wrapper.Clone("repo_url", "repo_path",
                          Verify.That <CloneOptions>(x => x.BranchName.Should().Be("branch")));
        });
    }
示例#2
0
    public void UpdateRepo()
    {
        // Retry only once if there's a failure. This gives us an opportunity to delete the git repository and start
        // fresh.
        var exception = CheckoutAndUpdateRepo();

        if (exception is not null)
        {
            _log.Information("Deleting local git repo and retrying git operation...");
            _fileUtils.DeleteReadOnlyDirectory(RepoPath);

            exception = CheckoutAndUpdateRepo();
            if (exception is not null)
            {
                throw exception;
            }
        }
    }
    private void DeleteAndCloneRepo(string repoUrl, string repoPath, string branch)
    {
        _fileUtils.DeleteReadOnlyDirectory(repoPath);

        var progress = new ProgressBar
        {
            Description = "Fetching guide data"
        };

        _staticWrapper.Clone(repoUrl, repoPath, new CloneOptions
        {
            RecurseSubmodules  = false,
            BranchName         = branch,
            OnTransferProgress = gitProgress =>
            {
                progress.ReportProgress.OnNext((float)gitProgress.ReceivedObjects / gitProgress.TotalObjects);
                return(true);
            }
        });
    }
示例#4
0
    public IEnumerable <string> GetCustomFormatJson()
    {
        // Retry only once if there's a failure. This gives us an opportunity to delete the git repository and start
        // fresh.
        var exception = CheckoutAndUpdateRepo();

        if (exception is not null)
        {
            _log.Information("Deleting local git repo and retrying git operation...");
            _fileUtils.DeleteReadOnlyDirectory(_repoPath);

            exception = CheckoutAndUpdateRepo();
            if (exception is not null)
            {
                throw exception;
            }
        }

        var jsonDir = Path.Combine(_repoPath, "docs/json/radarr");
        var tasks   = _fileSystem.Directory.GetFiles(jsonDir, "*.json")
                      .Select(async f => await _fileSystem.File.ReadAllTextAsync(f));

        return(Task.WhenAll(tasks).Result);
    }