diff --git a/NGitLab.Tests/RepositoryClient/RepositoryClientTests.cs b/NGitLab.Tests/RepositoryClient/RepositoryClientTests.cs index 4a060127..34ef080a 100644 --- a/NGitLab.Tests/RepositoryClient/RepositoryClientTests.cs +++ b/NGitLab.Tests/RepositoryClient/RepositoryClientTests.cs @@ -270,6 +270,29 @@ public async Task GetAllTreeObjectsInPathWith100ElementsByPage() Assert.That(treeObjects, Is.Not.Empty); } + [Test] + [NGitLabRetry] + public async Task GetAllTreeObjectsAcrossMultiplePages() + { + const int commitCount = 5; + using var context = await RepositoryClientTestsContext.CreateAsync(commitCount); + + // PerPage smaller than the number of entries forces several (keyset) pages + var options = new RepositoryGetTreeOptions { Path = string.Empty, Recursive = true, PerPage = 2 }; + + var treeObjects = context.RepositoryClient.GetTree(options).ToList(); + Assert.That(treeObjects.Count(t => t.Type == ObjectType.blob), Is.EqualTo(commitCount)); + Assert.That(treeObjects.Select(t => t.Path).Distinct(StringComparer.Ordinal).Count(), Is.EqualTo(treeObjects.Count)); + + var asyncTreeObjects = new List(); + await foreach (var item in context.RepositoryClient.GetTreeAsync(options)) + { + asyncTreeObjects.Add(item); + } + + Assert.That(asyncTreeObjects.Select(t => t.Path), Is.EquivalentTo(treeObjects.Select(t => t.Path))); + } + /// /// See . /// diff --git a/NGitLab/Impl/RepositoryClient.cs b/NGitLab/Impl/RepositoryClient.cs index a2e5a389..941b3700 100644 --- a/NGitLab/Impl/RepositoryClient.cs +++ b/NGitLab/Impl/RepositoryClient.cs @@ -27,7 +27,7 @@ public RepositoryClient(API api, ProjectId projectId) public IContributorClient Contributors => new ContributorClient(_api, _repoPath); - public IEnumerable Tree => _api.Get().GetAll(_repoPath + "/tree"); + public IEnumerable Tree => GetTree(new RepositoryGetTreeOptions()); public IEnumerable GetTree(string path) => GetTree(new RepositoryGetTreeOptions { Path = path }); @@ -159,6 +159,9 @@ private string BuildGetTreeUrl(RepositoryGetTreeOptions options) url = Utils.AddParameter(url, "recursive", options.Recursive); url = Utils.AddParameter(url, "per_page", options.PerPage); + // Offset pagination is unsupported on this endpoint since GitLab 15.0 + url = Utils.AddParameter(url, "pagination", "keyset"); + return url; }