Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions NGitLab.Tests/RepositoryClient/RepositoryClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tree>();
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)));
}

/// <remarks>
/// See <see href="https://docs.gitlab.com/update/deprecations/#gitlab-177"/>.
/// </remarks>
Expand Down
5 changes: 4 additions & 1 deletion NGitLab/Impl/RepositoryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public RepositoryClient(API api, ProjectId projectId)

public IContributorClient Contributors => new ContributorClient(_api, _repoPath);

public IEnumerable<Tree> Tree => _api.Get().GetAll<Tree>(_repoPath + "/tree");
public IEnumerable<Tree> Tree => GetTree(new RepositoryGetTreeOptions());

public IEnumerable<Tree> GetTree(string path) => GetTree(new RepositoryGetTreeOptions { Path = path });

Expand Down Expand Up @@ -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;
}

Expand Down
Loading