mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-03 03:55:51 +01:00
Fix offset in recursion
This commit is contained in:
@@ -269,13 +269,13 @@ public class GitBrowseCommand extends AbstractGitCommand
|
||||
TreeEntry entry = entryIterator.next();
|
||||
FileObject fileObject = createFileObject(repo, request, revId, entry);
|
||||
|
||||
if (resultCount > request.getOffset()) {
|
||||
files.add(fileObject);
|
||||
}
|
||||
|
||||
if (request.isRecursive() && fileObject.isDirectory()) {
|
||||
convertToFileObject(fileObject, repo, request, revId, entry.getChildren());
|
||||
}
|
||||
|
||||
if (resultCount > request.getOffset()) {
|
||||
files.add(fileObject);
|
||||
}
|
||||
}
|
||||
|
||||
parent.setChildren(files);
|
||||
|
||||
@@ -268,6 +268,75 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
|
||||
assertFalse(root.isTruncated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecursiveLimit() throws IOException {
|
||||
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||
|
||||
request.setLimit(4);
|
||||
request.setRecursive(true);
|
||||
|
||||
FileObject root = createCommand().getBrowserResult(request).getFile();
|
||||
|
||||
Collection<FileObject> foList = root.getChildren();
|
||||
|
||||
assertThat(foList)
|
||||
.extracting("name")
|
||||
.containsExactly("c", "a.txt");
|
||||
|
||||
FileObject c = findFile(foList, "c");
|
||||
|
||||
Collection<FileObject> cChildren = c.getChildren();
|
||||
assertThat(cChildren)
|
||||
.extracting("name")
|
||||
.containsExactly("d.txt", "e.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecursiveLimitInSubDir() throws IOException {
|
||||
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||
|
||||
request.setLimit(2);
|
||||
request.setRecursive(true);
|
||||
|
||||
FileObject root = createCommand().getBrowserResult(request).getFile();
|
||||
|
||||
Collection<FileObject> foList = root.getChildren();
|
||||
|
||||
assertThat(foList)
|
||||
.extracting("name")
|
||||
.containsExactly("c");
|
||||
|
||||
FileObject c = findFile(foList, "c");
|
||||
|
||||
Collection<FileObject> cChildren = c.getChildren();
|
||||
assertThat(cChildren)
|
||||
.extracting("name")
|
||||
.containsExactly("d.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecursiveOffset() throws IOException {
|
||||
BrowseCommandRequest request = new BrowseCommandRequest();
|
||||
|
||||
request.setOffset(2);
|
||||
request.setRecursive(true);
|
||||
|
||||
FileObject root = createCommand().getBrowserResult(request).getFile();
|
||||
|
||||
Collection<FileObject> foList = root.getChildren();
|
||||
|
||||
assertThat(foList)
|
||||
.extracting("name")
|
||||
.containsExactly("c", "a.txt", "b.txt", "f.txt");
|
||||
|
||||
FileObject c = findFile(foList, "c");
|
||||
|
||||
Collection<FileObject> cChildren = c.getChildren();
|
||||
assertThat(cChildren)
|
||||
.extracting("name")
|
||||
.containsExactly("e.txt");
|
||||
}
|
||||
|
||||
private FileObject findFile(Collection<FileObject> foList, String name) {
|
||||
return foList.stream()
|
||||
.filter(f -> name.equals(f.getName()))
|
||||
|
||||
Reference in New Issue
Block a user