Detect browse command for root dir correctly in git

This commit is contained in:
René Pfeuffer
2018-10-10 11:49:49 +02:00
parent ab11acae2d
commit 63669b67f0

View File

@@ -286,7 +286,7 @@ public class GitBrowseCommand extends AbstractGitCommand
logger.debug("load repository browser for revision {}", revId.name());
treeWalk = new TreeWalk(repo);
if (!Strings.isNullOrEmpty(request.getPath()) && !"/".equals(request.getPath())) {
if (!isRootRequest(request)) {
treeWalk.setFilter(PathFilter.create(request.getPath()));
}
revWalk = new RevWalk(repo);
@@ -303,7 +303,7 @@ public class GitBrowseCommand extends AbstractGitCommand
logger.error("could not find tree for {}", revId.name());
}
if (Strings.isNullOrEmpty(request.getPath())) {
if (isRootRequest(request)) {
result = createEmtpyRoot();
findChildren(result, repo, request, revId, treeWalk);
} else {
@@ -324,6 +324,10 @@ public class GitBrowseCommand extends AbstractGitCommand
return result;
}
private boolean isRootRequest(BrowseCommandRequest request) {
return Strings.isNullOrEmpty(request.getPath()) || "/".equals(request.getPath());
}
private FileObject findChildren(FileObject parent, org.eclipse.jgit.lib.Repository repo, BrowseCommandRequest request, ObjectId revId, TreeWalk treeWalk) throws IOException, RevisionNotFoundException {
List<FileObject> files = Lists.newArrayList();
while (treeWalk.next())