mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
(refs #50)Fix search logic in empty repository
This commit is contained in:
@@ -29,20 +29,24 @@ trait RepositorySearchService { self: IssuesService =>
|
|||||||
|
|
||||||
def countFiles(owner: String, repository: String, query: String): Int =
|
def countFiles(owner: String, repository: String, query: String): Int =
|
||||||
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
|
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
|
||||||
searchRepositoryFiles(git, query).length
|
if(JGitUtil.isEmpty(git)) 0 else searchRepositoryFiles(git, query).length
|
||||||
}
|
}
|
||||||
|
|
||||||
def searchFiles(owner: String, repository: String, query: String): List[FileSearchResult] =
|
def searchFiles(owner: String, repository: String, query: String): List[FileSearchResult] =
|
||||||
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
|
JGitUtil.withGit(getRepositoryDir(owner, repository)){ git =>
|
||||||
val files = searchRepositoryFiles(git, query)
|
if(JGitUtil.isEmpty(git)){
|
||||||
val commits = JGitUtil.getLatestCommitFromPaths(git, files.toList.map(_._1), "HEAD")
|
Nil
|
||||||
files.map { case (path, text) =>
|
} else {
|
||||||
val (highlightText, lineNumber) = getHighlightText(text, query)
|
val files = searchRepositoryFiles(git, query)
|
||||||
FileSearchResult(
|
val commits = JGitUtil.getLatestCommitFromPaths(git, files.toList.map(_._1), "HEAD")
|
||||||
path,
|
files.map { case (path, text) =>
|
||||||
commits(path).getCommitterIdent.getWhen,
|
val (highlightText, lineNumber) = getHighlightText(text, query)
|
||||||
highlightText,
|
FileSearchResult(
|
||||||
lineNumber)
|
path,
|
||||||
|
commits(path).getCommitterIdent.getWhen,
|
||||||
|
highlightText,
|
||||||
|
lineNumber)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -524,6 +524,8 @@ object JGitUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def isEmpty(git: Git): Boolean = git.getRepository.resolve(Constants.HEAD) == null
|
||||||
|
|
||||||
private def setReceivePack(repository: org.eclipse.jgit.lib.Repository): Unit = {
|
private def setReceivePack(repository: org.eclipse.jgit.lib.Repository): Unit = {
|
||||||
val config = repository.getConfig
|
val config = repository.getConfig
|
||||||
config.setBoolean("http", null, "receivepack", true)
|
config.setBoolean("http", null, "receivepack", true)
|
||||||
|
|||||||
Reference in New Issue
Block a user