mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-03 12:05:59 +01:00
Fix showing branch if specified branch, tag or id does not exist.
This commit is contained in:
@@ -213,11 +213,17 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
if(repository.commitCount == 0){
|
||||
repo.html.guide(repository)
|
||||
} else {
|
||||
val revision = if(revstr.isEmpty) repository.repository.defaultBranch else revstr
|
||||
|
||||
JGitUtil.withGit(getRepositoryDir(repository.owner, repository.name)){ git =>
|
||||
// get latest commit
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision))
|
||||
// get specified commit
|
||||
val (revCommit, revision) = try {
|
||||
val revision = if(revstr.isEmpty) repository.repository.defaultBranch else revstr
|
||||
(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)), revision)
|
||||
} catch {
|
||||
case e: NullPointerException => {
|
||||
val revision = repository.branchList.head
|
||||
(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision)), revision)
|
||||
}
|
||||
}
|
||||
// get files
|
||||
val files = JGitUtil.getFileList(git, revision, path)
|
||||
// process README.md
|
||||
@@ -225,20 +231,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
new String(JGitUtil.getContent(Git.open(getRepositoryDir(repository.owner, repository.name)), file.id, true).get, "UTF-8")
|
||||
}
|
||||
|
||||
repo.html.files(
|
||||
// current branch
|
||||
revision,
|
||||
// repository
|
||||
repository,
|
||||
// current path
|
||||
if(path == ".") Nil else path.split("/").toList,
|
||||
// latest commit
|
||||
new JGitUtil.CommitInfo(revCommit),
|
||||
// file list
|
||||
files,
|
||||
// readme
|
||||
readme
|
||||
)
|
||||
repo.html.files(revision, repository,
|
||||
if(path == ".") Nil else path.split("/").toList, // current path
|
||||
new JGitUtil.CommitInfo(revCommit), // latest commit
|
||||
files, readme)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user