Skip to content

Commit

Permalink
Fix showing branch if specified branch, tag or id does not exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
takezoe committed Jul 11, 2013
1 parent 88b8567 commit 62fb968
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/main/scala/app/RepositoryViewerController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -213,32 +213,28 @@ 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
val readme = files.find(_.name == "README.md").map { file =>
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)
}
}
}
Expand Down

0 comments on commit 62fb968

Please sign in to comment.